dotnet build on cmd vs VS2017 的区别在哪里? [英] Where is the difference of dotnet build on cmd vs VS2017?
问题描述
背景
一个简单的 dotnet core 2.0 项目依赖于 Xamarin.Forms (2.3.4.270).
A simple dotnet core 2.0 project has a dependency to Xamarin.Forms (2.3.4.270).
当我在 Visual Studio 2017 (15.3) 中构建项目时,构建成功.在命令行上运行 dotnet build
时失败并出现以下错误:
When I build the project in Visual Studio 2017 (15.3) then the build succeeds. When running dotnet build
on the command line it fails with the following error:
C:Userssteph.nugetpackagesxamarin.forms2.3.4.270uildportable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20Xamarin.Forms.targets(40,3):错误 MSB4062:Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName"任务无法从程序集中加载C:Userssteph.nugetpackagesxamarin.forms2.3.4.270uildportable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20Xamarin.Forms.Build.Tasks.dll.无法加载文件或程序集Microsoft.Build.Utilities.v4.0,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a'.该系统找不到指定的文件.确认声明是正确的,即大会及其所有依赖项可用,并且任务包含公共类实现 Microsoft.Build.Framework.ITask.[C:UsersstephDocumentsBitbucket ime-stamp-coreTimeStamp.Core.ViewsTimeStamp.Core.Views.csproj]
C:Userssteph.nugetpackagesxamarin.forms2.3.4.270uildportable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20Xamarin.Forms.targets(40,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:Userssteph.nugetpackagesxamarin.forms2.3.4.270uildportable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:UsersstephDocumentsBitbucket ime-stamp-coreTimeStamp.Core.ViewsTimeStamp.Core.Views.csproj]
因此,无论出于何种原因,Microsoft.Build.Utilities.v4.0
都丢失了.正如您在上面的屏幕截图中看到的那样,我已经尝试添加构建实用程序,但没有成功.无论是否添加了 Build Core,我都会得到相同的结果.
So for whatever reason Microsoft.Build.Utilities.v4.0
is missing. As you can see in the screenshot above I already tried to add the build utilities as well, without success. Independent on whether Build Core is added or not I'm getting the same result.
.csproj
文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.3.409" />
<PackageReference Include="Xamarin.Forms" Version="2.3.4.270" />
</ItemGroup>
</Project>
问题
dotnet build
和 Visual Studio 2017 构建此类项目的区别在哪里?我一直觉得VS2017也只是调用dotnet build
.- 我该如何解决这个问题?
- Where is the difference betweend
dotnet build
and Visual Studio 2017 for building such kind of project? I've been under the impression that VS2017 also just callsdotnet build
. - How can I fix this?
推荐答案
此版本的 Xamarin.Forms 表单包含无法在 .NET Core 版本的 MSBuild 上加载的构建任务,这就是您需要使用MSBuild 的完整框架版本(包含在 VS 中).
This version of the Xamarin.Forms forms contains a build task that cannot be loaded on the .NET Core version of MSBuild, which is why you need to use the full framework version of MSBuild (included in VS).
在 这个 GitHub 问题上有一些关于这个包的讨论.
There is some discussion about this package on this GitHub issue.
如果包含 MSBuild 任务的包不是专门为支持 .NET Core 和 .NET Framework MSBuild 而设计的,则可能会发生这些错误.
If a package containing MSBuild tasks is not specifically authored to support both .NET Core and .NET Framework MSBuild, these errors are likely to occur.
这篇关于dotnet build on cmd vs VS2017 的区别在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!