.NET Core - MSBuild and 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 −
It would make the transition of the existing Visual Studio solutions to .NET Core straightforward.
It is a huge change and it will also enable leveraging existing investment in CI/RM based around MSBuild.
During build in MSBuild, we can think of incremental compilation, resolving buildtime dependencies, configuration management, etc.
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.
Following are the changes in MSBuild and *.csproj −
Project.json file (*.xproj) will be replaced by MSBuild (*.csproj).
Features in project.json will start getting merged back into the the *.csproj.
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.
Supposedly that transition should be smooth and potentially automatic if using Visual Studio.
Advantages of MSBuild
MSBuild is open source and available on GitHub and is bound to become fully crossplatform.
MSBuild will dramatically simplify and trim the structure of the *.csproj.
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/.
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
Let us now create a new console project with .NET Core preview2 tooling by executing the following command.
dotnet new -t console
To see all the files created within this project, run the dir command.
You can see that two files are created, Program.cs and project.json file.
Let us now create a console app with .NET Core 2 preview1 tooling by executing the following command.
dotnet new console
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.
Let us now compare project.json and MSBuild.csproj files side by side.
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.