<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ORTHOcoders &#187; Versioning</title>
	<atom:link href="http://orthocoders.com/tag/versioning/feed/" rel="self" type="application/rss+xml" />
	<link>http://orthocoders.com</link>
	<description>U can code it, we can help</description>
	<lastBuildDate>Fri, 13 Jan 2012 07:16:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MSBuild scripting part II, Versioning and Deployment</title>
		<link>http://orthocoders.com/2008/12/31/msbuild-scripting-part-ii-versioning-and-deploy/</link>
		<comments>http://orthocoders.com/2008/12/31/msbuild-scripting-part-ii-versioning-and-deploy/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 23:46:36 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[MSbuild]]></category>
		<category><![CDATA[Versioning]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=8</guid>
		<description><![CDATA[MsBuild Introduction MsBuild is a language to create build scripts using predefined tasks. Please check my previous blog for a full description Versioning Before talking about deployment we have to consider how to version our assemblies before copying them to any environment. Having the correct version number is very important once you start a development [...]]]></description>
			<content:encoded><![CDATA[<h2>MsBuild Introduction</h2>
<p style="text-align: justify;">MsBuild is a language to create build scripts using predefined tasks. Please check my <a title="MSBuild Part I" href="http://orthocoders.com/?p=7" target="_blank">previous blog</a> for a full description</p>
<h2>Versioning</h2>
<p>Before talking about deployment we have to consider how to version our assemblies before copying them to any environment. Having the correct version number is very important once you start a development iteration. The QA team needs to know which version to test and report, the user needs to know which version they are seeing, you need to know which version is causing problems, etc&#8230;</p>
<p>.NET uses the <i>Properties/AssemblyInfo.cs</i> file to store the version info. Inside each file you will find the following code:</p>
<pre class="csharp" name="code">
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
</pre>
<p>Here is a brief description of the recommended usage of each number:</p>
<ul>
<li>Major: This number indicates a big difference between versions. When it changes the user will expect &#8220;Major&#8221; changes in functionality.</li>
<li>Minor: This number indicates fixes, bugs, etc. Still same functionality but with some modifications.</li>
<li>Build: This number indicates the amount of times you built the app so far. (not always used)</li>
<li>Revision: This number indicates the revision number from your source control. This number is very important because it would give you the information needed in order to check the revision you need and be able to reproduce bugs, errors, etc.</li>
</ul>
<p>So far, so good. We just need to change all the files in each project and put the same version&#8230; and when it changes&#8230; again&#8230; easy, right?</p>
<h3>MsBuild to the rescue</h3>
<p>Not to fret my friend, luckily we have <i>msbuild</i> on our side. First of all we will define the version we want in or <i>msbuild</i> file, using a property group.</p>
<pre class="xml" name="code">
	&lt;Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/&gt;

	&lt;PropertyGroup&gt;
		&lt;ProjectName&gt;MediaLibrary&lt;/ProjectName&gt;
		&lt;ExportFolder&gt;\temp\Export\$(ProjectName)&lt;/ExportFolder&gt;
		&lt;BuildFolder&gt;\temp\Builds\$(ProjectName)\Latest&lt;/BuildFolder&gt;
		&lt;Major&gt;0&lt;/Major&gt;
		&lt;Minor&gt;1&lt;/Minor&gt;
		&lt;Build&gt;0&lt;/Build&gt;
	&lt;/PropertyGroup&gt;
</pre>
<p>As you can see the revision number is not included because we would like to use the source control tool to get the revision number every time we run the script to make sure we always have the right version.</p>
<p><a title="Tigris.org" href="http://msbuildtasks.tigris.org/" target="_blank">Tigris</a> has a set of tasks that will help us to achieve our goal. You can download it for free and install it.</p>
<p>Now that we have the version we want (<em>Major.Minor.Build</em>) we need to get the revision number from the repository and store it into a property. Because I use SVN I&#8217;ll use the <em>SvnVersion</em> task from Tigris to get the version number and store it into the property <em>Revision</em>.</p>
<p>If you also use SVN you will need a command line tool in order to run <i>svnversion</i>. <a title="SVN client Collabnet" href="http://www.collab.net/downloads/subversion/" target="_blank">Collabnet</a> has a free SVN client you can download and use.</p>
<p>After finding the version number we need to find all the files that we would like to change. For that purpose we will define another <em>ItemGroup</em> including all the <em>AssemblyInfo.cs</em> files in our hierarchy and store them into the variable <em>AssemblyFiles</em>.</p>
<p>The final step is to replace each declaration with the version in the <em>AssemblyInfo.cs </em>file with the version we defined in our build file using the <em>FileUpdate</em> task for each <em>cs</em> file.</p>
<pre name="code" class="xml">
&lt;Target Name=&quot;UpdateAssemblyVersion&quot;&gt;
		&lt;SvnVersion LocalPath=&quot;$(MSBuildProjectDirectory)&quot;&gt;
	      &lt;Output TaskParameter=&quot;Revision&quot; PropertyName=&quot;Revision&quot; /&gt;
		&lt;/SvnVersion&gt;

		&lt;ItemGroup&gt;
			&lt;AssemblyFiles Include=&quot;**\AssemblyInfo.cs&quot;/&gt;
		&lt;/ItemGroup&gt;

 	    &lt;Message Text=&quot;Version: $(Major).$(Minor).$(Build).$(Revision)&quot;/&gt;

		&lt;FileUpdate Files=&quot;@(AssemblyFiles)&quot;
                Regex=&quot;(\d+)\.(\d+)\.(\d+)\.(\d+)&quot;
                ReplacementText=&quot;$(Major).$(Minor).$(Build).$(Revision)&quot; /&gt;

&lt;/Target&gt;
</pre>
<p>The <em>FileUpdate</em> task uses a regular expression to find the version number. In this case we are looking for four digits separated by dots and as replacement we use the variables we defined previously.</p>
<h2>Deployment</h2>
<p>Alright. We have all our assemblies (executable, etc) with the right version and we are ready to roll.<br />
Now, we need to build again to include the right version in release mode and then copy the files to the destination of our preference. </p>
<p>A common practice is to copy the files to a folder where all the team knows the latest version will reside. Using a continuous integration tool like <a href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET" target="_blank">Cruise Control .NET</a> or <a href="http://www.jetbrains.com/teamcity/download/" target="_blank">TeamCity</a> makes easier to have always the latest version available as soon a new change is committed to the repository.</p>
<p>I&#8217;ll call this task <em>DeployBin</em> and will do the following:</p>
<ul>
<li>Delete the destination folder</li>
<li>Call the <em>UpdateAssemblyVersion</em> task to update to the latest version of all the <em>Assembly.cs</em> files.</li>
<li>Build again (Release mode) to have the latest binaries with the version updated.</li>
<li>Create the destination folder.</li>
<li>Define a variable called <em>SourceFiles</em> using an <em>ItemGroup</em> to include all the assemblies I would like to copy and excluding the ones I don&#8217;t need (testing assemblies).</li>
<li>Copy all the files listed in the <em>SourceFiles</em> variable to the chosen destination.</li>
</ul>
<p>Ready? Here is the magic:</p>
<pre name="code" class="xml">
	&lt;Target Name=&quot;DeployBin&quot;&gt;
		&lt;RemoveDir Directories=&quot;$(BuildFolder);$(ExportFolder)&quot; ContinueOnError=&quot;true&quot; /&gt;
		&lt;CallTarget Targets=&quot;UpdateAssemblyVersion&quot;/&gt;
		&lt;CallTarget Targets=&quot;Build&quot;/&gt;
		&lt;MakeDir Directories =&quot;$(BuildFolder)&quot;/&gt;
		&lt;ItemGroup&gt;
			&lt;SourceFiles Include=&quot;**\bin\Release\*.dll&quot; Exclude=&quot;**\*.Tests\bin\release\*.dll&quot;/&gt;
		&lt;/ItemGroup&gt;
		&lt;Copy SourceFiles=&quot;@(SourceFiles)&quot;
				DestinationFolder=&quot;$(BuildFolder)&quot;&gt;
			&lt;Output TaskParameter=&quot;CopiedFiles&quot; PropertyName=&quot;Copied&quot;/&gt;
		&lt;/Copy&gt;
	&lt;/Target&gt;
</pre>
<p>Voila! That&#8217;s it! You can make the deployment as complicated as you want. You can separate the folders, rename the previous version, etc, etc.</p>
<p>Here is the <a href='http://orthocoders.com/wp-content/uploads/2009/01/medialibrary.msbuild'>complete file</a> in case you would like to look at it. I hope you will find it useful.</p>
<p>In my next blog about <em>MSBuild</em> we will talk about creating custom tasks.</p>
<p>Any feedback is most welcome.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2008/12/31/msbuild-scripting-part-ii-versioning-and-deploy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use MSbuild to build and test</title>
		<link>http://orthocoders.com/2008/12/12/how-to-use-msbuild-to-build-test-version-and-deploy/</link>
		<comments>http://orthocoders.com/2008/12/12/how-to-use-msbuild-to-build-test-version-and-deploy/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 21:08:17 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MSbuild]]></category>
		<category><![CDATA[Versioning]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=7</guid>
		<description><![CDATA[What is a build script? A build script is a small program written in the language of your choice that usually has more than one task used by the developer to build, test, deploy, etc&#8230; Why do I need a build script? A build script can give you the ability to compile, run tests, and [...]]]></description>
			<content:encoded><![CDATA[<h3>What is a build script?</h3>
<p style="text-align: justify;">A build script is a small program written in the language of your choice that usually has more than one task used by the developer to build, test, deploy, etc&#8230;</p>
<h3>Why do I need a build script?</h3>
<p style="text-align: justify;">A build script can give you the ability to compile, run tests, and build libraries, etc, without using the IDE. This is most useful before committing code to the repository and also, after the source is committed before being run by the continuous integration service.</p>
<p style="text-align: justify;">Doing all these tasks manually can be tedious and error prone.  If you are also suffering from lack of documentation the knowledge of the process will leave with the developer in charge of compiling, building, etc.</p>
<p style="text-align: justify;">Thus, instead of spending time writing documentation why not write a script to do all the steps for us and achieve the same results?</p>
<h2>Enters MS Build</h2>
<p style="text-align: justify;">MS provides a script building language based on XML. Very similar to Ant and NMake this XML based script has many predefined tasks that allow us to compile, build, etc, etc&#8230;</p>
<h3>How do I Start?</h3>
<p>Here is a minimal ms build file called algorithm.msbuild used to compile our solution in release mode:</p>
<pre class="xml" name="code">&lt;Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
	&lt;ItemGroup&gt;
		&lt;Solutions Include="**\*.sln"/&gt;
	&lt;/ItemGroup&gt;

	&lt;Target Name="Build"&gt;
		&lt;MSBuild Projects="@(Solutions)" Properties="Configuration=Release"/&gt;
	&lt;/Target&gt;
&lt;/Project&gt;</pre>
<p>The project tasks are identified by the tag <em>Target </em>. The code above defines one called <em>Build</em>. Inside the task you can see a call to the <em>MSBuild </em> task used to compile all the solutions defined in the variable <em>@Solutions</em>. This variable is declared inside an <em>ItemGroup </em>which allow us to use the <em>wildcards</em> to match all the solutions in our current folder and subfolders.</p>
<p>To run this file, open a command window and run:</p>
<pre class="xml" name="code">
msbuild algorithm.msbuild  /t:Build
</pre>
<h3>Clean and rebuild</h3>
<p>In order to rebuild our assemblies we need to be able to clean all the projects and then build them again.</p>
<p>In order to do that we are going to use the internal predefined task <em>Clean</em> that comes with the default target definitions when you install vs.</p>
<pre class="xml" name="code">
&lt;Target Name="Clean"&gt;
     &lt;MSBuild Targets="Clean" Projects="@(Solutions)" Properties="Configuration=Release"/&gt;
&lt;/Target&gt;

&lt;Target Name="Rebuild"&gt;
     &lt;CallTarget Targets="Clean;Build"/&gt;
&lt;/Target&gt;
</pre>
<p>The <em>Rebuild</em> target uses the previous defined targets <em>Build</em> and <em>Clean</em> to achieve our goal.</p>
<h2>Testing</h2>
<p style="text-align: justify;">Testing is an integral part of development and for each library or executable we build we should have our test counterpart.</p>
<p style="text-align: justify;">In this case I&#8217;m using <em>MBunit </em>and when you install <em>Gallio </em>(test runner) it will also install an assembly with <em>MSBuild </em>related tasks to be used in our scripts.</p>
<p style="text-align: justify;">First we have to include the <em>Gallio </em>task library to be used in our script file and then we can call the test runner to load all our assemblies that contain tests.</p>
<pre class="xml" name="code">
&lt;UsingTask TaskName="Gallio.MSBuildTasks.Gallio" AssemblyFile="c:\program files\gallio\bin\Gallio.MSBuildTasks.dll"/&gt;
&lt;Target Name="Test"&gt;
     &lt;ItemGroup&gt;
          &lt;TestAssemblies Include="**\bin\release\*.Tests.dll"/&gt;
     &lt;/ItemGroup&gt;
     &lt;Gallio Assemblies="@(TestAssemblies)"
          WorkingDirectory=""
          ApplicationBaseDirectory="$(SolutionFolder)\src\"
          IgnoreFailures="true"
          ReportDirectory="$(CCNetLastBuildFolder)"
          reportNameFormat="Test-Report"
          ReportTypes="Xml"
          ShowReports="false"
          &gt;
          &lt;Output TaskParameter="ExitCode" PropertyName="ExitCode" /&gt;
     &lt;/Gallio&gt;
     &lt;Error Text="Testing failed" Condition="$(ExitCode) == 1"/&gt;
&lt;/Target&gt;
</pre>
<p style="text-align: justify;">As you can see I&#8217;m using another <em>ItemGroup</em> to define the assemblies that should be included in the testing. By convention I name all my test assemblies with the postfix Tests in order to be able to identify them easily.</p>
<p>I won&#8217;t describe in detail all the attributes in here but you have to be careful with the test exit code.</p>
<p style="text-align: justify;">The last line of the task contains an Output parameter. That is a variable that is going to be defined after the task runs. In this case the exit code is most important because it will indicate if the test has passed or not. Because the <em>Gallio</em> task does not update this value we need to check for it after running all the tests to be able to make the build fail if the tests fail.</p>
<p style="text-align: justify;">The last line of the <em>Test</em> task uses the built in <em>Error</em> task to generate an error only when the <em>ExitCode</em> equals one indicating that the testing has failed.</p>
<p>Please follow the links to read more about <a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx">MSBuild </a>and <a href="http://www.mbunit.com/">MBUnit</a>.</p>
<p>Part II shows how to version our files using the version number from the repository and copy them to a different location. Go to <a href="http://orthocoders.com/?p=8" target="_blank">MSBuild Part II</a>.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2008/12/12/how-to-use-msbuild-to-build-test-version-and-deploy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

