Publishing ASP.NET Core Web API project
We have created a demo web API project PacktContacts
, tested it, and then run it in a local development environment. For production, the application should be published.
.NET Core or ASP.NET Core projects (either MVC or Web API) can be published using either CLI or Visual Studio tooling. We will learn both the ways to publish it.
Publishing by CLI
In Chapter 3, Anatomy of ASP .NET Core Web API, we learned various .NET Core commands. To publish an application, the .NET Core CLI provides us with the dotnet publish
command. It generates the necessary artifacts for running the application.
Open the Command Prompt from the project folder and run the following command to publish:
dotnet publish --output "<output-path>" --configuration release
Breaking down the publish command:
- The
dotnet publish
command compiles the application by referring*.csproj
. It collects all the dependencies and publishes them to a directory. - The
-output
option specifies the directory...