Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
24 Apr 2015 1  
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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here