<?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>Wed, 28 Jul 2010 20:31:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</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&amp;utm_medium=rss&amp;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>

<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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</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 manage version 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;Version&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Version</span> <span style="color: #000066;">VersionFile</span>=<span style="color: #ff0000;">&quot;version.txt&quot;</span> <span style="color: #000066;">RevisionType</span>=<span style="color: #ff0000;">&quot;Increment&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;Major&quot;</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Major&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;Minor&quot;</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Minor&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;Build&quot;</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;Build&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;/Version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- to generate our personnal version info --&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;AssemblyInfo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <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: #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;Build&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;AssemblyInfo</span></span>
<span style="color: #009900;">    <span style="color: #000066;">CodeLanguage</span>=<span style="color: #ff0000;">&quot;CS&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">OutputFile</span>=<span style="color: #ff0000;">&quot;Properties\AssemblyInfo.cs&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyTitle</span>=<span style="color: #ff0000;">&quot;Title&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyDescription</span>=<span style="color: #ff0000;">&quot;Description&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyCompany</span>=<span style="color: #ff0000;">&quot;Company&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyProduct</span>=<span style="color: #ff0000;">&quot;product&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyCopyright</span>=<span style="color: #ff0000;">&quot;Copyright © 2009&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">ComVisible</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">Guid</span>=<span style="color: #ff0000;">&quot;88812638-9547-4480-9bf4-4fe25103b35c&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyVersion</span>=<span style="color: #ff0000;">&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">AssemblyFileVersion</span>=<span style="color: #ff0000;">&quot;$(Major).$(Minor).$(Build).$(Revision)&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;$(Revision) != '0' &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 style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- We launch these two targets --&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;CallTarget</span> <span style="color: #000066;">Targets</span>=<span style="color: #ff0000;">&quot;Version&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CallTarget</span> <span style="color: #000066;">Targets</span>=<span style="color: #ff0000;">&quot;AssemblyInfo&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 style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<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;AfterBuild&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 style="color: #000000; font-weight: bold;">&gt;</span></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>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.097 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-07-29 16:37:26 -->
