<?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>Enterprise Mobile &#187; Team Foundation System Build</title>
	<atom:link href="http://blog.enterprisemobile.com/category/team-foundation-system-build/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.enterprisemobile.com</link>
	<description>Blogging about enterprise mobility, mobile devices, security, management and deployments.</description>
	<lastBuildDate>Thu, 24 Jun 2010 21:32:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automating Build Versioning and Publishing of Smart Device Projects with Team Foundation Build</title>
		<link>http://blog.enterprisemobile.com/2008/07/automating-build-versioning-and-publishing-smart-device-projects-with-team-foundation-build/</link>
		<comments>http://blog.enterprisemobile.com/2008/07/automating-build-versioning-and-publishing-smart-device-projects-with-team-foundation-build/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 19:41:53 +0000</pubDate>
		<dc:creator>kdutta</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Team Foundation System Build]]></category>
		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://blog.enterprisemobile.com/?p=23</guid>
		<description><![CDATA[A few months ago I sent out an email describing the process of setting up the Team Foundation Build System to play nicely with Smart Device Projects. This mail included: setting up the build machine to work with Smart Device Projects, account permissions, publish location, versioning, and also a workaround to making Smart Device CAB [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I sent out an email describing the process of setting up the Team Foundation Build System to play nicely with Smart Device Projects. This mail included: setting up the build machine to work with Smart Device Projects, account permissions, publish location, versioning, and also a workaround to making Smart Device CAB projects buildable by TFS. I’m sure other developers have had to or will have to go through the same pains of figuring this out, so I decided to publish it a la blog.<span id="more-23"></span></p>
<style type="text/css">
<!--
#wp_codebox { height:auto; }
-->
</style>
<p>I hit 3 snags while working on this:</p>
<ol>
<li>Build Service Setup and Permissions</li>
<li>Automatic versioning in the standard Major.Minor.Build.Revision style</li>
<li>Smart Device CAB files are not supported by MSBuild</li>
</ol>
<p><strong>Build Service Setup and Permissions</strong></p>
<ol>
<li>Set up Team Build on the Build machine (BuildMachine)
<ol type="a">
<li>Install Team Build</li>
<li>Install Visual Studio 2008 on the machine as well, otherwise Compact Framework projects will not compile.</li>
<li>Install the Windows Mobile 6 Professional and Standard SDKs, Visual Studio 2008 only ships with Windows Mobile 5 SDKs.</li>
</ol>
</li>
<li>Make sure the Build Service account (TFSBuild) has full access and permissions to the share you are publishing (\\PublishMachine\Builds\&#8230;).</li>
<li>Create a Build Agent (only needs to be done once per server, and then is accessible to everyone). In Visual Studio, click Build, and type the server name (BuildMachine).</li>
<li>Create a Build Definition for your project
<ol type="a">
<li>In Team Explorer, under Builds, create a new Build definition. The wizard is very straightforward. Choose a location in the source tree, and choose a build configuration (Release). This will create a tfsbuild.proj file in the location you specified in the source tree. You will need to edit this file later on.</li>
<li>Right click the build definition and perform a build. Verify it succeeded. You will notice that the build number is Ole Automation dated. Not very easy on the eyes.</li>
</ol>
</li>
</ol>
<p><strong>Automatic Versioning</strong></p>
<p>Microsoft has some generic MSBuild tasks available that can be used to handle this. They are a separate download from Visual Studio however. Here’s the relevant links:</p>
<ul>
<li><a href="http://www.tfsbuild.com/Default.aspx?Page=Increment%20Build%20Numbers%20(major,%20minor,%20build,%20etc)&amp;AspxAutoDetectCookieSupport=1">TFSBuild</a></li>
<li><a href="http://www.codeplex.com/sdctasks">SDCTasks</a></li>
</ul>
<ol>
<li><strong>Setting up your Solution</strong>
<ol type="a">
<li>Add the Microsoft.Sdc.Common.tasks and Microsoft.Sdc.Tasks.dll to the root of your solution. Using the ones provided by Microsoft actually caused me build errors for whatever reason. Some of the tasks they included were the cause. I have commented out all the tasks but those necessary to accomplish versioning. I have attached the <a href="http://blog.enterprisemobile.com/wp-content/uploads/2008/07/microsoftsdccommon.zip">.dll and the edited .tasks</a> file to this blog.</li>
</ol>
</li>
<li><strong>Preparing the Version.xml File</strong>
<ol type="a">
<li>I have attached a sample <a href="http://blog.enterprisemobile.com/wp-content/uploads/2008/07/version.xml">Version.xml</a> to this blog. Save this to a network share (preferably the same as the one being used when the Build definition was created). The task will reference this file to retrieve the current version, increment it, and save the new version back to the file.</li>
<li>The build service account (TFSBuild) needs to have full permissions to this file. This file must not be read only.</li>
</ol>
</li>
<li><strong>Modifying the TFSBuild.proj</strong>
<ol type="a">
<li>Check the tfsbuild.proj file out for edit</li>
<li>Add the following XML blob before the ending <code>&lt;/Project&gt;</code> tag:

<div id="wp_codebox"><table width="100%" ><tr id="p233"><td width="1%" 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
</pre></td><td class="code" id="p23code3"><pre class="xml"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- This will retrieve and increment a version number from a file on a network share --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">Project</span>=<span style="color: #ff0000;">&quot;$(MSBuildProjectDirectory)\Microsoft.Sdc.Common.tasks&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;BuildNumberOverrideTarget&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Now update the version number --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;versionnumber</span> .Update <span style="color: #000066;">VersionNumberConfigFileLocation</span>=<span style="color: #ff0000;">&quot;\\emsea100\path\to\Version.xml&quot;</span>
                        <span style="color: #000066;">SkipSourceControl</span>=<span style="color: #ff0000;">&quot;true&quot;</span>
                        <span style="color: #000066;">OnlyIncrementRevision</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output</span> <span style="color: #000066;">TaskParameter</span>=<span style="color: #ff0000;">&quot;VersionNumber&quot;</span> <span style="color: #000066;">PropertyName</span>=<span style="color: #ff0000;">&quot;BuildNumber&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/versionnumber<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- This will replace all version numbers in the assemblyinfo.cs files with the one from the share --&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- This target is called after Team build gets all the source files from TFS. --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;AfterGet&quot;</span> <span style="color: #000066;">DependsOnTargets</span>=<span style="color: #ff0000;">&quot;VersionAssemblies&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;VersionAssemblies&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Get the Assembly Info files.--&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;createitem</span> <span style="color: #000066;">Include</span>=<span style="color: #ff0000;">&quot;$(SolutionRoot)\**\AssemblyInfo.cs;&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output</span> <span style="color: #000066;">TaskParameter</span>=<span style="color: #ff0000;">&quot;Include&quot;</span> <span style="color: #000066;">ItemName</span>=<span style="color: #ff0000;">&quot;AssemblyInfos&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/createitem<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Update the version numbers --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;file</span> .Replace <span style="color: #000066;">Force</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">Path</span>=<span style="color: #ff0000;">&quot;%(AssemblyInfos.FullPath)&quot;</span> <span style="color: #000066;">NewValue</span>=<span style="color: #ff0000;">&quot;AssemblyVersion(&amp;quot;$(BuildNumber)&amp;quot;)&quot;</span> <span style="color: #000066;">regularExpression</span>=<span style="color: #ff0000;">&quot;AssemblyVersion\(\&amp;quot;(\d+.\d+.\d+.\d+)\&amp;quot;\)&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
<li>Edit the <code style="color: navy;">VersionNumberConfigFileLocation</code> value to be configured for your publish machine and directory. You can also change the <code style="color: navy;">OnlyIncrementRevision</code> to false so that the build number also gets autoincremented.</li>
</ol>
</li>
</ol>
<p><strong>Building a Smart Device CAB Project Using MSBuild</strong></p>
<p>There is no “good” way to do this. I did this by creating a standard Smart Device CAB project, and then building it on my development machine. If your project is called SmartDeviceCab, in the SmartDeviceCab\Debug folder, there is a SmartDeviceCab.inf file. That file can be used as input to CabWiz.exe to create the file from a command prompt. I will be using the INF file of our recently released tool, Device IP Utility, as an example.</p>
<ol>
<li><strong>Solution Setup</strong>
<ol type="alpha">
<li>Copy the EMIPUtil.inf file to the solution root folder.</li>
<li>Right click the solution and add existing file: %SolutionRoot%\ EMIPUtil.inf</li>
</ol>
</li>
<li><strong>Modifying the INF file</strong>
<ol type="a">
<li>The INF file will contain a section of absolute paths to the location of the binaries on the development machine. This needs to be changed to absolute paths on the build machine. Note that all the binaries on the build machine will be dumped into the same directory, making it relative easy to edit. The first INF file shows what the file may look on your development machine, and the second will show how it should look on your build server.
<ol>
<li><strong>Old Paths Local to Your Development Machine</strong>
<pre id="wp_codebox" style="height: auto;">
<div>
1=,”Common1″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\EnterpriseMobile.WindowsMobile.IPUtil\bin\Release\”
2=,”Common2″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\EnterpriseMobile.WindowsMobile.IPUtil\obj\Release\”
3=,”Common3″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\EnterpriseMobile.WindowsMobile.Utilities\bin\Release\”
4=,”Common4″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\EnterpriseMobile.WindowsMobile.Utilities\obj\Release\”
5=,”Common5″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\WMIPUtil\obj\Release\”
6=,”Common6″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\WindowlessControls\bin\Release\”
7=,”Common7″,,”C:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\WindowlessControls\obj\Release\”
8=,”Common8″,,”c:\Users\kdutta\Documents\Visual Studio 2008\Projects\Device IP Utility\Device IP Utility - Production\EnterpriseMobile.WindowsMobile.IPUtil.Interop\Windows Mobile 5.0 Smartphone SDK (ARMV4I)\Release\”</div>
</pre>
</li>
<li><strong>New Paths on Build Machine</strong>
<pre id="wp_codebox" style="height: auto;">
<div>
1=,”Common2″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
2=,”Common3″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
3=,”Common4″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
4=,”Common5″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
5=,”Common6″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
6=,”Common7″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
7=,”Common8″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”
8=,”Common9″,,”C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries\Release\”</div>
</pre>
</li>
</ol>
</li>
</ol>
</li>
<li><strong>Making MSBuild call CabWiz.exe</strong>
<ol type="a">
<li>Check out and edit the tfsbuild.proj file</li>
<li>Before the ending <code>&lt;/Project&gt;</code> tag, insert the following:

<div id="wp_codebox"><table width="100%" ><tr id="p234"><td width="1%" class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p23code4"><pre class="xml"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- This will build a CAB file from an .inf file --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;BeforeDropBuild&quot;</span> <span style="color: #000066;">DependsOnTargets</span>=<span style="color: #ff0000;">&quot;MakeCAB&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;MakeCAB&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Building a CAB file&quot;</span> <span style="color: #000066;">Importance</span>=<span style="color: #ff0000;">&quot;normal&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;&amp;quot;C:\Program Files\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\cabwiz.exe&amp;quot; &amp;quot;C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Sources\EMIPUtil.inf&amp;quot; /compress /dest &amp;quot;C:\Documents and Settings\TFSBuild\Local Settings\Temp\Device IP Utility\Device IP Utility - Production\Binaries&amp;quot;&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
<li>Modify the following Command Attribute to be set up specifically for your build machine. This defines the path to CabWiz.exe, the path to your INF file, and the output directory of the CAB file.</li>
<li>This XML insert calls the CabWiz.exe prior to publishing the binaries. CabWiz.exe adds the CAB file to the binaries folder, which in turn gets published with everything else.</li>
</ol>
</li>
</ol>
<p>Sadly there is somewhat poor support for Smart Device Projects in TFSBuild, so making it work isn’t exactly elegant, but it works!</p>
<p>Koushik Dutta<br />
Software Engineer<br />
<a href="http://www.koushikdutta.com">www.koushikdutta.com</a><a href='http://blog.enterprisemobile.com/wp-content/uploads/2008/07/microsoftsdccommon.zip'>microsoftsdccommon</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enterprisemobile.com/2008/07/automating-build-versioning-and-publishing-smart-device-projects-with-team-foundation-build/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
