【问题标题】:How can I check if MSBuild is using .NET Core?如何检查 MSBuild 是否使用 .NET Core?
【发布时间】: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 吗?

【问题讨论】:

    标签: msbuild .net-core


    【解决方案1】:

    原来有一个属性MSBuildRuntimeType 可以是CoreMonoFull。所以我可以这样做:

    <PackageReference Include="Scripty.MsBuild" Version="0.7.4" Condition="'$(MSBuildRuntimeType)'!='Core'" />
    

    Reference from SDK

    【讨论】:

    • 更新:MSBuildRuntimeType 现在是 documented,所以如果您正在查看它并不确定它是否是一个稳定的 API,它似乎是。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 2012-06-03
    • 2017-11-22
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多