Build Net Framework web application referencing net-standard library with Cake build

允我心安 提交于 2019-12-11 04:13:13

问题


I have two projects: NET Standard class library and regular NET Framework web application. Web application references class library.

I use Visual Studio 2017 Preview.

When I try to build the solution with Cake using MSBuild command I get the unsupported project message:

error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MS Build 2003 format.

If I try to use DotNetCoreBuild I get:

error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.0.2-vspre-006949\Microsoft\VisualStu dio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

But the solution is built successfully by Visual Studio.


回答1:


Latest MSBuild version has the targets to build NET Standard libraries. The problem is in Visual Studio Preview installation path: Cake can't find the latest MSBuild.

It will also fail if you will try to specify VS2017 in MSBuildToolVersion.

You have to specify the MSBuild executable manually to make it work with VS Preview.

string msBuildPath = @"c:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\15.0\Bin\MSBuild.exe";

MSBuild("../NetStdExample.sln", new MSBuildSettings {
    Verbosity = Verbosity.Minimal,
    ToolPath = msBuildPath
});

Update by @Gary Ewan Park: there is a tool for determining latest VS install.



来源:https://stackoverflow.com/questions/46179678/build-net-framework-web-application-referencing-net-standard-library-with-cake-b

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