How to publish .NET Core 3.x MVC application from Visual Studio 2019

Sheonarayan
Posted by in .NET Core category on for Intermediate level | Points: 250 | Views : 18228 red flag

.NET Core 3.x is the way forward in .NET Core platform from Microsoft as support for .NET 2.x is stopped officially. In this article, I will demonstrate steps to follow to publish .NET Core 3.x MVC application using Visual Studio 2019.
In order to publish our .NET Core 3.x MVC application using Visual Studio, ensure that your application is building without any error. In this article I have used Microsoft Visual Studio 2019 (latest version) to demonstrate the steps to publish project.

First right click your Project (not your solution) and select Publish.... as shown in the picture below.


This will open up Publish tab in the Visual Studio as shown below. First we need to create a Profile, this is as simple as writing name in the Textbox displayed (in my case its FolderProfile1, you can give any meaningful name). 

  • Check the Target Location, this is generally the bin/Release folder of your project.
  • Check Delete Existing Files to true, this is good as you may want to publish your project again and again and you don't want old files to remain there that might not be used by the latest version of your application.



  • Check Configuration, this opens up another dialogue box as shown below. This lets you select following
    • Configuration - Whether to publish in Debug or Release mode
    • Target Framework - Framework to Target with this publish. Better to select latest version of .NET Core
    • Deployment Mode - Select Framework-Dependent assuming you server will have .NET Core 3.x runtime installed. Another benefit is that his is comparatively smaller in size. The other mode is Self-contained that will have all the Core framework related files as well related with your project specific .dlls. To know more about Deployment Mode, click here.
Click on Save button.




Now click on Publish button on the Publish tab. This will start building your project that you can see in the Output window of Visual Studio and if everything goes right, you will see a success message like below.



Your folder structure under bin/release/{framework-version}should look like below. 



Most of the folders and files displayed above are related with supporting plugins or namespaces you use in your project so you just need the publish folder (to host your application on the server, see picture below) where you have all your project specific files like wwwroot (contains your .css, js, images etc), Views (MVC .cshtml files) and Areas (different areas in the form of modules of your applications).

IMPORTANT: In .NET Core 3.x build by default Views folders are not created rather, it is built inside the ProjectName.dll when you publish. This is something I didn't want, because if I want to do some small changes in views html, css class or js, I will have to republish the entire project and upload again. Thankfully, there is solution of this project explained here



This comes to the final stage where we have our application ready to be hosted. I will explain how to host this published application on Windows server in the next article.

Hope you liked this article, do share your feedback and comment. Feel free to ask any questions or facing any problems while following steps explained in this article.

Thanks for reading.

Page copy protected against web site content infringement by Copyscape

About the Author

Sheonarayan
Full Name: Sheo Narayan
Member Level: HonoraryPlatinum
Member Status: Administrator
Member Since: 7/8/2008 6:32:14 PM
Country: India
Regards, Sheo Narayan http://www.dotnetfunda.com

Ex-Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001. Connect me on http://www.facebook.com/sheo.narayan | https://twitter.com/sheonarayan | http://www.linkedin.com/in/sheonarayan

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)