Targeting multiple frameworks with Cake script

我只是一个虾纸丫 提交于 2020-01-02 18:07:13

问题


A co-worker recently added .NET Standard support to one of our projects using the new VS2017 .csproj format:

This seems to have broken my script as I get the following error when using the Cake MSBuild alias (http://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildAliases/C240F0FB):

error : Project 'C:\example\path\myproj.csproj' targets '.NETFramework,Version=v4.6.1'. It cannot be referenced by a project that targets '.NETStandard,Version=v1.6'.

Does Cake support building against multiple frameworks using the new VS2017 project format? If so, is there a way I can do so with the MSBuildSettings argument I can pass to the MSBuild alias? Thanks a lot.


回答1:


Yes Cake fully supports building VS2017 projects both using latest .NET SDK 1.0.4 and MSBuild 15.x.

Cake itself is built using Cake, VS2017 and .NET Core SDK 1.0.4 https://github.com/cake-build/cake

When using MSBuild alias make sure you're using correct version of MSBuild by setting Tool version to MSBuildToolVersion.VS2017.

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

If you've got VS2017 installed in a non standard location, then you can use the VSWhere tool and alias to locate correct MSBuild path

#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
}); 

Read more about this at: http://cakebuild.net/blog/2017/03/vswhere-and-visual-studio-2017-support



来源:https://stackoverflow.com/questions/45248212/targeting-multiple-frameworks-with-cake-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!