Click here to Skip to main content
14,836,169 members
Articles / Programming Languages / C#
Technical Blog
Posted 19 Feb 2015

Tagged as

Stats

130.1K views
44 bookmarked

Integrate Jenkins with MSBuild and NuGet

Rate me:
Please Sign up or sign in to vote.
5.00/5 (23 votes)
28 Jan 2016CPOL3 min read
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)

Share

About the Author

Anton Angelov
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

 
GeneralMy vote of 5 Pin
yrsk.aravind13-Dec-18 19:29
Memberyrsk.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
MemberMember 1227015118-Jan-18 7:31 
QuestionNuget From a Batch? Your Favorite. How does this update .csproj Hintpaths? Pin
MarkWardell6-Oct-17 4:42
MemberMarkWardell6-Oct-17 4:42 
PraiseThanks Pin
nishantk2319-Oct-16 2:04
Membernishantk2319-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
MemberPeter Andrews3-May-16 9:32 
AnswerRe: msbuild section missing after install Pin
Anton Angelov9-May-16 7:56
MemberAnton Angelov9-May-16 7:56 
GeneralRe: msbuild section missing after install Pin
Member 1370145328-Feb-18 2:36
MemberMember 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
MemberLarry E27-Jan-16 7:31 
AnswerRe: Nuget Command Line Pin
Anton Angelov28-Jan-16 9:32
MemberAnton 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
Memberscatp12-Jan-16 9:37 
GeneralMy vote of 5 Pin
Atanas Atanasov23-Feb-15 11:24
MemberAtanas 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.