How To Deploy And Publish a .NET 7 App In IIS?

Introduction

This article demonstrates the step-by-step approach to deploying and publishing a .NET 7 application to Internet Information Services (IIS).

Step 1. IIS Configuration (Optional)

If IIS is not already configured, we could follow the steps below to make it enabled.

Open Control Panel > Programs > Programs and Features > Turn Windows features on or off.

Expand Internet Information Services, World Wide Web Services, and Application Development Features.

Window feature

Step 2. Install the .NET Core Hosting Bundle on the IIS server

Make sure you have a server with IIS installed and properly configured. Otherwise, you can follow the above optional steps.

Ensure that the necessary components for hosting .NET 7 applications are enabled. The hosting bundle installs the .NET Core Runtime, .NET Core Library, and the ASP.NET Core Module.

Please click on the link below to download and run Installer on the Windows server.

Microsoft .NET 7

Please restart the server after installation.

Step 3. Publish to a File Folder

In Visual Studio, right-click the project you want to deploy and choose publish.

Visual Studio

Click on Folder > Next > Folder location will populate the default path as “bin\Release\net7.0\publish\”. > Click on Finish > Publish.

Publish

Folder Location

Publishes Succeeded

OPTIONAL - Alternative way to generate published files,

Open a terminal and navigate to the root directory of your .NET 7 project.

Run the following command to publish your application:

dotnet publish -c Release -o PublishOutput

This will compile your application in Release mode and generate the necessary files in the Publish folder.

Step 4. Copy Files to Preferred IIS Location

Now, copy the published files to the location where they should be stored. In our case, let's copy the files to C:\inetpub\wwwroot\EmpoyeeAPI.

Files

Step 5. Create an Application in IIS & Configure Application Pool

Open the IIS Manager on your server.

Create a new site or use an existing site to host your application. Right-click on the "Sites" node and choose "Add Website".

Provide a site name, a physical path (point it to the PublishOutput folder from the previous step), and an optional hostname.

Physical Path

Make sure the .NET CLR version is set to "No Managed Code" since .NET 7 uses the .NET Core runtime.

Click on Application Pools > Select application pool name > Set the .NET CLR version to "No Managed Code" > Set the pipeline mode to "Integrated".

.NET CLR Version

Step 6. Test your app after deployment

After configuring the site, try accessing it through a web browser. Make sure everything is working as expected.

After deployment

Important points, as we are deploying Web API in our case, generally, Swagger UI middleware is kept under the app.Environment.IsDevelopment() check. For demonstration purposes, I kept this swagger middleware outside of this condition so that we can check the page in a browser.

Swagger

Happy Reading!


Similar Articles