BuildMaster Documentation

Building an ASP.NET MVC or WebForms Application

  • Last Modified: 2019-12-04

ASP.NET MVC is the most popular web framework built for .NET that allows developers to build maintainable, scalable, cross-platform web applications. By separating concerns (i.e. not coupling the HTML views with the database backend and vice-versa), teams of developers with a variety of skillsets are able to focus on their areas of expertise without having to understand the intimate details of the underlying framework like its predecessor ASP.NET WebForms.

Building ASP.NET Applications

MSBuild (Microsoft Build Engine) is a tool for building all types of .NET applications, and it's used internally by Visual Studio to build projects and solutions. CI servers would perform similar build tasks or operations by invoking MSBuild operations.

MSBuild doesn't require Visual Studio to be installed, but you will need to install and configure the following:

  • Visual Studio Build Tools are installed
  • Ensure that ".NET desktop build tools" and "Web development build tools" options are chosen during installation/modification

The simplest way to build a web application is by running MSBuild directly:

msbuild.exe MyWebProject.csproj "/p:Configuration=Release" "/p:OutDir=C:\tmp\website\\"

The difference between web applications from other types of applications (e.g. console applications, WinForms, or WPF) is that when an output directory is specified, the build output is generated in a special subdirectory in the format:

<outputDir>\_PublishedWebsites\<projectName>

The contents of this output directory are the files that would be deployed to the IIS home directory.

Building ASP.NET Applications with BuildMaster

Because building ASP.NET applications simply involves running MSBuild, building ASP.NET applications is simple with BuildMaster. Behind the scenes, BuildMaster uses the MSBuild::Build-Project operation to run MSBuild.

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

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

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, which is often the cause of "are you missing an assembly reference" errors.

To install NuGet packages before running MSBuild, use the NuGet::Restore-Packages() 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
);

Deploying ASP.NET Applications to IIS

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

Is this documentation incorrect or incomplete? Help us by contributing!

This documentation is licensed under CC-BY-SA-4.0 and stored in GitHub.

Generated from commit bd2ce6f3 on master