Windows 10 Universal App - Type exists in both “Wi

2019-04-20 05:05发布

somehow (I have not even done anything) I get many erros in Visual Studio 2015 but I cant understand what the problem really is.

It says that a lot of "types" exists in both "Windows.Foundation.UniversalApiContract" libraries.

Can somebody help me? What can I do to rescue my solution and my project? I've tried to clean and rebuild it sometimes and this doesn't helped.

Errors in Visual Studio 2015

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-20 05:21

I ran into something similar:

15178 errors, huh?

Not fun. I think it started when I accidentally added an extension method to a set of utilities I keep in a Portable Class Library project that referenced using Windows.ApplicationModel.DataTransfer;, as I'd (stupidly) added some code that accessed the clipboard to the PCL. And that makes some sense; now I'm effectively targeting two Windows platforms, which is obviously wrong.

A few things got added to that PCL project's csproj file. First was this line:

<UseVSHostingProcess>false</UseVSHostingProcess>

The second was this ItemGroup:

<ItemGroup>
    <Reference Include="Windows.Foundation.UniversalApiContract">
      <HintPath>..\..\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\2.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
    </Reference>
</ItemGroup>

I'm not sure if all this was required, but I did remove the clipboard-related code, the reference to Windows.ApplicationModel.DataTransfer; in my usings, and reset/removed the changes to the csproj file.

I still had many of the same errors, however. I've found that doing clean rebuilds doesn't always work as I'd expect, so I've created a .bat file that I keep in the root of the start-up project's folder to run when I have trouble. First I have to close the solution in Visual Studio, and then I run...

cd C:\Projects\solutionName\projectName
cd ./bin
rmdir x64 /S /Q
rmdir x86 /S /Q
rmdir ARM /S /Q

cd ../obj/
rmdir x64 /S /Q
rmdir x86 /S /Q
rmdir ARM /S /Q

cd ..
pause

I now also have to run that (again, with the solution closed) before building and submitting to the store. Not real sure why but doing both of these -- removing non-PCL code from & resetting the PCL project and blasting those /bin and /obj folders -- did fix the issue.

My unscientific hunch for why I have to blow away /bin and /obj is that VS doesn't always seem to build my projects in dependency order, and often references older compilations of my code when it should've started fresh. Blasting away any possible dated crutch seems to force it into doing things The Right Way. ¯\_(ツ)_/¯

查看更多
冷血范
3楼-- · 2019-04-20 05:34

Looks like you are referencing both the Windows 10 SDK metadata (UAP) and the Windows 8.1 SDK metadata (Windows). Are you mixing old and new binaries, or an old project file? Try to create a new project from scratch and added your sources.

查看更多
登录 后发表回答