If you are new with .NET Core 1.1, please take a look at the post .NET Core 1.1 – Where to Start first.
I am assuming you already have an ASP.NET MVC application created and build. If you don’t have, please check the following post: NET Core 1.1 – Creating an ASP.NET Core using the .NET CLI for details about how to create an ASP.NET Core MVC application.
The idea of this post is to show you how to create a self-contained application that does not requires that the .NET SDK be installed on the target machine.
The first thing that we need to do is to edit the .csproj file, in my case the HelloWorld.csproj, to include the runtimes. By default, the .csproj is created as follows:
If I want to publish a self-contained version of my application to Windows, for example, all I have to do is to modify the .csproj including the following line:
After saved the changes, it is necessary to run the following command to restore the dependencies:
To generate the self-contained application, run the following command:
dotnet publish -c release -r Win10-x64
As I am using the runtime Win10-x64, the outcome files will be generated inside the folder win10-x64\publish:
Observe that this time, the application was build with the .exe extension instead of .dll. If you open up the web.config of this publish folder, you will notice that this file does not refers to the dotnet.exe anymore:
Now, lets suppose that you would like to publish to MAC or Linux. In this case, all you need to do is to add the following runtime to the .csproj file:
- dotnet publish -c release -r ubuntu.16.10-x64
- dotnet publish -c release -r osx.10.11-x64
I hope you liked it.