<?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>Florent Clairambault &#187; MSBuild</title>
	<atom:link href="http://florent.clairambault.fr/tag/msbuild/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Insert SVN version and Build number in your C# AssemblyInfo file</title>
		<link>http://florent.clairambault.fr/insert-svn-version-and-build-number-in-your-c-assemblyinfo-file?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=insert-svn-version-and-build-number-in-your-c-assemblyinfo-file</link>
		<comments>http://florent.clairambault.fr/insert-svn-version-and-build-number-in-your-c-assemblyinfo-file#comments</comments>
		<pubDate>Tue, 03 Feb 2009 18:51:35 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=115</guid>
		<description><![CDATA[Software version number is quite important. It helps you track what versions have your users when they report something. And when it’s linked to an SVN version number, it’s even better. Well, with MSBuild Community Task, you can easily automatically generate smart version numbers, you have to: Download MSBuildCommunityTasks Make sure your “svn.exe” binary is [...]]]></description>
			<content:encoded><![CDATA[<p>Software version number is quite important. It helps you track what versions have your users when they report something. And when it’s linked to an SVN version number, it’s even better.</p>
<p>Well, with MSBuild Community Task, you can easily automatically generate smart version numbers, you have to:</p>
<ul>
<li>Download MSBuildCommunityTasks</li>
<li>Make sure your “svn.exe” binary is in C:\program files\subversion\bin</li>
<li>Add this at the end of your .csproject file :</li>
</ul>
<p><strong style="color: red">2011-07-02 update: As <a href="http://thekindofme.wordpress.com/2009/04/27/svn-revision-number-as-version-nunmber-in-vs-through-a-build-target/">given</a> in <a href="http://florent.clairambault.fr/insert-svn-version-and-build-number-in-your-c-assemblyinfo-file#comment-5642">Markus comment</a>, this code is a much better option:</strong></p>

<div class="wp_codebox"><table><tr id="p1153"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p115code3"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Import of the MSBuildCommunityTask targets --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Import</span> <span style="color: #000066;">Project</span>=<span style="color: #ff0000;">&quot;$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- to AssemblyInfo to include svn revision number --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;BeforeBuild&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SvnVersion</span> <span style="color: #000066;">LocalPath</span>=<span style="color: #ff0000;">&quot;$(MSBuildProjectDirectory)&quot;</span> <span style="color: #000066;">ToolPath</span>=<span style="color: #ff0000;">&quot;$(ProgramFiles)\VisualSVN\bin&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Output</span> <span style="color: #000066;">TaskParameter</span>=<span style="color: #ff0000;">&quot;Revision&quot;</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Revision&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SvnVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FileUpdate</span> <span style="color: #000066;">Files</span>=<span style="color: #ff0000;">&quot;Properties\AssemblyInfo.cs&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Regex</span>=<span style="color: #ff0000;">&quot;(\d+)\.(\d+)\.(\d+)\.(\d+)&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">ReplacementText</span>=<span style="color: #ff0000;">&quot;$1.$2.$3.$(Revision)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target</span></span></pre></td></tr></table></div>

<p>You should only have a &#8220;&lt;/Project&gt;&#8221; field left…</p>
<p>Then, you just have to open your project and build your project, it will fail once (missing version.txt file) and then work forever. This will generate your Assembly &#038; AssemblyFile versions like this: Major.Minor.SvnVersion.BuildVersion </p>
<p>In your C# code, to get your version, you just have to add something like that:</p>

<div class="wp_codebox"><table><tr id="p1154"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p115code4"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">String</span> Version <span style="color: #008000;">&#123;</span>
  get <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Assembly</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Version</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/insert-svn-version-and-build-number-in-your-c-assemblyinfo-file/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/15 queries in 0.006 seconds using disk: basic
Object Caching 395/408 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 10:51:55 -->
