Skip to main content

C# VS 2013 with Jenkins build server, git native on TFS 2013, installing git-extensions on windows server 2012 and http checkout including msbuild

C# VS 2013 with Jenkins build server, git native on TFS 2013, installing git-extensions on windows server 2012 and http checkout including msbuild


What a title, huh?
well, git still is a bit exotic under windows... if you don't use the default tools. though its MUUUUCH better than a few years back.

now i wanted to set up a build server for my company, and i decided to use jenkins, mostly out of curiosity how it performs with .NET.
after all i used it for 1 year with java source code and was very happy with it, now i wanted to see how it does with C#.

but first i need to overcome several obstacles...

here is my system:

* a windows server 2012
* a TFS 2013 (express) that has our C# source code hosted in the (now-native) git repository. this means its accessible over HTTP
* our source code uses nuget...


install jenkins, install git plugins, install msbuild plugin, install git version 2.48 (NO EARLIER VERSION!!!!) and INSTALL EVERYTHING UNDER LINUX folder instead of Program Files(x86), i learned that
the hard way that you else can have nasty hickups... also make sure to tell the installation to use the credential manager; when installing you can choose to install msysgit, kdiff3 and the credentialsmanager. make sure you install and use the 3rd one!
install vs2013 express WEB EDITION! i needed the web edition, because the other one could not build WCF projects. best thing of course is to install a pro version if you have a license lying around...

in jenkins go to "Configure System", set "C:\Linux\Git\bin\git.exe" as "Path to Git executable".


go to jenkins, system configuration. under MSBuild create a new one, give it a name:

"MsBuild"

set MS-Build path to
"Path to MSBuild              ": "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" as we use the lastest vs, so i use the latest version directory i find...


THATS RIGHT GUYS; YOU HAVE TO SPECIFY THE EXE IN THE PATH!!! that took me a while until i had figured that out...


then you create a "free" project in jenkins, as source code managment you choose "git" and enter the URL of the TFS. for me this lies under
http://192.168.0.80:8080/tfs/companyname/_git/projectname

as the credentials i used my own domain account that is also member of the team for "projectname".

under build triggers, i build every 15 minutes so i used:

"Poll SCM":
 with
 "H/15 * * * *"


 first i add a build step that runs a small script:

 choose "execute windows command batch" and put the following there:

echo "down hacking the nuget package manager... i know this is a volatile script:"
echo "NOTE: in case you have an access error, relax security on 'jobs' folder"

"C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\nuget.exe" restore "C:\Program Files (x86)\Jenkins\jobs\test3\workspace\testcheckout\myCompanyName.sln"
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86


 now i went to the directory
  "C:\Program Files (x86)\Jenkins\jobs\test3\workspace"
 and gave access to EVERYBODY onto that file, else nuget will not be able to install the packages there...

 then i added a build step, chose "build a visual studio project or solution using msbuild" and as our .sln file is just in the root git directory i just put inside
 "myCompanyName.sln". choose the "MsBuild" we created earlier instead of using the default!!!

 now i gave msbuild a parameter:
 "/p:VisualStudioVersion=12.0"

 because i had an external build error something like this:
 * External VS2013 build error “error MSB4019: The imported project <path> was not found”
 * The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
  
 the parameter for msbuild fixed that.
  
 after i was done i found a good explanation for setting up some standard .NET stuff with jenkins... if i had seen it beforehand, it would have saved quite some time!
 i will post it with some articles that helped me come to those solutions. i know they are not yet completely refined and its still a bit hacky, but that can be solved later on!

 http://dotdotnet.blogspot.co.il/2011/11/building-net-application-with-jenkins.html
  http://justinramel.com/2012/09/17/jenkins-dot-net/
  http://docs.nuget.org/docs/reference/package-restore-with-team-build
  http://stackoverflow.com/questions/19718281/external-vs2013-build-error-error-msb4019-the-imported-project-path-was-not
  http://www.techques.com/question/1-10227967/build-.net-application-in-Jenkins-using-MSBuild
  http://stackoverflow.com/questions/8563325/mvc-project-on-vs2010-error-the-project-type-is-not-supported-by-this-installa
  http://stackoverflow.com/questions/8639501/jenkins-could-not-run-git
  http://jenkins-ci.361315.n4.nabble.com/Failed-to-connect-to-repository-Could-not-init-tmp-td4699972.html
  https://github.com/gitextensions/gitextensions/issues/1492
  https://github.com/gitextensions/gitextensions/issues/2354
  https://groups.google.com/forum/#!topic/jenkinsci-users/dgpZKtt7k-8
  http://mindinthewater.blogspot.co.at/2011/02/executing-visual-studio-2010-unit-tests.html
 http://dotdotnet.blogspot.co.il/2011/11/building-net-application-with-jenkins.html




Comments

Anonymous said…
Thank a lot ! You are the best !