【发布时间】:2017-07-07 08:01:31
【问题描述】:
我正在使用Scripty.MsBuild 在 ASP.NET Core 项目中生成一些文件。当我从 VS2017 构建时,目标运行成功,但是当我通过 dotnet 构建时,出现错误:
Scripty.MsBuild.targets(31,5): error MSB4062: The "ScriptyTask" task could not be loaded from the assembly C:\Users\geirsagberg\.nuget\packages\scripty.msbuild\0.7.4\build\\..\tools\Scripty.MsBuild.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 <UsingTask> 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.
我目前的解决方法是为Release 配置禁用Scripty.MsBuild:
<PackageReference Include="Scripty.MsBuild" Version="0.7.4" Condition="'$(Configuration)'=='Debug'" />
这让我可以在调试模式下从 VS 构建,并在构建服务器上使用 dotnet 构建。
但是,我仍然希望能够在本地以调试模式执行dotnet run(用于从 VSCode 运行)。因此,我需要有条件地包含PackageReference,具体取决于Visual Studio 的MSBuild 是否正在运行,或者dotnet 版本。据我所知,这两个版本号完全相同。我错过了什么吗?
我可以使用 MSBuild 中的属性来区分 VS MSBuild 和 dotnet 吗?
【问题讨论】: