MSBuild cannot find a reference

I also found a similar reference issue when building an UWP appx package. There are a lot of error messages look like:

App.xaml.cs(6,15): error CS0234: The type or namespace name 'ApplicationModel' does not exist in the namespace 'Windows' (are you missing an assembly reference?)

If opening the sln file with VS2017, it builds no problem.

I did two things to fix this issue:

  1. I noticed that the original solution requires winSDK 10.0.18362, but on my build machine, I don't have it. If opening with VS2017, it asks me to re-target the SDK to an installed older version. I think the msbuild may not be able to do the re-target, so I just downloaded and installed the required winSDK 18362.
  2. I added a "/t:restore" option to the msbuild command line, and run the msbuild twice:
    msbuild mySolution.sln /p:Configuration="Release" /p:Platform="x64" /t:restore
    msbuild mySolution.sln /p:Configuration="Release" /p:Platform="x64"

For restore, please refer to https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target


I know this is an old post, but I came across it today, so thought I would offer feedback for anyone else.

I've encountered this a few times and found that changing the Target Framework from .NET Framework 4 Client Profile to just .NET Framework 4 does the trick.


Had the same issue today, ended that the project that could not be referenced had a different platform specified, x86 where the other projects where Any Platform. To get around this, I had to set the parameter with /p:Platform="Mixed Platforms". You can see what VS uses by going to Configuration Manager and looking at the Active Solution Platform selected in the top right.


Apparently this seems to be a known problem in MSBuild as more people have issues with this. I still haven't received a valid reply from Microsoft regarding this, but the discussion was continued here : http://social.msdn.microsoft.com/Forums/en-CA/msbuild/thread/434abf1a-30db-4b13-8062-13755898dd71