简体   繁体   English

将MSBuild与新的csproj格式一起使用

[英]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). 我的一个同事将他的一个C#项目移植到了新的csproj格式(有关详细信息,请参见http://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/ )。 Using Visual Studio 2017 building works. 使用Visual Studio 2017构建作品。 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. 不幸的是,我也在某些控制台应用程序中使用MSBuild来编译这些项目,并且当使用新的“ PackageReference”关键字时,Visual Studio 2017附带的当前MSBuild版本似乎遇到了麻烦。

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". 我有一个控制台应用程序,在这里我从“程序文件(x86)\\ Microsoft Visual Studio \\ 2017 \\ Professional \\ MSBuild \\ 15.0 \\ Bin”引用一些“ Microsoft.Build”程序集。 I am using the "BuildManager" for building the code. 我正在使用“ BuildManager”来构建代码。 My collegue is using a lot of nuget package references which were previously defined in the "packages.config" file. 我的同事正在使用很多nuget包引用,这些引用以前是在“ packages.config”文件中定义的。 This file does not exist any more ... instead all nuget references are now included in the csproj file using "<PackageReference Include=...". 该文件已不存在……而是现在使用“ <PackageReference Include = ...”将所有nuget引用都包含在csproj文件中。

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' (...)". 当我启动控制台应用程序时,我将收到消息“(...)错误CS0234:名称空间'Microsoft'(...)中不存在类型或名称空间名称“ CodeAnalysis”。 "Microsoft.CodeAnalysis" is one of the Nuget packages my collegue is using. “ Microsoft.CodeAnalysis”是我的同事正在使用的Nuget软件包之一。 It seems that the BuildManager does not restore these nuget packages :( 似乎BuildManager不会还原这些nuget包:(

It seems that the BuildManager does not restore these nuget packages 似乎BuildManager不能还原这些nuget包

According to the error messages: 根据错误信息:

error CS0234: The type or namespace name "CodeAnalysis" does not exist in the namespace 错误CS0234:名称空间中不存在类型或名称空间名称“ CodeAnalysis”

Your project may have lost those packages in the location: C:\\Users\\<username>\\.nuget\\packages , you can check if it exists. 您的项目可能在以下位置丢失了这些软件包: C:\\Users\\<username>\\.nuget\\packages ,您可以检查其是否存在。

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). 要解决此问题,您应该使用Visual Studio 2017打开同事的项目,然后手动还原nuget程序包(右键单击解决方案->“还原NuGet程序包”)。 That because the class of BuildManager could not be used to restore the nuget package. 那是因为BuildManager的类无法用于还原nuget包。 NuGet package restore supported by NuGet/Visual Studio. NuGet / Visual Studio支持的NuGet软件包还原。

So you should restore those nuget packages, then build it with your console application. 因此,您应该还原这些nuget软件包,然后使用控制台应用程序对其进行构建。 Besides, there is a known issue about the " Microsoft.Build " assemblies 15.0. 此外,还有一个有关“ Microsoft.Build ”程序集15.0的已知问题。 You can refer to this issue on GitHub for detail. 您可以在GitHub上参考此问题以获取详细信息。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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