简体   繁体   中英

Using MSBuild with the new csproj format

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 :(

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM