Dotnet Core 简明教程

.NET Core - MSBuild and project.json

NET Core 已经决定放弃 project.json 而返回到 MSBuild 和 *.csproj。这是已经发生在刚刚发布的 .Net Core 2.0 preview1 工具中。这样做多少有些令人失望,因为 project.json 带来了一股清新的空气。但这是可以理解的,并且也拥有许多优势。

The .NET Core has decided to drop project.json and go back to MSBuild and *.csproj. This is something that’s already happened in the just released .Net Core 2.0 preview1 tooling. This is fairly disappointing, because the project.json was a breath of fresh air. However, it is understandable and have many advantages as well.

我们现在来讨论这一变更带来的优势 −

Let us now discuss the advantages that the change brings in −

  1. It would make the transition of the existing Visual Studio solutions to .NET Core straightforward.

  2. It is a huge change and it will also enable leveraging existing investment in CI/RM based around MSBuild.

  3. During build in MSBuild, we can think of incremental compilation, resolving buildtime dependencies, configuration management, etc.

  4. A lot of work is required to ship dotnet cli on time, because it is no longer just about ASP.NET Core, but also console apps, UWP apps, etc.

以下是 MSBuild 和 *.csproj 中的更改 −

Following are the changes in MSBuild and *.csproj −

  1. Project.json file (.xproj) will be replaced by MSBuild (.csproj).

  2. Features in project.json will start getting merged back into the the *.csproj.

  3. It is not yet clear what they are going to do about the packages list, but it was mentioned they might keep it as json under nuget.json or merge it into the *.csproj.

  4. Supposedly that transition should be smooth and potentially automatic if using Visual Studio.

Advantages of MSBuild

  1. MSBuild is open source and available on GitHub and is bound to become fully crossplatform.

  2. MSBuild will dramatically simplify and trim the structure of the *.csproj.

  3. Microsoft is also introducing a new project system which will enable a lot of scenarios without the need for Visual Studio and the details are given on the this Url https://github.com/dotnet/roslyn-project-system/.

  4. The goal is that even with the MSBuild setup, working with builds and project will be as seamless in Visual Studio IDE as outside of it.

MSBuild vs project.json

现在通过执行以下命令使用 .NET Core preview2 工具包创建新的控制台项目。

Let us now create a new console project with .NET Core preview2 tooling by executing the following command.

dotnet new -t console

要查看在此项目中创建的所有文件,请运行 dir 命令。

To see all the files created within this project, run the dir command.

run dir

你可以看到创建了两个文件,即 Program.csproject.json 文件。

You can see that two files are created, Program.cs and project.json file.

现在通过执行以下命令使用 .NET Core 2 preview1 工具包创建一个控制台应用程序。

Let us now create a console app with .NET Core 2 preview1 tooling by executing the following command.

dotnet new console

要查看在此项目中创建的所有文件,请运行 dir 命令。你可以看到创建了三个文件,即 Program.cs, NuGet.configMSBuild.csproj ,而不是 project.json 文件。

To see all the files created within this project, run the dir command. You can see that three files are created, Program.cs, NuGet.config and MSBuild.csproj instead of the project.json file.

console

现在让我们并排比较 project.jsonMSBuild.csproj 文件。

Let us now compare project.json and MSBuild.csproj files side by side.

compare

在左边,我们以 json 格式的文件,而在右边,文件是 XML 格式。你可以在 project.json 文件,在依赖关系部分,里面的 netcoreapp1.0 ,而在 MSBuild.csproj 文件,你将看到 netcoreapp2.0

To the left, we have the file in json format while on the right, the file is in XML format. You can see that in the project.json file, inside the dependencies section, there is netcoreapp1.0, while in MSBuild.csproj file, you will see the netcoreapp2.0.