2

一位同事最近使用新的 VS2017 .csproj 格式为我们的一个项目添加了 .NET Standard 支持:

在此处输入图像描述

这似乎破坏了我的脚本,因为在使用 Cake MSBuild 别名 ( http://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildAliases/C240F0FB ) 时出现以下错误:

错误:项目 'C:\example\path\myproj.csproj' 的目标是 '.NETFramework,Version=v4.6.1'。以“.NETStandard,Version=v1.6”为目标的项目不能引用它。

Cake 是否支持使用新的 VS2017 项目格式针对多个框架进行构建?如果是这样,有没有一种方法可以使用我可以传递给 MSBuild 别名的 MSBuildSettings 参数来做到这一点?非常感谢。

4

1 回答 1

4

Yes Cake 完全支持使用最新的 .NET SDK 1.0.4 和 MSBuild 15.x 构建 VS2017 项目。

Cake 本身是使用 Cake、VS2017 和 .NET Core SDK 1.0.4 https://github.com/cake-build/cake构建的

使用 MSBuild 别名时,请通过将Tool version设置为MSBuildToolVersion.VS2017来确保您使用的是正确版本的 MSBuild 。

MSBuild("./src/Cake.sln", 
    new MSBuildSettings { ToolVersion = MSBuildToolVersion.VS2017
});

如果您将 VS2017 安装在非标准位置,则可以使用 VSWhere 工具和别名来定位正确的 MSBuild 路径

#tool nuget:?package=vswhere 

DirectoryPath vsLatest = VSWhereLatest();

FilePath msBuildPathX64 = (vsLatest==null) ? null : vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/amd64/MSBuild.exe"); 

MSBuild("./src/Example.sln", 
    new MSBuildSettings { ToolPath = msBuildPathX64
}); 

阅读更多相关信息: http ://cakebuild.net/blog/2017/03/vswhere-and-visual-studio-2017-support

于 2017-07-22T06:28:51.230 回答