Restoring and Building with MSBuild


Advertisements


In this chapter, we will discuss how to restore and build your MSBuild (*.csproj) file using the command line utility. To see what commands are available in .NET Core 2.0 preview 1, let us run the following command.

dotnet help 

You will see all the commands like new, restore, build, etc.

Restore

Following is the default implementation in Program.cs file.

using System;  
namespace MSBuild { 
   class Program { 
      static void Main(string[] args) { 
         Console.WriteLine("Hello World!"); 
      } 
   } 
} 

Let us now execute the following command to see the progress.

dotnet build

You will see a lot of errors. These errors need to be rectified.

Lot of errors

Let us now run the following command.

dotnet restore

You can see that all the packages are restored. Some new folders and files have also been generated.

Generated

To see the directory structure, let us run the following command.

tree /f 

Following is the directory structure −

Directory structure

Let us now rebuild the project running the following command again.

dotnet build

Now you project will build successfully without any error(s) and MSBuild.dll is also created.

MSBuild.dll

To see the output, let us run the following command −

dotnet run 

You can see the following output on your console.

Console Output

Advertisements