1
votes

I currently got stuck into following problem:

A collegue of mine has ported one of his C# projects to the new csproj format (see http://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/ for details). Using Visual Studio 2017 building works. Unfortunately I am using MSBuild in some console application for compiling these projects too and it seems that the current MSBuild version that is shipped with Visual Studio 2017 gets into trouble when using the new "PackageReference" keyword.

Does anyone has a hint for me?

Update:

Here are some more details:

I have a console application where I am referencing some "Microsoft.Build" assemblies from "Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin". I am using the "BuildManager" for building the code. My collegue is using a lot of nuget package references which were previously defined in the "packages.config" file. This file does not exist any more ... instead all nuget references are now included in the csproj file using "<PackageReference Include=...".

When I start my console application it, I'll get the message "(...) error CS0234: The type or namespace name "CodeAnalysis" does not exist in the namespace 'Microsoft' (...)". "Microsoft.CodeAnalysis" is one of the Nuget packages my collegue is using. It seems that the BuildManager does not restore these nuget packages :(

1
What happens when you run msbuild /version? Maybe you've got an earlier version of msbuild on your path.Jon Skeet
(Run where msbuild to find out.)Jon Skeet
I have a console application where I am referencing some "Microsoft.Build" assemblies ... one moment ... just pressed too early <enter> ^^Sandman
So which version of those assemblies are you referring to? It would be helpful to give all the details in the question.Jon Skeet
At this point I think it would be easier to help you if you'd provide a concrete example - a minimal console app invoking msbuild, along with a minimal project for it to fail to build.Jon Skeet

1 Answers

0
votes

It seems that the BuildManager does not restore these nuget packages

According to the error messages:

error CS0234: The type or namespace name "CodeAnalysis" does not exist in the namespace

Your project may have lost those packages in the location: C:\Users\<username>\.nuget\packages, you can check if it exists.

To resolve this issue, you should open your colleague's project with Visual Studio 2017, then restore the nuget packages manually (Right click the solution->Restore NuGet Packages). That because the class of BuildManager could not be used to restore the nuget package. NuGet package restore supported by NuGet/Visual Studio.

So you should restore those nuget packages, then build it with your console application. Besides, there is a known issue about the "Microsoft.Build" assemblies 15.0. You can refer to this issue on GitHub for detail.

Hope this helps.