Home  >  Article  >  Backend Development  >  Configuring a .NET continuous integration environment for Jenkins

Configuring a .NET continuous integration environment for Jenkins

大家讲道理
大家讲道理Original
2017-01-24 15:43:422968browse

At the end of last year, thanks to the company's introduction of Jenkins, we took the first step in continuous integration. This article will not go into details on how to install Jenkins. The main focus is on configuring the .Net environment. In addition, this article is based on Jenkins installed in a Windows environment.

1. Installation environment

First we need to prepare several installation packages and install them on Windows:

.NET Framework 4.6.1 https://www.microsoft.com/zh-cn/download/details.aspx?id=49982
Microsoft Build Tools 2015 https://www.microsoft.com/zh-CN/download/details.aspx?id=48159
.NET Framework 4.6.1 Developer Pack https://www.microsoft.com/zh-CN/download/details.aspx?id=49978
NuGet x86 Commandline https://dist.nuget.org/index.html

The first one is of course the familiar .NET Framework running environment;

The second one is MSBuild. Although we usually use Visual Studio to compile and publish programs using the graphical interface, Visual Studio actually calls MSBuild to perform various operations. Therefore, if we want Jenkins to automatically compile code, we must also prepare a set for it. MSBuild.

The third package is the .NET Framework 4.6.1 Developer Pack, which was called Targeting Pack in the past and contains a bunch of assemblies. For example, early versions of Visual Studio 2013 did not have .NET Framework 4.6.1 when it was released. If you want it to support it, you need to install this developer package. If you do not install it, you will be prompted with an error that the System.Object and System.Attribute assemblies cannot be found when compiling the 4.6.1 program later. The 4.6.1 Developer Pack contains the contents of the 4.0, 4.5, and 4.6 Targeting Pack. Installing the 4.6.1 package does not require the installation of other versions of 4.0 packages. In addition, if you need Chinese support, you need to install the English version first, and then install the Chinese language pack.

The last item is the NuGet console program. Before compiling the program, you need to use NuGet to restore the package. This software does not need to be installed, just put it in a fixed location, such as D:\Tools\CI.

2. Install the Jenkins plug-in

Enter the Jenkins plug-in management page and install the MSBuild plug-in at: https://wiki.jenkins-ci. org/display/JENKINS/MSBuild+Plugin

After installation, enter the "Global Tool Configuration" interface:

Find the "MSBuild" column in the opened page, first click "MSBuild Installation", and then click the "Add MSBuild" button to configure the path of MSBuild.exe. Since I use 32-bit MSBuild, I can configure it like this:

Default installation path of MSBuild

32-bit C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe
64-bit C:\Program Files ( x86)\MSBuild\14.0\Bin\amd64\MSBuild.exe

Don’t forget to save after configuring.

3. Jenkins Job Configuration

After preparing the running environment and Jenkins plug-in, let’s create a new Job and give it a try. Our company uses Subversion, so I will download the code from SVN. Using repositories such as Git is also similar, so I will skip it here.

1. Restore NuGet package

We need to add an "Execute Windows batch command" step in the "Build" column to restore the NuGet package Restore

1 D:\tools\CI\nuget.exe restore .\YourSolutionName.sln

First, specify the path of nuget.exe, and then use the restore command to restore the package of the YourSolutionName.sln solution file in the current directory. You can modify it according to your actual situation.

2. Configure MSBuild compilation parameters

Still in the "Build" column, create a new "Build a Visual Studio project or solution using MSBuild" (generated using MSBuild VS project or solution) Steps

From top to bottom, in order

  • The selected MSBuild version

  • The path + file name of the target project or solution file

  • MSBuild parameters

Here we mainly talk about "Command Line Arguments" configuration, for more comprehensive MSBuild documentation, please refer to MSDN: https://msdn.microsoft.com/zh-CN/library/dd393574.aspx

I hope to generate a ASP.NET MVC project and publish it to the file system, mainly using:

  • /t:Rebuild Rebuild

  • /p:Configuration=Release Release generation mode

  • ##/p:VisualStudioVersion=14.0 Specify sub-toolset (https:/ /msdn.microsoft.com/zh-cn/library/bb383796.aspx) version, if not set, an error will be reported

  • /p:DeployOnBuild=True;PublishProfile=Testing-Environment -CI-publish Use the Testing-Environment-CI-publish.pubxml publishing file to publish the project

4. Supplement

[ Updated at 09:30 on January 24, 2017]

Sorry, I missed this when I posted the article last night. If you use MSBuild to compile the project according to the above configuration, you may encounter this error:

The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14" was not found .0\WebApplications\Microsoft.WebApplication.targets”

At this time, you only need to find a computer with Visual Studio 2015 installed and change C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio Copy all the contents in the \v14.0 directory to the directory of the Windows system where Jenkins is located, and then rebuild it.


There may be some content about Jenkins integrating xUnit.net unit testing and automatic release later, but I don’t know if it will be available before the year Can’t post it XD

I hope the article can be useful to everyone.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn