我正在使用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中以debug模式构建,并在构建服务器上使用dotnet
进行构建。
然而,我仍希望能够以debug模式在本地运行dotnet run
(用于从VSCode运行)。因此,我需要根据Visual Studio的MSBuild或dotnet
版本有条件地包含PackageReference
。据我所知,这两个版本号完全相同;我漏掉了什么吗?
MSBuild中是否有属性可用于区分VS MSBuild和dotnet
?
MSBuildRuntimeType
现在已经记录,所以如果您正在查看此内容并且不确定它是否为稳定的API,则似乎是这样。 - Joe Sewell