Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

ASP.NET MVC & WebForms

view on GitHub

BuildMaster can help build and deploy your ASP.NET MVC or WebForms applications to Windows (IIS), Linux, and the cloud.

This article will walk through how to automate the build and deployment of an ASP.NET web application.

CI/CD for ASP.NET Web Applications

The best way to build and deploy your ASP.NET Web Applications is with an automated, repeatable process (i.e. a pipeline).

BuildMaster includes several pipeline templates, and you can customize one to follow your current or desired process

The standard, three-environment pipeline is common in most organizations, but you can add and remove stages as needed.

Creating a Build Script for ASP.NET Web Applications

The general process for building an ASP.NET application is as follows:

  • Get source code from the source control repository
  • Compile project with MSBuild or dotnet publish
  • Capture artifact for deployment

Using BuildMaster's Build .NET Project Script Template

BuildMaster includes a number of script templates that offer a simple, no-code solution for performing common build or deployment operations and can be converted to OtterScript to allow more advanced solutions. The Build .NET Project Script Template contains the most common operations needed to pull the source code, build, test (optional), and create an artifact of your ASP.NET application.

buildmaster-dotnet-build-with-npm-template

Using OtterScript Directly

Compiling a ASP.NET Application

To build an ASP.NET application, the first step is to acquire the source code from your SCM of choice, e.g. using Git::Get-Source. Once the source code is obtained, simply run the MSBuild::Build-Project or the DotNet::Publish operation.

Using dotnet publish for .NET 5+

A rough example plan of this would be:

Git::Get-Source
(
    RepositoryUrl: https://github.com/Inedo/ProfitCalc.git,
    Branch: master
);

DotNet::Publish ProfitCalc.Web\ProfitCalc.Web.csproj
(
    Configuration: Release,
    Output: ~\Output
);

Create-Artifact
(
    From: ~\Output\_PublishedWebsites\ProfitCalc.Web
);

The DotNet::Publish operation in this example effectively runs the following dotnet publish command:

dotnet publish ProfitCalc.Web\ProfitCalc.Web.csproj -c Release -o "C:\...<buildmaster-temp>...\Output\\"

Using MSBuild for .NET Framework

A rough example plan of this would be:

Git::Get-Source
(
    RepositoryUrl: https://github.com/Inedo/ProfitCalc.git,
    Branch: master
);

MSBuild::Build-Project ProfitCalc.Web\ProfitCalc.Web.csproj
(
    To: ~\Output
);

Create-Artifact
(
    From: ~\Output\_PublishedWebsites\ProfitCalc.Web
);

The MSBuild::Build-Project operation in this example effectively runs the following MSBuild command:

msbuild.exe ProfitCalc.Web\ProfitCalc.Web.csproj "/p:Configuration=Release" "/p:OutDir=C:\...<buildmaster-temp>...\Output\\"

Restoring NuGet Packages

By default, MSBuild does not restore NuGet packages during a build, but dotnet publish will. This will often the cause of "are you missing an assembly reference" errors. If you get an error message like this, you will need to use the NuGet::Restore-Packages operation.

An example of the NuGet::Restore-Packages operation is as follows:

NuGet::Restore-Packages
(
    Target: ~\Src\<project-name>,
    Source: https://proget.corp/nuget/InternalNuGet/
);

This will essentially call nuget.exe install, and instruct it to look for a packages.config file in the SourceDirectory, and packages in the target Source.

Unit Tests

Unit tests for ASP.NET applications are handled by VSTest. An example operation to execute and capture unit test results is as follows:

WindowsSdk::Execute-VSTest
(
    TestContainer: ~\Output\ProfitCalc.Tests.dll
);

Creating a Deploy Script for ASP.NET

While ASP.NET applications can be hosted on a variety of web servers, Microsoft's Internet Information Services (IIS) is the most common. See our Deploy IIS Site Script Template or our Deploying an IIS Website to learn how to accomplish this with BuildMaster.