> ## Content Index
> Fetch the complete content index at: https://horrell.ca/llms.txt
> Use this file to discover other available public pages before exploring further.

# Recommendations for MSBuild in a Jenkins pipeline
- URL: https://horrell.ca/2018/12/21/recommendations-for-msbuild-in-a-jenkins-pipeline/
- Published: 2018-12-21T14:00:00.000Z
- Updated: 2024-04-16T02:13:20.000Z
- Author: Christopher Horrell
- Tags: jenkins, MSBuild, #Import 2024-10-01 02:36

MSBuild has a lot of [command line options](https://docs.microsoft.com/en-ca/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2015&ref=horrell.ca) that are relevant when building in a [Jenkins pipeline](https://jenkins.io/solutions/pipeline/?ref=horrell.ca).

A useful command argument to set is `/nodeReuse:false`. This ensures that `MSBuild.exe` exits after being called. The default is `true` and is meant to reduce the startup time for subsequent builds. In a [Jenkins pipeline](https://jenkins.io/solutions/pipeline/?ref=horrell.ca), this isn't really useful since all processes are killed off at the end of a build. In fact, the default `true` option can be problematic in cases where you have later stages in your pipeline that might do a cleanup or a `git clean -fdx` but can't because a `MSBuild.exe` process is holding a file open (like a DLL from a Nuget package).

At work we use declarative pipelines for everything and based on our experience building Visual Studio projects, a simple pipeline would look something like this:

```groovy
pipeline {
  environment {
    MSBUILD = "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
    CONFIG = 'Release'
    PLATFORM = 'x64'
  }
  stages {
    stage('Build') {
      steps {
        bat "NuGet.exe restore your_project.sln"
        bat "\"${MSBUILD}\" your_project.sln /p:Configuration=${env.CONFIG};Platform=${env.PLATFORM} /maxcpucount:%NUMBER_OF_PROCESSORS% /nodeReuse:false"
      }
    }
  }
}
```

It's pretty bare bones, and doesn't include tests, but you get the idea.