How to Configure Jenkins to build .net projects?

Scenario: Adding Capability to Jenkins to Build .net Projects

  • Lets assume our ficticious organization ASquareZone has a DevOps Team and they were asked to setup a Jenkins Build for .net Project.
  • Now DevOps Team has to setup Daily builds for .net projects.
  • There are two .net Projects One which is Classic/Standard .net Framework Based which can be built only on windows Systems (Traditional .net Projects) and the Other One is based on .net Core which can be built on linux flavor

Solution

Design

  • The DevOps Team has setup the Jenkins setup as shown below
  • Ubuntu 18.04 with dotnet core installed will be the Jenkins Master Node
  • Windows 2016 server with Visual Studio 2019 Build Tools installed will be Jenkins Agent Node for .net Standard Project Build Preview

Setup

  1. Create a Virtual Machine in AWS/Azure or any other environment with Ubuntu 18.04
    • In this series, I will be using a virtual machine created in Azure with 2 virtual cpus and 8 GB of RAM
    • For steps on How to create a VM on Azure Refer Here and on AWS Refer Here
  2. Now login into this VM after installing Java and Jenkins, Ensure you install dotnet core on this machine, Refer Here for steps. Remember to check whether the jenkins user has the proper permissions setup.
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo add-apt-repository universe
sudo apt-get update
sudo apt-get install apt-transport-https -y
sudo apt-get update
sudo apt-get install dotnet-sdk-3.1 -y
sudo apt-get install aspnetcore-runtime-3.1 -y
sudo apt-get install dotnet-runtime-3.1 -y
  1. Now Create a Virtual Machine in AWS/Azure or any other environment with Windows 2016 DataCenter

    • Install Chocolatey on the Windows Machine Refer Here, Restart the machine and execute
    choco install jdk8 -y
    choco install googlechrome -y
    
    • Download BuildTools for VisualStudio 2019 (This version can be other) and select the dotnet build tools as shown below Preview
  2. Ensure this windows server is added as an agent to jenkins machine

  3. Ensure the MSBuild Plugin is installed Preview

  4. Now Navigate to Manage Jenkins => Global Tools => MSBuild and Configure as shown below Preview

  5. Now we are all set to use Jenkins Build on .net

Implementing

Dotnet Core Build on Linux Machine

  • For this activity lets take forked version of nopcommerce from here
  • Now lets create a new Jenkins Job with Free style
  • Have a look into General section, Source code and BUild sections it the following images Preview Preview Preview
  • Now Build the Project and check the output
  • dotnet restore command will restore dependencies
  • dotnet build command will create the build for the project

Dotnet Project MSBuild on Windows Machine

  • In classic dotnet projects we need msbuild to be installed to build the projects and to resolve dependencies we need a tool called as nuget
  • Nuget tool is part of version control in some .net repos, if it is not download nuget from here and ensure to add this nuget to the folder which is added to PATH environment variable
  • Msbuild command line Refer Here
  • For building the code lets use the code from the repository here Preview Preview Preview

2 thoughts on “How to Configure Jenkins to build .net projects?

  1. That’s quite informative and elaborate – I was getting stuck in many places when I first tried without this guide, but now as I have had a read through I clearly understand where I went wrong – thanks a lot for this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner