Build .NET Project Script Template
  • 09 Jan 2023
  • 4 Minutes to read
  • Dark
  • PDF

Build .NET Project Script Template

  • Dark
  • PDF

A script template is a simple, no-code solution for performing common build or deployment operations and can be converted to OtterScript at any time.

The Build .NET Project Script Template will:

This article will detail the options for these steps, as well as how they're performed.

Using This Script Template

A synchronized Git repository is required for this template, and if your application does not have one, you will not be able to add or edit this script template.

To add this script template to your application, navigate to Scripts, click Add Script, and then select Build .NET Project from the list of Build Script Templates. After doing so, you'll see a dialog like this:


There are a lot of options available, and this article will discuss how these options are used in different steps of the build process.

Note that the dotnet SDK is required on the server you'll run this script on (i.e. your build server). However, you can check the "Ensure dotnet SDK is installed" box in the "dotnet Options" to automatically install the required SDK as part of the build process.

Checking Out from Git

First, the script template checks out code from a Git repository. The branch (or specific commit) is selected when the build is created, before the script is even run. The script will then check out code from that exact commit.

๐Ÿ›  OtterScript Notes

This step uses the Git::Checkout-Code operation without any parameters.

Building/Compiling .NET Project

Next, the script template will use the .NET CLI to build/compile your project.

Project or Solution

Select either a solution (.sln) file or a project file (.csproj) from your source repository that will be built. In most cases, it won't make a difference which one you selectโ€”but for this template, it's generally recommended to use the project file to keep things simple.

NuGet Package Source

Select where to fetch the NuGet packages needed to build your project. This list will typically contain NuGet feeds from your connected ProGet instance, and an option for Not Specified, which will use the public repository.

You can also enter in a custom URL to a feed, though this isn't recommended, as you can create a NuGet feed resource and use that instead.

Build Configuration

By default, this is set to Release, which will perform a standard optimized build. You can set it to Debug or any other build configuration if needed.

Assembly Version

This sets the Ensures that the built .NET assembly has this version. The default value is the variable $ReleaseNumber, which will supply the release number associated with the current build.

๐Ÿ›  OtterScript Notes

When this option is selected, the DotNet::Set-ProjectVersion will be run with the AssemblyVersion parameter.


You can select which dotnet command to use.

  • dotnet publish is Microsoft's recommended command for building an application you intend to deploy, as it includes third-party dependencies in the build output
  • dotnet build may produce the desired results for some applications (especially ASP.NET or .NET Framework applications)

See Microsoft's publish documentation to learn more.

Other Options

Settings for other common operations using dotnet build/publish are also included:

  • Output directory: Build output will be copied here instead of the default output directory
  • Framework: Framework version to build, typically only used for multi-targeted projects. Uses common .NET monikers such as net6.0, net452, netstandard2.0, etc.
  • Runtime: When publishing an executable, specifies the runtime/platform to target such as win-x64, linux-x64, etc.
  • Self-contained: When publishing, include the entire .NET runtime and all required dependencies in the output
  • Additional arguments: These are passed to dotnet exactly as specified
๐Ÿ›  OtterScript Notes

This step uses the DotNet::Build or DotNet::Publish operation, depending on the Command you selected. The parameters will depend on the options you've entered.

Record Dependencies to ProGet

When a ProGet feed is selected for a NuGet package source, a checkbox to scan for package dependencies will appear. If checked, the NuGet dependencies for this build will be recorded in your ProGet instance.

๐Ÿ›  OtterScript Notes

This step uses the ProGet::Scan operation with the Project parameter set to the value of the "Project or Solution".

Running Unit Tests

If any unit test projects are detected, you can select one to run as part of your build script. You can also enter the name of a project if one wasn't detected.

Select a test project will call dotnet test and record the results in BuildMaster. See our unit tests documentation to learn more.

๐Ÿ›  OtterScript Notes

This step uses the DotNet::Test operation with the Project parameter set to the value of the "Test project".

Capturing Build Artifacts

As the last step, BuildMaster will capture artifacts from a path within the working directory that you specify. These are the files that you will deploy later.

The specific path within the working directory can be difficult to predict. For example, according to the dotnet publish documentation, the build's output directory will be:

  • [project_file_folder]/bin/[configuration]/[framework]/publish/ for a framework-dependent executable and cross-platform binaries
  • [project_file_folder]/bin/[configuration]/[framework]/[runtime]/publish/ for a self-contained executable

That's just assuming you even want the output directory; for certain ASP.NET web applications, you may want the project root folder.

Finding the Right Subpath

Usually, the easiest way to find the path you want is:

  1. Create a build using this template
  2. Inspect the build's artifacts
  3. Find the subpath you want within the artifact
  4. Enter that in the "Capture artifacts from:"

Then, the build artifact going forward will contain only those files.

๐Ÿ›  OtterScript Notes

This step uses the Create-Artifact operation, with the parameters depending on the options you've entered.

Was this article helpful?