DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. CI/CD for .NET MVC Using Jenkins

CI/CD for .NET MVC Using Jenkins

Check out how Windows Visual Studio and Jenkins come together to create an effective CI/CD process for .NET applications.

Shivangi Garg user avatar by
Shivangi Garg
·
May. 13, 19 · Tutorial
Like (2)
Save
Tweet
Share
33.80K Views

Join the DZone community and get the full member experience.

Join For Free

Jenkins provides us many ways to set up a CI/CD environment for almost any code language and source code repository. It is an open source automation server which can be used to automate tasks related to building, testing, and delivering or deploying software. It is also an essential tool that aids DevOps teams, which are getting more popular due to the increasing amount of projects we manage at a given period, to ensure their high-quality deliverables. Jenkins has plugins that integrate with third-party source-controllers like Github.

Before we proceed with actual building and deployment, we need to make sure we have build tools installed on the machine.

This can be done through Visual Studio Build Tools, available from the Visual Studio Installer. 

Image title


Then we need to install build tools to build a MVC application. This can be done by clicking the Modify button for Visual Studio Build Tools and then selecting web development build tools.

Image title

If we didn't install these build tools, the msbuild  command would only work in the Developer Command Prompt.

We need to install plugins to use in the Jenkins.

  • Go to Manage Plugins.

  • Find and install the Github Plugin.

  • Find and install the MsBuild Plugin.

I have implemented CI/CD using Jenkins. First of all, you need to download Jenkins and there are a number of ways to use it. I am using it as a windows service on the machine. After starting the Jenkins service, you need to add your application and add the configuration. First, click on "New Item." Then, give the application an Item Name and select the "Freestyle Project" option and then click "OK."

Image title


Now for the configuration.

In the General section, you can enter the description of the item and discard the old builds, it means it will automatically discard builds.

In the Source Code section, I used a Git repository. Here we have to provide the URL of the repository and the branch name from which you want to deploy the code.

Image title

Build triggers can be added if you want the build to be triggered automatically.

Image title


In the build environment, we want to make sure we choose to clean the Jenkins workspace before the build starts.

Image title


Nuget Resrore:

When we commit the code in the repository we don't commit the packages, so first we have to restore the NuGet packages.

As you can see, the code is committed without NuGet dependencies.

Image title

The restore command from the NuGet CLI downloads and installs any packages missing from the packages folder. 

Image title


Once the command is entered, you can see packages folder created with all NuGet dependencies.

Image title


MSBuild:

Now we can actually execute MSBuild command.

This command requires that the MSBuild plugin be installed in Jenkins, path to the sln file and optionally we can also provide the PackageFileName  attribute in  the command line with path and package name.

Image title

Command:

/t:clean;build;package /p:PackageFileName="C:\Program Files (x86)\Jenkins\workspace\HelpDesk_CI\HelpdeskMVC.zip"


MSDeploy:

Msdeploy commad can be used to deploy zip created in previous step to be deployed to IIS.

Image title

Command:

C:\"Program Files (x86)"\IIS\"Microsoft Web Deploy V3"\msdeploy.exe -verb:sync -source:package="HelpdeskMVC.zip" -dest:auto -setParam:name="IIS Web Application Name",value="Default Web Site/Helpdesk"

Note:

In order to deploy zip you need to install "Web Deployment Tool 2.1".

You can install this by right clicking on "Default Web Site" and then going to "Install Application from Gallery".

Image title


Then search for "Web Deployment Tool 2.1" in search box. In my case it is already installed.

Image title


Post Build/Deploy actions:

You can add various post build actions like sending email notifications, archiveing the deloyale artifact etc

Image title

Conclusion:

I created a very basic CI/CD for my .Net MVC application. Jenkins gives us flexibility for adding more complex builds.

Continuous Integration/Deployment Jenkins (software)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • MongoDB Time Series Benchmark and Review
  • Orchestration Pattern: Managing Distributed Transactions
  • How Agile Architecture Spikes Are Used in Shift-Left BDD
  • How To Build a Spring Boot GraalVM Image

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: