是否可以从代码中使用MSBuild来构建asp.net核心项目? [英] Is It possible to build asp.net core project using MSBuild from code?

查看:46
本文介绍了是否可以从代码中使用MSBuild来构建asp.net核心项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用另一个C#项目来构建asp.net核心项目.这是示例代码.(我正在使用Visual Studio 2015)

I want to build asp.net core project using another C# project. Here is the sample code. ( I am using Visual Studio 2015)

var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection(Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry);
projectCollection.DefaultToolsVersion = "14.0";
projectCollection.RegisterLogger(new Microsoft.Build.Logging.ConsoleLogger(Microsoft.Build.Framework.LoggerVerbosity.Detailed));
var project = projectCollection.LoadProject(@"H:\Development\WebApplication22\src\WebApplication22\WebApplication22.xproj");
bool b = project.Build();

它给了我很多错误.以下是其中之一.

It gives me many errors. Following is one of them.

不能执行"GetTransitiveNonDotNetProjectDependencies"任务从程序集C:\ Program Files加载(x86)\ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ DotNet \ Microsoft.DotNet.Tasks.dll.类型'Microsoft.DotNet.Tasks.KProcess'中的方法'get_BuildEngine'来自程序集'Microsoft.DotNet.Tasks,Version = 14.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'没有执行.确认声明正确无误,该程序集及其所有依赖项均可用,并且任务包含一个实现的公共类Microsoft.Build.Framework.ITask.完成目标项目"WebApplication22.xproj"中的"_GetDependencyFragmentFiles"-失败.

The "GetTransitiveNonDotNetProjectDependencies" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Tasks.dll. Method 'get_BuildEngine' in type 'Microsoft.DotNet.Tasks.KProcess' from assembly 'Microsoft.DotNet.Tasks, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' does not have an implementation. Confirm that the 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. Done building target "_GetDependencyFragmentFiles" in project "WebApplication22. xproj" -- FAILED.

注意:如果我使用的是Visual Studio命令提示符并使用MSbuild,那么它将正常工作.

Note : If I am using Visual Studio Command Prompt and use MSbuild then it works fine.

推荐答案

暂时没有.当您从Visual Studio命令提示符运行msbuild来构建asp.net核心项目时,它将调用dotnet.exe进行构建.

No for now. When you run msbuild from Visual Studio Command Prompt to build a asp.net core project, it will call dotnet.exe to build.

MS目前正在努力从.xproj/project.json迁移到.csproj/MSBuild,并且最有可能在Visual Studio 15 RTM中使用.您可以参考此链接以获取更多信息:对Project.json 的更改.

MS is working on moving from .xproj/project.json to .csproj/MSBuild currently and most possible to be available in Visual Studio 15 RTM. You can refer to this link for more information: Changes to Project.json.

此更改的第一波将在Visual Studio"15"中发生RTM:在Visual Studio中打开任何.NET Core项目时,它将自动将.xproj转换为.csproj,将资产从将project.json文件分为配置文件和.csproj文件.我们还将提供使用.NET转换应用程序的工具命令行工具.

The first wave of this change will happen in the Visual Studio "15" RTM: when opening any .NET Core project in Visual Studio, it will automatically convert from .xproj to .csproj, moving the assets from the project.json file into configuration files and the .csproj file. We will also provide a tool for converting applications using the .NET command line tools as well.

这篇关于是否可以从代码中使用MSBuild来构建asp.net核心项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆