且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将dotnetcore项目迁移到1.0.4后出现“ dotnet build”错误

更新时间:2022-01-22 18:24:06

.NET Core CLI中包含的MSBuild的.NET Core版本是能够在Windows机器上构建经典项目,只要它们以.NET Framework> = 4.0为目标,就可以安装参考程序集,并且不使用特殊的目标/任务。

The .NET Core build of MSBuild that is included in the .NET Core CLI is capable of building classic projects on windows machines as well as long as they target .NET Framework >= 4.0, reference assemblies are installed and no special targets / tasks are used.

在您的情况下,您尝试使用与主机MSBuild实例不同的体系结构来编译资源。从即将推出的2.0工具开始的基于SDK的项目中可以解决此问题,但经典项目依靠MSBuild使用其他CLR启动附加过程-.NET Core不支持。

In your case, you tried to compile a resource with a different architecture than the host MSBuild instance is. This is worked around in SDK-based projects beginning in the upcoming 2.0 tools but classic projects rely on MSBuild to launch an additional process using a different CLR - which is not supported on .NET Core.

解决此问题的简单方法是不使用 dotnet 命令恢复/构建解决方案,而使用其 msbuild 等效项,使用与开发人员命令提示符一起安装在Visual Studio中的msbuild.exe。 (例如=> msbuild / t:还原 msbuild msbuild / t:发布/ p:Configuration = Release 等。)

The easy way to work around it is to not use the dotnet commands to restore / build the solution, but their msbuild equivalents using the msbuild.exe installed with visual studio using the developer command prompt. (e.g. => msbuild /t:Restore, msbuild, msbuild /t:Publish /p:Configuration=Release etc.).

另一种解决方法是编辑有问题的csproj文件,将其添加到< Project> 在旧项目中:

Another workaround would be to edit the problematic csproj file to add this to the <Project> in the "old" project:

<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
  <GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
  <GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
</PropertyGroup>

有一个在MSBuild的GitHub存储库中发布有关此问题。