Click here to Skip to main content
15,881,172 members
Articles / Programming Languages / C#

Integrate Jenkins with MSBuild and NuGet

Rate me:
Please Sign up or sign in to vote.
5.00/5 (24 votes)
28 Jan 2016CPOL3 min read 155K   44   14
The next logical step in your build will be to build your solution or projects. I will guide you how to do it via MSBuild as build engine and NuGet for downloading the necessary packages.

In my previous article, “Getting Started with Jenkins and GitHub”, I showed you how to create your first Jenkins job and download the source of your project from GitHub. If your projects are stored in TFS, you can read how to setup your Jenkins job for TFS here: “Integrate Jenkins with Team Foundation Server“. The next logical step in your build will be to build your solution or projects. I will guide you how to do it via MSBuild as build engine and NuGet for downloading the necessary packages.

Install Jenkins Plugins

  • Click Manage Jenkins link:

  • Click Manage Plugins link:

  • Click the Available tab and type the name of the desired plugin in the filter text box:

  • Install the MSBuild Plug-in – This plugin makes it possible to build a Visual Studio project (.proj) and solution files (.sln).

Configure Build Step

  • Open Manage Jenkins Page.
  • Click Configure System link.

  • Under the MSBuild section, click MSBuild Installations… button
  • Enter Name- msbuild.exe
  • Enter default path to msbuild.exe - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MsBuild

  • Open the configure page of your Jenkins job
  • Click Add build step button
  • Select Build a Visual Studio project or solution using MSBuild
  • For MSBuild Version, choose the configuration that you have created – msbuild.exe
  • For MSBuild Build File – enter the path to the project/solution that needs to be built in the format - ${WORKSPACE}\PhantomTube\PhantomTube.sln (${WORKSPACE} is a Jenkins variable that contains the default workspace location)
  • In Command Line Arguments – you can enter msbuild.exe arguments that you use when you build your project though command line. For example /p:Configuration=Release is going to build your project in Release mode. Or you can increase the logging verbosity, etc.

Configure NuGet Package Restoration

In order to restore NuGet packages, you have a couple of options. You can try some of the available plugins. However, my preferred approach is to use Windows batch command.

First, you need to download the NuGet.exe which you are going to use for the operation. 

You need to paste a command like the following in the Command text box: “C:\J\Nuget\NuGet_2.81.exe restore “C:\J\jobs\PhantomTube\workspace\PhantomTube\PhantomTube.sln“”.

The step should be moved above the MSBuild step because in order for the build to be successful, you are going to need all package downloaded beforehand.

Now you are ready to test your setup. Open your job from the link listed on the main Jenkins page. Click the Build Now button.

If you open the console output, you can check the status of your build.

So Far in the Jenkins Series

  1. Integrate Jenkins with Team Foundation Server
  2. Integrate Jenkins and GitHub
  3. Configure Jenkins MSTest Tests Execution
  4. Delete TFS Workspace in Jenkins Job
  5. Output MSTest Tests Logs To Jenkins Console Log
  6. Integrate Jenkins with MSBuild and NuGet
  7. Create Jenkins Job for Creating NuGet Packages
  8. Visual Studio Test Agents Cleaning Scripts
  9. Jenkins Get Source Code By Specific TFS Changeset

 

If you enjoy my publications, feel free to <a href="http://automatetheplanet.com/newsletter/" target="_blank">SUBSCRIBE</a>
Also, hit these share buttons. Thank you!

 

The post - Integrate Jenkins with MSBuild and NuGet appeared first on Automate The Planet.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Automate The Planet
Bulgaria Bulgaria
CTO and Co-founder of Automate The Planet Ltd, inventor of BELLATRIX Test Automation Framework, author of "Design Patterns for High-Quality Automated Tests: High-Quality Test Attributes and Best Practices" in C# and Java. Nowadays, he leads a team of passionate engineers helping companies succeed with their test automation. Additionally, he consults companies and leads automated testing trainings, writes books, and gives conference talks. You can find him on LinkedIn every day.

Comments and Discussions

 
Question'msbuild.exe' is not recognized as an internal or external command Pin
Member 1587716127-Dec-22 6:48
Member 1587716127-Dec-22 6:48 
GeneralMy vote of 5 Pin
yrsk.aravind13-Dec-18 19:29
yrsk.aravind13-Dec-18 19:29 
QuestionHi, I am facing issue in my jenkins buils can you please me out....! Pin
Member 1227015118-Jan-18 7:31
Member 1227015118-Jan-18 7:31 
QuestionNuget From a Batch? Your Favorite. How does this update .csproj Hintpaths? Pin
MarkWardell6-Oct-17 4:42
MarkWardell6-Oct-17 4:42 
PraiseThanks Pin
nishantk2319-Oct-16 2:04
nishantk2319-Oct-16 2:04 
QuestionNice article Pin
Gandalf_TheWhite7-Oct-16 23:43
professionalGandalf_TheWhite7-Oct-16 23:43 
Questionmsbuild section missing after install Pin
Peter Andrews3-May-16 9:32
Peter Andrews3-May-16 9:32 
AnswerRe: msbuild section missing after install Pin
Anton Angelov9-May-16 7:56
Anton Angelov9-May-16 7:56 
GeneralRe: msbuild section missing after install Pin
Member 1370145328-Feb-18 2:36
Member 1370145328-Feb-18 2:36 
GeneralMy vote of 5 Pin
Santhakumar M28-Jan-16 19:15
professionalSanthakumar M28-Jan-16 19:15 
QuestionNuget Command Line Pin
Larry E27-Jan-16 7:31
Larry E27-Jan-16 7:31 
AnswerRe: Nuget Command Line Pin
Anton Angelov28-Jan-16 9:32
Anton Angelov28-Jan-16 9:32 
Thank you for the feedback, I will definitely update the article. Smile | :)
QuestionAre you sure that "the newest versions don’t support the restore command"? Pin
scatp12-Jan-16 9:37
scatp12-Jan-16 9:37 
GeneralMy vote of 5 Pin
Atanas Atanasov23-Feb-15 11:24
Atanas Atanasov23-Feb-15 11:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.