Click here to Skip to main content
15,891,567 members
Articles / .NET
Tip/Trick

How To Automate Build Process of ASP.NET Websites using Jenkins and MSBuild

Rate me:
Please Sign up or sign in to vote.
4.43/5 (5 votes)
24 Apr 2015CPOL2 min read 41.5K   7   3
How to build ASP.NET websites using Jenkins

Introduction

Jenkins offers out of the box build solution for Web application, but it becomes difficult to build an ASP.NET website. This article describes step by step how websites can be built using Jenkins.

Background

I had to offer an auto building solution to one of the clients that I was working for. It was an ASP.NET wesite and had dependant projects also. Jenkins could build web applications seamlessly. But there when it comes to website, it becomes an issue.

Using the Code

Pre-requisites

  1. Install Visual Studio .NET 4.0
  2. Install SQL Server management studio 2008 R2
  3. Install Tortoise SVN
  4. Download and install Jenkins Windows native package from http://jenkins-ci.org/

Download and Install MSbuild Extension pack from the below mentioned location:

Setting up Jenkins for Source Code

Add Plugin to Jenkins

  1. Open the URL http://localhost:8080/ in browser.
  2. Click on Manage Jenkins.
  3. Navigate to "Manage Plugin" section.
  4. Click on available tab.
  5. Install Msbuild plugin(Click on install without restart).
  6. Restart Jenkins.

Creating a New Project in Jenkins

  1. Follow all the steps mentioned in "Add plugin to jenkins".
  2. Click on New job.
  3. Choose "Build a free-style software project" option. Add job name and click on "OK". It creates a new project to be built.

Configuration of the Project

  1. Click on the newly created project.
  2. Click on configure.
  3. Under "Source Code Management", choose Subversion module option.
  4. Fill the 'Repository URL' textbox with the corresponding sourcecode URL of SVN.

    Exp- http://svn.xyz.com/svn/admin
    Note- It may ask for credentials. Please fill the credentials for SVN (which you use to log in to SVN) so that Jenkins application can access SVN. Refer to the below image.

  5. Click on 'Add build Step' button and choose 'Build a Visual Studio project or solution using MsBuild' option.
  6. Fill the details as shown in the below image:

    Note - MsBuild file should be the build script file from local directory.

  7. Click on save.
  8. Build the project.
  9. Build details can be seen on the console output section on the left hand navigation panel.

MSbuild script code (The MSbuild script file that was added in the previous step - SourceCodeBuild.msbuild)

XML
<Project ToolsVersion="4.0" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
< PropertyGroup>
< ProductVersion>10.0.11107</ProductVersion>
< TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    </PropertyGroup>
    <Target Name="PrecompileWeb">
        <AspNetCompiler
            VirtualPath="/TestWebSite"
            PhysicalPath="C:\Test-CI\SourceCode\TestWebSite"
            TargetPath="c:\precompiledweb\TestWebSite\"
            Force="true"
            Debug="true" />
    </Target>
< /Project>

Note (Build Script explanation) -

Physical Path - It is the physical path where the code is pulled from SVN. The local working directory.

Target Path - It is the physical location to which your compiled files would be pushed. The user needs to create these paths beforehand.

Points of Interest

It took close to 3 days of effort only to figure out how to write build script for the website to be built.

History

  • 24th April, 2015: Initial version
This article was originally posted at http://gayatriatwork.blogspot.com

License

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


Written By
Team Leader
India India
I have over 8 years of experience in web application development using Microsoft technologies. I work with Happiest minds Technologies.

Comments and Discussions

 
PraiseMy Vote of 5 Pin
NoufNouf20-Dec-15 20:45
NoufNouf20-Dec-15 20:45 
GeneralMy vote of 5 Pin
Phebous27-Apr-15 15:37
Phebous27-Apr-15 15:37 
GeneralRe: My vote of 5 Pin
Gayatri G27-Apr-15 20:05
Gayatri G27-Apr-15 20:05 

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.