.NET Core 2.0 – How to publish a self-contained application

If you are new with .NET Core 2.0, 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:

dotnet restore


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:



And restore again the dependencies of your project:


dotnet restore


Also, you need to inform the runtime target during the publish:
  • dotnet publish -c release -r ubuntu.16.10-x64




  • dotnet publish -c release -r osx.10.11-x64



If the machine that you want to run the self-contained application does not have the .NET Runtime, and if you decided to use IIS to host your application, in this case like a reverse-proxy, you have to install the .NET Core Module for IIS that is available at ASP.NET Core Server Hosting Bundle.


I hope you liked it.


Comments (24)

  1. mario says:

    I came here to look for how to run an application. I did the publish from VS2017 and i assume it did all this for me. But how do you actually run it?

    1. Hi Mario,
      There are some options to running your application.
      1) You can run from VS2017 by pressing F5 to debug you application.
      2) After publishing to IIS, for example, you can browse the URL http://localhost/ followed by the name of you application (virtual directory)
      3) You can open the cmd, navigate to you app solution folder and type:
      dotnet run
      After that, all you have to do is access you application through http://localhost:5000/ followed by the name of your application.

      1. amrit gautam says:

        HI Luís Henrique Demetrio,

        how could i change the port number from 5000 to any other like 8089

        1. You can use the UseUrls method of WebHostBuilder or you can configure the server address using the configuration.
          Please check the following documentation for more information:

  2. Vinicius says:

    Quick question. Can I publish to Ubuntu or osx from a Windows machine and vice versa?

    1. Yes, All you have to do is publish informing the runtime (Win10-x64, osx.10.11-x64 or ubuntu.16.10-x64). After that, you need to use a tool of you preference to copy the files.

  3. Marcelo Salduendo says:

    Hi Luis,
    Thanks so much for this tutorial.. I’m doing my first steps on asp.net core and this was helpful for me
    Just a question, my publish process does not generate the exe file like yours..
    But, on web config the line seems to be Ok:

    (note that my project name is different)
    I can not figure it out.. what am I doing wrong?
    using VS 2017 Community
    Thanks in advance,

    1. Thanks for your great feedback.
      I think that the easy way to do that is to open up your project file (.csproj) and include the following line inside the PropertyGroup tag:


      After saving the changes, you need to restore the references of the project. You can run the following command:

      dotnet restore

      Finally, you can publish your self-contained application using the following command:

      dotnet publish -c release -r win10-x64

      Observe that I am using the win10-x64 runtime. Feel free to change that.

      The executable file is supposed to be at:


      I hope have helped.


      1. pesquera says:

        Hi Luis,
        The problem about not generating the exe file, was the uppercase
        Just in case, to help somebody else with the same issue:
        correct: dotnet publish -c release -r win10-x64
        incorrect: dotnet publish -c release -r Win10-x64
        Please correct the code above (with the screenshots)
        Best Regards,

        1. Thank you so much for let me know about that. 🙂
          I will fix that immediately.

  4. Steve Bishop says:

    They really need to make it easier to select the runtime. These XML tags are so arbitrary and not documented at all in the CLI documentation. Thank you for explaining it.

  5. Syed Raza says:

    Hi Luís Henrique,

    Hope you will be very fine, I have one question regarding deploying it on hosting server through ftp. What actually published is exe file and I dont understand how can I deploy standalone package on server with IIS support.

    Syed Raza

    1. Thanks for your question.
      In this case, all you have to do is copy the content where your application was published (i.e., dotnet -c realease -r win10-x64) to the IIS application virtual directory. In this case, the IIS will act as a reverse-proxy, where w3wp.exe process will call your application binary. Take a look inside the web.config (after published) to see how it works.
      I hope have helped.

  6. Dan Mills says:

    Hi Luis,
    Thanks for all this.
    My question has to do with the very last paragraph.
    The machine I want to run the self-contained application on belongs to someone else, (godaddy)).
    I have a windows, shared-hosting account with them, and so I expect to use IIS by default.
    They have not installed anything for asp.net core on their servers.
    Is the ASP.NET Core Server Hosting Bundle something I need to install on my machine or does it need to go on the server?

  7. Dev says:

    Have you tried this Console app(.net core). It is not so easy as this… 🙁

    1. The steps is the same. Please, double-check that you are using the following command:
      dotnet publish -c release -r win10-x64

      The executable file will be at:

  8. nam says:

    I published to centos.7-x64 succesfully. Then how can I deploy it to the centos server with Nginx ? I uploaded all files to the server and run dotnet run (or dotnet run myapp) => Couldn’t find a project to run. Ensure a project exists in /var/www/myapp. Or pass the path to the project using –project

    1. Sorry the huge delay to answer you! After one year, I realized that I missed this question. I believe that you already have the answer, but I will post the link here anyway in case it can be useful to anyone else:


  9. Pierre says:

    As the identifier is w10-x64, if I understand well it means it will run on Windows 10 only, right? or not?
    What about if I would like that the generated application be able to run on Windows 8 and 7 as well?
    Thank you

    1. That is a really great question.

      Yes, the win10-x86 or win10-x64 is for Windows 10.

      For other versions you can specify:

      Windows 7 / Windows Server 2008 R2
      Windows 8 / Windows Server 2012
      Windows 8.1 / Windows Server 2012 R2
      Windows 10 / Windows Server 2016

      dotnet publish -c release -r win-x86
      Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
      Copyright (C) Microsoft Corporation. All rights reserved.

      xxx -> C:\temp\xxx\bin\release\netcoreapp2.0\win-x86\xxx.dll
      xxx -> C:\temp\xxx\bin\release\netcoreapp2.0\win-x86\publish\

      More details at:

      I hope it helps.

  10. Thaha Jemni says:

    Just have to say thank you! It really helped me a lot!

  11. Nimish Dhruv says:

    I have one question related to Self contain deployment.
    My project have two console applications project named “CosoleApp1” and “ConsoleApp2”.
    When I publish project the relevant publish folder created inside individual project folder along with “ConsoleApp1.exe” and “ConsoleApp2.exe”.
    So now my question is how to publish solution so all the executables for all project will remain in one common folder so we need to pick only that folder in Self contain package.

Skip to main content