<?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>Jeff Wilcox &#187; Infrastructure</title>
	<atom:link href="http://www.jeff.wilcox.name/topics/dev/infrastructure/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeff.wilcox.name</link>
	<description>Silverlight, rich client apps and web development</description>
	<lastBuildDate>Mon, 26 Jul 2010 17:56:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Building Silverlight 3 and Silverlight 4 applications on a .NET 3.5 build machine</title>
		<link>http://www.jeff.wilcox.name/2010/03/sxs-sl3-sl4-build-machine/</link>
		<comments>http://www.jeff.wilcox.name/2010/03/sxs-sl3-sl4-build-machine/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 19:01:18 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2010/03/sxs-sl3-sl4-build-machine/</guid>
		<description><![CDATA[Thanks to modular MSBuild tasks and components, you can actually build Silverlight 3 and Silverlight 4 applications on the same build machine, without having .NET 4 installed. This is great for constrained TFS build environments, and although not supported in any way, this does allow you to edit and build simple Silverlight 4 apps created [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to modular MSBuild tasks and components, you can actually build Silverlight 3 and Silverlight 4 applications on the same build machine, without having .NET 4 installed.</p>
<p>This is great for constrained TFS build environments, and although not supported in any way, this does allow you to edit and build simple Silverlight 4 apps created first for Silverlight 3, using Visual Studio 2008.</p>
<h4>Background</h4>
<p>On the Silverlight Toolkit team, we have a need to always have a previous version branch, and a new version, building together in a daily TFS Build. We do this by having the Silverlight 3 and Silverlight 4 SDKs, reference assemblies, and other resources checked into the source enlistment.</p>
<h4>Caveats</h4>
<p>This post is not intended for the general Silverlight developer: it is designed for build engineers and continuous integration fans that need to build both versions. Since the adoption rate of new Silverlight versions is typically very quick, the need to build previous versions diminishes very quickly in my opinion.</p>
<p>Important: this will be using the .NET 3.5 C# compiler, and not the C# 4 compiler. This means that you will not have the ability to build apps that use the new <em>dynamic </em>language feature.</p>
<p>Important note 2: this assumes you are starting with a Silverlight 3 class library or app, not one that you created in Visual Studio 2010. The project file formats in 2010 are updated to use MSBuild 4 and a few other differences, so this scenario (basically building SL3 project formats against the SL4 runtime) is not for everyone.</p>
<p>Important note 3: Visual Studio 2010 supports multi-targeting Silverlight, so you can create projects in 2010 that are 3 or 4 much easier – no need for any of these hacks if your build environment already has .NET 4.</p>
<p>This is based on a <a href="http://www.jeff.wilcox.name/2009/03/sxs-sl2-sl3-building/">previous post</a> about building Silverlight 2 and 3 together.</p>
<p>This method does not require a build machine to have Silverlight installed at all, nor any of its SDKs.</p>
<h2>Preparing your source enlistment</h2>
<p>You want to copy the various build assets for both Silverlight 3 and Silverlight 4 into the tree, in a folder such as ExternalTools\Silverlight\v3 and v4. Repeat these steps for each version of Silverlight (v3.0, v4.0 directories) you need to build:</p>
<ul>
<li>Create a directory to store the MsBuild assets for Silverlight, and copy in the files from %programfiles%MSBuild\Microsoft\Silverlight\v3.0.</li>
<li>Copy the “Reference Assemblies” directory from %programfiles%\Microsoft SDKs\Silverlight\v3.0\ into the tools directory. </li>
<li>Copy the “Libraries” directory from %programfiles%\Microsoft SDKs\Silverlight\v3.0\ into the directory.</li>
</ul>
<p>You can then use relative paths in your projects or custom build targets to get things rolling.</p>
<h2>Customizing the &lt;Import /&gt; element in your projects</h2>
<p>Within your source enlistment, you must then update all Silverlight project files to instead reference the relative-path building scripts instead of those installed on the machine.</p>
<p>Even when building in Visual Studio 2008, the proper version will build.</p>
<p>On the Toolkit team, all VB and C# source projects within the enlistment reference a relative path, typically something like ..\..\Silverlight.CSharp.targets, instead of the standard Silverlight CSharp targets from the Silverlight MSBuild scripts.</p>
<p>Inside this relative path, it defines the properties. For Silverlight 3:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:ac281bf1-826d-4dbd-bad9-8750cce72616" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">&lt;Project
  ToolsVersion="3.5"
  DefaultTargets="Build"
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;

  &lt;PropertyGroup&gt;
    &lt;!-- Define the ExternalTools property first --&gt;
    &lt;SilverlightBuildResources&gt;$(ExternalTools)\Silverlight\v3.0\&lt;/SilverlightBuildResources&gt;

    &lt;TargetFrameworkDirectory&gt;$(SilverlightBuildResources)Reference Assemblies\&lt;/TargetFrameworkDirectory&gt;
    &lt;TargetFrameworkSDKDirectory&gt;$(SilverlightBuildResources)Libraries\Client\&lt;/TargetFrameworkSDKDirectory&gt;
    &lt;SilverlightRuntimeVersion&gt;3.0.40217.0&lt;/SilverlightRuntimeVersion&gt;
  &lt;/PropertyGroup&gt;
  &lt;Import Project="$(SilverlightBuildResources)Microsoft.Silverlight.CSharp.targets"/&gt;
&lt;/Project&gt;</pre>
</div>
<p>And for Silverlight 4:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:c8990b1e-59ad-45a4-b7fe-84898f42a31f" class="wlWriterEditableSmartContent">
<pre class="c-sharp" name="code">&lt;Project
  ToolsVersion="3.5"
  DefaultTargets="Build"
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;

  &lt;PropertyGroup&gt;
    &lt;!-- Define the ExternalTools property first --&gt;
    &lt;SilverlightBuildResources&gt;$(ExternalTools)\Silverlight\v4.0\&lt;/SilverlightBuildResources&gt;

    &lt;TargetFrameworkDirectory&gt;$(SilverlightBuildResources)Reference Assemblies\&lt;/TargetFrameworkDirectory&gt;
    &lt;TargetFrameworkSDKDirectory&gt;$(SilverlightBuildResources)Libraries\Client\&lt;/TargetFrameworkSDKDirectory&gt;
    &lt;SilverlightRuntimeVersion&gt;4.0&lt;/SilverlightRuntimeVersion&gt;
  &lt;/PropertyGroup&gt;
  &lt;Import Project="$(SilverlightBuildResources)Microsoft.Silverlight.CSharp.targets"/&gt;
&lt;/Project&gt;</pre>
</div>
<p>Note that we are only providing the major version here, this prevents having to update with each new build of Silverlight 4.</p>
<h2>Adding Silverlight Toolkit support</h2>
<p>To build apps that use the Silverlight Toolkit in a similar manner, just copy the Silverlight Toolkit binaries into the same client libraries folder of the SDK.</p>
<h2>WCF RIA Services Note</h2>
<p>There’s a hard-coded import statement that will import a single version of the WCF RIA Services if present on the machine.</p>
<p>At the bottom of the Silverlight 4 file Microsoft.Silverlight.Common.targets, you will see this line:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:8b26dc04-7f02-4f26-bf58-d3fb45c62467" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">&lt;Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v4.0\Microsoft.Ria.Client.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v4.0\Microsoft.Ria.Client.targets')"/&gt;</pre>
</div>
<p>You may want to <strong>comment out or remove this line</strong> if this impacts your multi-version builds in any way.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2010/03/sxs-sl3-sl4-build-machine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code signing Visual Studio 2010 extensions (VSIX)</title>
		<link>http://www.jeff.wilcox.name/2010/03/vsixcodesigning/</link>
		<comments>http://www.jeff.wilcox.name/2010/03/vsixcodesigning/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 22:13:33 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2010/03/vsixcodesigning/</guid>
		<description><![CDATA[Here's a simple application (and optional source) for a tool to allow you to quickly Authenticode code sign Visual Studio 2010 extension files (VSIX).]]></description>
			<content:encoded><![CDATA[<p>To follow up my “<a href="http://www.jeff.wilcox.name/2010/02/codesigning101/">epic code signing</a>” post, I wanted to share a small app I built to code sign Visual Studio 2010 Extensions.</p>
<h3>VSIX files can contain a digital signature</h3>
<p>Which extension would you rather install? Here’s one without a digital signature:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Download and Install" border="0" alt="Download and Install" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/03/DownloadandInstall.png" width="473" height="388" /> </p>
<p>And one with:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Extension Installer" border="0" alt="Visual Studio Extension Installer" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/03/VisualStudioExtensionInstaller.png" width="492" height="376" /> </p>
<h3>Download My SignExtension Tool</h3>
<p>This is a simple .NET 4 app that allows you to select your .Vsix file, your .Pfx file, enter a password, and sign away.</p>
<p><a href="http://media.jeff.wilcox.name/blog/signextension/SignExtension.zip">SignExtension.zip</a> (30 KB, contains the app only. App is signed.)     <br /><a href="http://media.jeff.wilcox.name/blog/signextension/SignExtension.Source.zip">SignExtension.Source.zip</a> (27 KB, contains the Visual Studio 2010 project source for .NET 4 only)</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Visual Studio Extension Signing" border="0" alt="Visual Studio Extension Signing" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/03/VisualStudioExtensionSigning.png" width="557" height="382" /> </p>
<h3>How to manually sign an extension</h3>
<p>The new .Vsix files are really glorified zip files, and the extensions manager is able to identify when such files have a verified digital signature. However, there isn’t a Subject Interface Package (SIP) for VSIX, so the traditional <a href="http://msdn.microsoft.com/en-us/library/8s9b9yaz(VS.80).aspx">SignTool.exe</a> program cannot sign extension packages.</p>
<p>Instead, you need to use the System.IO.Packaging namespace and the <a href="http://msdn.microsoft.com/en-us/library/system.io.packaging.packagedigitalsignaturemanager.aspx">PackageDigitalSignatureManager</a> type to sign, using a <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx">X509Certificate2</a> type.</p>
<p>It took some trial and error, plus discussion searching, to find the best common practice for this. Here’s some of that key code:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:377118e8-ac96-46eb-971f-f0c5eb7c89ed" class="wlWriterEditableSmartContent">
<pre class="c-sharp" name="code">private static void SignAllParts(Package package, string pfx, string password, string timestamp)
        {
            var signatureManager = new PackageDigitalSignatureManager(package);
            signatureManager.CertificateOption = CertificateEmbeddingOption.InSignaturePart;

            List&lt;Uri&gt; toSign = new List&lt;Uri&gt;();
            foreach (PackagePart packagePart in package.GetParts())
            {
                toSign.Add(packagePart.Uri);
            }

            toSign.Add(PackUriHelper.GetRelationshipPartUri(signatureManager.SignatureOrigin));
            toSign.Add(signatureManager.SignatureOrigin);
            toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));

            try
            {
                signatureManager.Sign(toSign, new System.Security.Cryptography.X509Certificates.X509Certificate2(pfx, password));
            }
            catch (System.Security.Cryptography.CryptographicException ex)
            {
                System.Windows.Forms.MessageBox.Show("Signing could not be completed: " + ex.Message, "Signing Failure");
            }
        }</pre>
</div>
<p><em>Hope this helps.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2010/03/vsixcodesigning/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting started with code signing for under $100</title>
		<link>http://www.jeff.wilcox.name/2010/02/codesigning101/</link>
		<comments>http://www.jeff.wilcox.name/2010/02/codesigning101/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 05:33:47 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2010/02/codesigning101/</guid>
		<description><![CDATA[I recently documented the steps to "code signing 101": acquiring a trusted cert/key pair, the process, and then signing an app.]]></description>
			<content:encoded><![CDATA[<p><strong>Update 3/15/10: Silverlight 4 supports code signing elevated trust .XAP files</strong></p>
<p>I recently jumped in and acquired an Authenticode code signing certificate &amp; key pair. It’s great being able to sign my .NET executables, installers, and even Visual Studio 2010 extensions.</p>
<p>I’m documenting my efforts here in the hope that others would be able to follow the relatively straightforward process – there’s not much magic other than learning to export and work with the certificate mechanisms inside Windows. But I know a lot of devs see it as a black magic art, and really it’s just about time, money, and some quick learning.</p>
<h4>Which dialog would you click ‘Yes’ on?</h4>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="FakeFirefox" border="0" alt="FakeFirefox" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/FakeFirefox.png" width="498" height="295" /></p>
<p>Windows 7 is leaps and bounds ahead of Vista in terms of usability. The improved User Account Control experience is nice. I think that a lot of people are finally becoming more wary of unsigned software, especially installers.</p>
<p>With the net full of stories of mirror servers becoming compromised, or people blinding clicking yes on many dialogs, the assurance of the dialog without the scary orange warning banner is the one I think every software developer would like to offer their customers. It’s the professional thing to do.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="UacFirefox" border="0" alt="UacFirefox" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/UacFirefox.png" width="498" height="295" />&#160;</p>
<p>So here we are, from start (no cert) to finish (signing a .NET app). It only took about two days to go through the identity verification process, but the time was well worth it – and the rest is easy given the nice signing tools in Windows and Visual Studio.</p>
<p>We’ll be getting a certificate &amp; private key through a trusted root certificate authority (CA) provider, not test signing or self-signing. If you’ve ever purchased an SSL certificate for your web servers, similar process.</p>
<p>For a list of current program members, see <a href="http://support.microsoft.com/kb/931125">this download</a> on the Microsoft site – there are hundreds of businesses and governments in the program.</p>
<p>Some corporate IT departments will have their own internal CA, so although those companies can sign apps for internal use, using them on machines without that CA cert installed will yield the un-trusted publisher dialog.</p>
<h4>What is Authenticode?</h4>
<p>Authenticode is the name for the code signing system on Windows. There are <a href="http://msdn.microsoft.com/en-us/library/ms537364(VS.85).aspx">many tools from Microsoft</a> that are core to code signing and ship in the Windows SDK.</p>
<p>Code signing certificates have an expiration date, but as long as a timestamp server is used when signing, signed apps can still be used and verified. Certificates can also be revoked if ever compromised.</p>
<p>For good measure, here’s a short Wikipedia page on <a href="http://en.wikipedia.org/wiki/Code_signing">code signing</a>, and the MSDN document “<a href="http://msdn.microsoft.com/en-us/library/ms537361(VS.85).aspx">Introduction to Code Signing</a>”.</p>
<h4>What code signing is not</h4>
<p>Signing is only a way of proving that some person or company is who they say they are. It doesn’t tell you whether there’s a nice person, or in any way validate functionality of an app.</p>
<p>Also, .NET projects have a “Signing” tab, but this is actually a feature called <a href="http://msdn.microsoft.com/en-us/magazine/cc163583.aspx">Strong Naming</a>, and is different. Most commercial software products using .NET will be both strong named, <em>plus</em> be code signed.</p>
<h4>What all can you use your $99/year key for?</h4>
<ul>
<li>Signing Windows executables</li>
<li>.NET programs, class libraries, ClickOnce apps</li>
<li>.MSI installer files</li>
<li>Adobe AIR apps</li>
<li>Java JARs</li>
<li>Microsoft Office/VBA macros</li>
<li>Mozilla objects and extensions</li>
<li>Signing Visual Studio extension packages (.vsix files), although SignTool doesn’t directly support this (no SIP module)</li>
</ul>
<p><em>Note that only Verisign offers code signing certificates for Windows device drivers through a special program for kernel-mode code signing.</em></p>
<h4>How does Microsoft do code signing?</h4>
<p>Obviously the Microsoft corporate keys are extremely secure and private. All signing is performed through a set of intricate systems that accept builds, check conditions, scan for viruses, and who knows what else… and eventually provide the signed binaries.</p>
<p>It’s pretty much a black box to us as engineers, but it works for hundreds of thousands of files.</p>
<p>As a dev, I’ve had more than my share of wild Friday nights trying to get code strong named and signed: there’s a big process and it revolves around a lot of people, smart cards, and it eventually works out.</p>
<h2>Step-by-step guide to purchasing a certificate</h2>
<p>Here’s my experience with getting a certificate. Different certification companies may have different processes, but in general you can be sure that you will need to do a lot to provide proof and authenticity of your name/company.</p>
<p>You can purchase a personal certificate (independent developer, professional geek) quicker than a corporate certificate given the different proof requirements.</p>
<p>Since the name/company name is what will be shown in the publisher field, you obviously wouldn’t want to get a personal certificate for company use. Also, be aware that the address you provide to a signing company will be embedded inside the certificate.</p>
<p>I purchased my code signing cert through <a href="https://secure.ksoftware.net/code_signing.html">K Software</a>, which is an official reseller of <a href="http://www.comodo.com/">Comodo</a> certificates, a popular Level 2 CA whose certificates are part of the root CA program on computers everywhere. The certificate costs $99 per year. I’ve heard of other companies sometimes offering specials as low as $65 a year, and others such as Verisign asking $499 a year.</p>
<p>Since there is some pain in the process (producing copious amounts of evidence) and waiting for that to be validated, you may want to consider purchasing a multi-year certificate and skip having to renew yearly.</p>
<p>You must use Windows and either Internet Explorer or Firefox to make the initial request. After the entire process is complete and the certificate is issued (days later), you will need to use the same computer and browser to complete the process. You will then export the certificate and private key to a file so you can store it safely somewhere.</p>
<h4>What proof will be required</h4>
<p>This is a partial list, the authentication process may require other documents. Most verification can be done through fax, mail, or even email.</p>
<p>If you’ve ever purchased an SSL certificate, it’s almost the same exact process.</p>
<ul>
<li>Your own domain name:</li>
</ul>
<ul>
<li>The domain’s WHOIS records must match the information you provide in your order.</li>
<li>If you use Private Registration services, you’ll need proof from the private registration company that you own the domain and your address matches. This can be a pain.</li>
</ul>
<li>Corporate entities:</li>
<ul>
<li>Articles of Incorporation</li>
<li>Business License</li>
<li>Other documentation such as DUNS details</li>
</ul>
<li>Individuals:</li>
<ul>
<li>Driver’s license or passport</li>
<li>Recent utility statements with matching data</li>
<li>Phone statement with matching information, name, and phone number where final phone verification will be performed</li>
</ul>
<p>This information will be asked for after you order and pay for the service. It is performed by the CA (Comodo in my case), <em>not</em> by the company or reseller you buy the service from.</p>
<p>For the remainder of this section, everything will be specific to Comodo. I found them helpful, quick and responsive, and professional, so I would definitely recommend their service. It is a great value when purchased through a reseller.</p>
<h4>Step 1: Register with the CA to track your validation tickets and receive support</h4>
<p>You’ll need to do this with an email address at your domain name. You register with the same email you’ll use in the next step.</p>
<p>If you don’t usually receive mail at your domain, you should be able to easily setup mail forwarding to your normal mail address. On a Windows server, <a href="http://www.smartertools.com/SmarterMail/Free-Windows-Mail-Server.aspx">SmarterMail Free</a> sets up in minutes and is great for this.</p>
<p>Simply create an account at Comodo Support for this: <a title="https://support.comodo.com/index.php?_m=core&amp;_a=register" href="https://support.comodo.com/index.php?_m=core&amp;_a=register">https://support.comodo.com/index.php?_m=core&amp;_a=register</a></p>
<h4>Step 2: Submit basic data and purchase</h4>
<p>Start at the K Software site, which is a reseller of Comodo’s: <a title="https://secure.ksoftware.net/code_signing.html" href="https://secure.ksoftware.net/code_signing.html">https://secure.ksoftware.net/code_signing.html</a></p>
<p>Current prices are $99 US for one year, $198 for 2 years, and so on.</p>
<p>After navigating to the page, click Buy Now. Internet Explorer will pop up a message that the site is attempting to perform a digital certificate operation. Click Yes.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="WebAccessConfirmation" border="0" alt="WebAccessConfirmation" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/WebAccessConfirmation.png" width="528" height="291" /> </p>
<p>On the order form page, you will submit your details, including address, email, etc. The email address needs to be an email address on your domain name that can be verified, <em>not</em> a Hotmail or Google Mail address. Note that this information will be embedded inside the final issued certificate.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="OrderForm" border="0" alt="OrderForm" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/OrderForm.png" width="685" height="419" /> </p>
<p>Important values at the end of the page:</p>
<ul>
<li>CSP should be Microsoft Enhanced Cryptographic Provider v1.0 (the default)</li>
<li>Key size: 2048 is fine for most people</li>
<li>Exportable: definitely – if you don’t check this, you can’t get a PKCS 12 (.pfx on Windows) file to use for signing, and would have to do all signing on that machine</li>
<li>User protected: Leave this unchecked</li>
</ul>
<p>After clicking Submit Order, you’ll go to a payment page. I used PayPal and was done in seconds.</p>
<h4>Step Three: You’ll be contacted</h4>
<p>At this point you’re done with the K Software order. You will be contacted via e-mail from Comodo, and they’ll step you through what verification they need at that time, and how to submit it.</p>
<p>In my case I had to go through several rounds of verification, including sending a recent phone bill.</p>
<p>I ran into some hiccups because the domain name I used for the e-mail address, though owned by me, is hard to prove: my WHOIS data all says ‘Domains By Proxy’, which is the provider of private registration services for GoDaddy. I had to find a way to provide proof that I own the domain.</p>
<p>The final verification step is when they eventually call your phone number. After that call, they’ll issue the certificate approval, and you’ll receive a final e-mail about 20 minutes later to go pick up the certs.</p>
<p>This step took me 1.5 business days including waiting time.</p>
<h4>Step Four: Pick up your key</h4>
<p>On the same computer you started the operation on, and same browser, click on the link provided in the e-mail Comodo sent when the key was ready.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="KSoftwarePickup" border="0" alt="KSoftwarePickup" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/KSoftwarePickup.png" width="685" height="531" /> </p>
<p>On this page, you’ll again receive a notification about a certificate operation. That’s fine. At this point you now have the key stored in your browser certificate system.</p>
<h4>Step Five: Export your key</h4>
<p>This step is for Internet Explorer users. If you’re using Mozilla Firefox, <a href="http://blog.ksoftware.net/2009/10/exporting-your-code-signing-certificate-to-a-pfx-file-from-firefox/">here’s some other instructions</a>.</p>
</p>
<p>In IE now, click Tools | Internet Options. Click on the Content tab, and then the Certificates button:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="InternetOptions" border="0" alt="InternetOptions" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/InternetOptions.png" width="455" height="573" /> </p>
<p>Within the Personal (first) tab of the Certificates dialog, click on the new certificate issued by UTN-USERFirst-Object (this is one of the many Comodo level 2 CAs in the Windows root CA program):</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Certificates" border="0" alt="Certificates" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/Certificates.png" width="551" height="509" /> </p>
<p>Then click ‘Export…’. In the Certificate Export Wizard, read the useless text and click Next.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ExportWizardStart" border="0" alt="ExportWizardStart" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/ExportWizardStart.png" width="545" height="498" /> </p>
<p>Select the option ‘Yes’ for exporting the private key along with the certificate.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ExportPrivateKeyPlease" border="0" alt="ExportPrivateKeyPlease" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/ExportPrivateKeyPlease.png" width="545" height="498" /> </p>
<p>Next, you pick the file format. Only PFX/PKCS #12 should be available. I checked both ‘Include all certificates in the certification path if possible’ and ‘Export all extended properties’, though to be honest I haven’t a clue whether this is needed.</p>
<p>I wouldn’t recommend clicking the delete private key option, I like knowing that on this particular machine I can still re-export the cert as needed in the future.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ExportTypeAndOptions" border="0" alt="ExportTypeAndOptions" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/ExportTypeAndOptions.png" width="545" height="498" /> </p>
<p>Now, come up with a password to protect the file. You will need to use this password when using tools such as SignTool.exe, or setting up an automated code signing process of your own.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ExportKeyPasswordDialog" border="0" alt="ExportKeyPasswordDialog" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/ExportKeyPasswordDialog.png" width="545" height="498" /> </p>
<p>Finally, pick where you want your .PFX file stored.</p>
<h4>Step Six: Protect your key</h4>
<p>Although code signing certificates have a mechanism through the CA to revoke keys, <strong>you do not ever want to have to do this.</strong></p>
<p>Take precautions. It is your duty to protect your key. Many people find ways to store this information through smart card or other physical security mechanisms.</p>
<p>As an individual, it’s pretty easy for me: Only I know the password, I have the file securely stored, and I don’t need to worry about sharing it with others.</p>
<p>Business entities and groups will have more trouble coming up with the appropriate processes and systems for this. Ideally some sort of automated system should be used to perform the code signing, with alternative authentication; providing the key file and a password is not the best method.</p>
<h4>Import Wizard Note</h4>
<p>To manually sign on another machine, you’ll want to double-click on the .pfx file. An import wizard will open up that will allow you to install the cert and private key on your machine.</p>
<p>For manual signing you typically select from your private certificate store on the machine, instead of using the .pfx file directly. For automated signing, you probably will use the .pfx.</p>
<h2>How to sign your apps and libraries</h2>
<p>Now the fun part. Armed with your new code signing certificate and private key, you’re ready to go SignTool.exe’ing.</p>
<p>SignTool is included with the Windows 6.0 and 7.0A SDKs, and you’ll have it in your path if you have Visual Studio 2008 or 2010 installed and are using the associated Visual Studio Command Prompt.</p>
<p>You can create scripts to sign quickly using command line parameters, or even write .NET apps using types in the System.Security.Cryptography.X509Certificates namespace.</p>
<p>It’s easiest to get started by manually signing, using the Digital Signature Wizard. From a Visual Studio 2008 Command Prompt, for instance, run:</p>
<blockquote><p>signtool.exe signwizard</p>
</blockquote>
<p>This will popup the wizard that will walk you through.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard" border="0" alt="Digital Signature Wizard" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard.png" width="545" height="431" /></p>
<p>Select the file you want to sign:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (3)" border="0" alt="Digital Signature Wizard (3)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard3.png" width="545" height="431" /></p>
<p>The ‘Typical’ option will let you pick from the certificate store on your machine. You don’t actually select the previously-exported .PFX file when manually signing.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (4)" border="0" alt="Digital Signature Wizard (4)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard4.png" width="545" height="431" /></p>
<p>Here I click ‘Select from Store…’:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (5)" border="0" alt="Digital Signature Wizard (5)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard5.png" width="545" height="431" /></p>
<p>Which pops up a Windows dialog listing available code signing certificates.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SelectACertificate" border="0" alt="SelectACertificate" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/SelectACertificate.png" width="471" height="266" /> </p>
<p>Here I can verify the goods:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (6)" border="0" alt="Digital Signature Wizard (6)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard6.png" width="545" height="431" /></p>
<p>On the next wizard page, you can optionally offer more information here as appropriate.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (7)" border="0" alt="Digital Signature Wizard (7)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard7.png" width="545" height="431" /> </p>
<p>The last optional, but highly recommended step, is to use the timestamp server provided by the CA. This is a service that authenticates when the data (your app) was signed.</p>
<p>This means that your app will continue to be valid, even after the certificate expires, as long as the cert is not revoked.</p>
<p>For Comodo, their timestamping server is: <a title="http://timestamp.comodoca.com/authenticode" href="http://timestamp.comodoca.com/authenticode">http://timestamp.comodoca.com/authenticode</a></p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (8)" border="0" alt="Digital Signature Wizard (8)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard8.png" width="545" height="431" /></p>
<p>Click Next and you’ll see the summary of what signing is to take place.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (9)" border="0" alt="Digital Signature Wizard (9)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard9.png" width="545" height="431" /></p>
<p>After clicking Finish, the dialog will go away, and pretty soon you should receive a success/failure message.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Digital Signature Wizard (10)" border="0" alt="Digital Signature Wizard (10)" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/DigitalSignatureWizard10.png" width="440" height="203" /></p>
<h4>CodeSign.exe Parameters</h4>
<p>You can also code sign in scripts and the command line using arguments. For instance, here’s a sample made-up signing argument list. You can specify any number of files to sign as the final arguments.</p>
<blockquote><p>signtool.exe sign /f PathToKeysAndCert.Pfx /p “MySuperSecretPasswordToUseThePfxFile” /v /t http://timestamp.comodoca.com/authenticode “C:\MyFileToSign.exe”</p>
</blockquote>
</p>
<p>For all the parameters, type ‘signtool sign /?’</p>
<h4>That’s it!</h4>
<p>You can use a variety of tools to check that the signing works fine, including just examining the file in the Windows explorer.</p>
<p>Authenticode-signed executables, MSIs and libraries will have a ‘Digital Signatures’ tab in the properties window (though not irregular file types, such as Adobe AIR files).</p>
<p>Here’s the .exe I signed:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="FileProperties" border="0" alt="FileProperties" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/FileProperties.png" width="451" height="565" />&#160;&#160;&#160; </p>
<p>And that’s it! <strong>Ship it!</strong></p>
<p>Your customers will have that extra level of confidence when using your application. At some point, the more more professional software developers and software companies code sign, the more likely customers will be able to make proper security decisions about their computers… and the real benefit of the crisp user account control user interface comes to light.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VerifiedPublisher" border="0" alt="VerifiedPublisher" src="http://www.jeff.wilcox.name/wp-content/uploads/2010/02/VerifiedPublisher.png" width="498" height="295" /> </p>
<p>Hope this helps. Let me know how your experiences with code signing go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2010/02/codesigning101/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Walkthrough: The power of the November 2009 Silverlight Toolkit testing tools</title>
		<link>http://www.jeff.wilcox.name/2009/11/november-walkthrough/</link>
		<comments>http://www.jeff.wilcox.name/2009/11/november-walkthrough/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 23:02:09 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/11/november-walkthrough/</guid>
		<description><![CDATA[The November 2009 Silverlight Toolkit is essentially a tools and infrastructure release on top of the October 2009 release (where we first introduced Visual Studio 2010 support). It also adds a Silverlight 4 Beta version. New infrastructure &#38; test tools ship in the Silverlight Toolkit There is a lot in the release that is joining [...]]]></description>
			<content:encoded><![CDATA[<p>The November 2009 Silverlight Toolkit is essentially a tools and infrastructure release on top of the October 2009 release (where we first introduced Visual Studio 2010 support). It also adds a Silverlight 4 Beta version.</p>
<h2>New infrastructure &amp; test tools ship in the Silverlight Toolkit</h2>
<p>There is a lot in the release that is joining publicly for the first time, based on some of the internal tools and utilities that we use in building and testing the Silverlight Toolkit, plus things we’d like to have as typical Silverlight developers.</p>
<p>These tools join in the Experimental quality band, and over the next few posts, I’ll dig into the details. This post is a literal walkthrough of how you could go about seeing all the utilities in the meantime.</p>
<p>One important thing to call out is that, as an initial release, there are definitely some rough edges: the test tools are centered around Microsoft Build (msbuild) integration, instead of Visual Studio integration; there’s no add-in or nice right-click project support to use these tools today.</p>
<p>We’ll be collecting feedback along the way and making changes in future releases. Until then, hopefully some of you will find the infrastructure useful, if only to peak behind the curtain. We’re also shipping the full source to these tools, you’ll find an Infrastructure.zip file inside the toolkit install folder.</p>
<h4>What we’ll do in this walkthrough</h4>
<p>This walkthrough uses Silverlight 4, though the instructions are virtually identical if you’re using Silverlight 3.</p>
<ul>
<li>Install the Silverlight Toolkit</li>
<li>Create a new Silverlight class library with a simple business object</li>
<li>Add a Silverlight Unit Test Application using the new templates found in the Silverlight Toolkit</li>
<li>Run the tests in Visual Studio</li>
<li>Run the tests from the command line in various browsers</li>
<li>Collect block-level code coverage information for the build</li>
</ul>
<p>This is screen-shot heavy, as future posts will dig into the details. I appreciate your patience!</p>
<p>Requirements:</p>
<ul>
<li>Latest Silverlight Toolkit</li>
<li>For test automation:</li>
</ul>
<ul>
<li>MSBuild on the machine</li>
</ul>
<li>For code coverage:</li>
<ul>
<li>Visual Studio 2010 Beta 2 Ultimate</li>
</ul>
<h2>Installing the tools</h2>
<p>When you install either Silverlight Toolkit drop from November, you’ll see that there’s a new feature listed in the setup: the Tools &amp; Templates feature. It’s selected by default, and adds Visual Studio templates, installs the tools, and prepares the tools if your machine has the proper dependencies on it.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SetupNewFeature" border="0" alt="SetupNewFeature" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/SetupNewFeature.png" width="541" height="430" /> </p>
<h2>Create a Silverlight Class Library</h2>
<p>Open Visual Studio 2010 Beta 2, after installing the toolkit. Create a new <strong>Silverlight Class Library</strong> project, we’ll store a simple business object in it.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioNewSilverlightClassLibraryProject" border="0" alt="VisualStudioNewSilverlightClassLibraryProject" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioNewSilverlightClassLibraryProject.png" width="685" height="480" /> </p>
<p>Whichever flavor of Silverlight you use, remember to use the same flavor while creating future projects in the same solution!</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioSelectSilverlightVersion" border="0" alt="VisualStudioSelectSilverlightVersion" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioSelectSilverlightVersion.png" width="685" height="231" /></p>
<p>Create a new Person.cs type, with a few properties and a method. Here’s the source:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:bc34624e-1aaa-4618-a4cc-6c9dad4c3107" class="wlWriterEditableSmartContent">
<pre class="c-sharp" name="code">using System;

namespace MyApplication
{
    public class Person
    {
        public string First { get; set; }
        public string Last { get; set; }

        public string FullName { get { return First + " " + Last; } }

        public bool MightBe(string substring)
        {
            return FullName.Contains(substring);
        }
    }
}</pre>
</div>
<h2>Add a Silverlight Unit Test Application</h2>
<p>Right-click on the solution in the Solution Explorer and select Add New Project. Under the Visual C# (and also Visual Basic) languages node, select the Silverlight subgroup. You’ll see a <strong>Silverlight Unit Test Application</strong> project template.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioUnitTestTemplate" border="0" alt="VisualStudioUnitTestTemplate" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioUnitTestTemplate.png" width="685" height="446" /></p>
<p>You now have two projects:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioTestAppAndClassLibrarySolutionExplorer" border="0" alt="VisualStudioTestAppAndClassLibrarySolutionExplorer" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioTestAppAndClassLibrarySolutionExplorer.png" width="283" height="385" /></p>
<p>Next up, we want to add a reference to the class library, so that the unit tests can access the library. Right-click on the new test project and then select the Add Reference option. Under the Project tab, choose the class library you created earlier.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioAddReference" border="0" alt="VisualStudioAddReference" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioAddReference.png" width="593" height="478" /></p>
<p>Now, let’s add some unit tests. Clear out the content in the created Tests.cs file and drop this in:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:a7e8d8fd-b4cb-4725-bb1a-cd35db6190c2" class="wlWriterEditableSmartContent">
<pre class="c-sharp" name="code">using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyApplication;

namespace PersonTestProject {
    [TestClass]
    public class Tests
    {
        [TestMethod]
        public void TestCtor()
        {
            Person p = new Person();
        }

        [TestMethod]
        public void TestSetName()
        {
            Person p = new Person { First = "Scott", Last = "Guthrie" };
            Assert.AreNotEqual(p.First, p.Last);
        }

        [TestMethod]
        public void TestGetFullName()
        {
            Person p = new Person { First = "Steve", Last = "Ballmer" };
            StringAssert.Equals("Steve Ballmer", p.FullName);
        }
    }
}</pre>
</div>
<p>The tests are pretty simple, and exercise various simple PMEs on the type.</p>
<h2>Run the unit tests from Visual Studio</h2>
<p>Right-click on the test project and select Set as StartUp Project from the menu. Then, press F5 or click the Run button to begin execution.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioSetAsStartupProject" border="0" alt="VisualStudioSetAsStartupProject" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioSetAsStartupProject.png" width="530" height="605" /> </p>
<p> The default web browser will open up, the tests will run, and the window will stay open. When you are satisfied, close the browser. You’ve just run some simple tests!</p>
<h2>Running unit tests from the Visual Studio command line</h2>
<p>More interesting is being able to automate the tests: through MSBuild, we’ve added a task that can control the browser and save out the log file(s) from the unit tests when they run.</p>
<p>To do this, you need a few things:</p>
<ul>
<li>The Visual Studio command prompt open.</li>
<li>The full path to the test project.</li>
</ul>
<h4>Open the command prompt</h4>
<p>Personally, I always pin the Visual Studio 2008 tools command prompt next to my Visual Studio taskbar icons.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TaskbarCmdPrompt" border="0" alt="TaskbarCmdPrompt" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/TaskbarCmdPrompt.png" width="685" height="71" /> </p>
<p>You can start it from the Start Menu, under the tools for the Visual Studio version you are using.</p>
<p>Alternatively, make sure MSBuild is in your path.</p>
<p>Or, start a command prompt and then move to your 32-bit Program Files, then ‘Visual Studio 9.0’, then VC. Run ‘vcvarsall.bat x86’</p>
<p><strong>Note</strong>: all these command prompts should be 32-bit, even on a x64 machine. Silverlight is a 32-bit world today.</p>
<h4>Move to the test project</h4>
<p>To get the full path to the test project, I just right-click on the test project in Visual Studio, then Open Folder in Windows Explorer. I copy the path from the resulting Explorer dialog’s crumb navigation bar.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioOpenWindowsExplorerForProjectLocation" border="0" alt="VisualStudioOpenWindowsExplorerForProjectLocation" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioOpenWindowsExplorerForProjectLocation.png" width="685" height="428" /> </p>
<p>Now, inside the command prompt window, move to that path:</p>
<blockquote>
<p>pushd (PASTE PATH HERE) &lt;enter&gt;</p>
</blockquote>
<p>To run the unit tests in the default browser, simply type </p>
<blockquote>
<p><strong>msbuild /t:test</strong> </p>
</blockquote>
<p>and press Enter.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CommandLineMsbuildTest" border="0" alt="CommandLineMsbuildTest" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/CommandLineMsbuildTest.png" width="685" height="120" /></p>
<p>You’ll see the browser open, quickly run some tests, and then close. Here’s what it looks like, captured in the middle of the 5-second test run:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TestRunningInInternetExplorer" border="0" alt="TestRunningInInternetExplorer" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/TestRunningInInternetExplorer.png" width="685" height="345" /></p>
<p>And afterwards, you’ll see that Msbuild reports success, and you can read the test to see that 3 passing tests were reported, out of 3 total tests.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CommandLineMsbuildTestWithResults" border="0" alt="CommandLineMsbuildTestWithResults" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/CommandLineMsbuildTestWithResults.png" width="685" height="433" /></p>
<h3>Running tests in Google Chrome</h3>
<p>It’s easy! Just set the browser property to Chrome.</p>
<blockquote>
<p><strong><font color="#808080">msbuild /t:test </font>/p:browser=chrome</strong></p>
</blockquote>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CommandLineMsbuildTestChrome" border="0" alt="CommandLineMsbuildTestChrome" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/CommandLineMsbuildTestChrome.png" width="685" height="67" />&#160;</p>
<p>And just like that, Chrome opens up and runs the tests.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TestRunningInChrome" border="0" alt="TestRunningInChrome" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/TestRunningInChrome.png" width="685" height="428" /></p>
<h3>Running tests in Mozilla Firefox</h3>
<p>Just set the browser to Firefox.</p>
<blockquote>
<p><strong><font color="#808080">msbuild /t:test </font>/p:browser=firefox</strong></p>
</blockquote>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TestRunningInFirefox" border="0" alt="TestRunningInFirefox" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/TestRunningInFirefox.png" width="685" height="428" /></p>
<h3>Tag Expressions</h3>
<p>A nice feature to help select a subset of tests is the Tag Expression syntax. By specifying a tag expression at the command prompt, you can include and exclude tests that are marked with the Tag attribute found in Microsoft.Silverlight.Testing.</p>
<p>Also, tags <strong>implicitly exist for all test method names,</strong> short and full.</p>
<p>So, let’s run the test called <strong>TestSetName</strong> from our project.</p>
<blockquote>
<p><strong><font color="#808080">msbuild /t:test </font>/p:tagexpression=TestSetName</strong></p>
</blockquote>
<p>You may briefly see indication in the test UI in the browser that a ‘Tag expression’ is in use.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TestRunningInInternetExplorerWithTagExpression" border="0" alt="TestRunningInInternetExplorerWithTagExpression" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/TestRunningInInternetExplorerWithTagExpression.png" width="685" height="344" /></p>
<p>And the build results show that just one test ran:</p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CommandLineMsbuildTestWithTagExpressionResults" border="0" alt="CommandLineMsbuildTestWithTagExpressionResults" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/CommandLineMsbuildTestWithTagExpressionResults.png" width="685" height="433" /> </p>
<p>If you want to run all tests <strong>except that one</strong>, use this tag expression:</p>
<blockquote>
<p><strong><font color="#808080">msbuild /t:test </font>/p:tagexpression=!TestSetName</strong></p>
</blockquote>
<p>Cool, and easy!</p>
<h3>Test results files</h3>
<p>Another nice feature of running the tests through MSBuild is that you’ll see test result files (end in *.trx) inside the same folder as the test page for the application.</p>
<p>Similar and conformant to the Visual Studio *.trx format, you can parse and work with this data to understand execution times, results, and read other information. Unfortunately, you cannot open these files in Visual Studio 2010 Beta 2, but they do open in Visual Studio 2008. Note that there isn’t any real test integration with VS here: this is just an informative display. </p>
<p>Here’s a directory with several test result files (plus some coverage stuff we’ll get to later):</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="LookingInTheBinariesFolderAfterTestsRun" border="0" alt="LookingInTheBinariesFolderAfterTestsRun" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/LookingInTheBinariesFolderAfterTestsRun.png" width="685" height="502" /></p>
<p>You can open up the TestResults trx file and see what kind of information is in it:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="LookingAtTheTrxFile" border="0" alt="LookingAtTheTrxFile" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/LookingAtTheTrxFile.png" width="685" height="524" /></p>
<p>And here’s the results file opened in Visual Studio:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudio2008TestResultsTrxFile" border="0" alt="VisualStudio2008TestResultsTrxFile" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudio2008TestResultsTrxFile.png" width="685" height="312" />&#160;</p>
<h2>Preparing for Code Coverage</h2>
<p>Ripe for a Visual Studio add-in, this process requires us modifying the test project’s .csproj file some. Instructions are the same for Visual Studio.</p>
<p>We need to <strong>manually select the assembly to be instrumented </strong>by setting a property. The assembly to be instrumented must not be signed, and not have a strong name. In this example, the assembly is <strong>SilverlightClassLibrary3</strong>.</p>
<p>To make changes to the test project, to specify this, first unload the project by right-clicking on the test project and selecting the Unload option: </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioUnloadProject" border="0" alt="VisualStudioUnloadProject" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioUnloadProject.png" width="503" height="621" /></p>
<p>Then, right-click the project file that is ‘(unavailable) and select ‘Edit’. </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioEditProject" border="0" alt="VisualStudioEditProject" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioEditProject.png" width="492" height="214" /></p>
<p>Now you’ll see the XML data for the project. Scroll down in the template to where there is a commented out ItemGroup, and some comments about the code coverage support. Remove the comments from the ItemGroup: </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioEditingTestProjectFileOriginal" border="0" alt="VisualStudioEditingTestProjectFileOriginal" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioEditingTestProjectFileOriginal.png" width="685" height="435" /></p>
<p>And now, change the Include statement from SilverlightClassLibrary1 to whatever your assembly to instrument is called. In our example here, it is called SilverlightClassLibrary3.</p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioEditingTestProjectFile2" border="0" alt="VisualStudioEditingTestProjectFile2" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioEditingTestProjectFile2.png" width="685" height="435" /> </p>
<p> Now, that’s it. Let’s close the file and then right-click the project again and select Reload Project:</p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VisualStudioReloadTestProject" border="0" alt="VisualStudioReloadTestProject" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/VisualStudioReloadTestProject.png" width="502" height="400" /> </p>
<p> Now we’re ready to go!</p>
<h2>Running Silverlight Code Coverage</h2>
<p>Just like the msbuild /t:test from above, we have a similar target named <strong>CoverageTest</strong> and <strong>CoverageView</strong>. CoverageTest collects the data, while CoverageView collects the coverage data and then shows the results in an application that explores the hit and not hit portions of your source code.</p>
<p>Let’s collect coverage!</p>
<p><strong>Note:</strong> This is assuming that you have a high-level SKU of Visual Studio 2010 Beta 2 installed. The coverage tools depend on the Static Analysis Tools that ship in the beta. You will receive an error if you run this on a machine without those tools. We’ll look for a better experience in the future.</p>
<p>Remember, the same properties from above – browser and tag expression – still can apply and work in the coverage targets.</p>
<blockquote>
<p><strong><font color="#808080">msbuild </font>/t:coveragetest</strong></p>
</blockquote>
<p>Here is what it will look like if everything line up. Unfortunately, the coverage experience is a very early preview and very flaky in some situations due to the dependency on beta components. We also haven’t had I admit enough time to iron out all the issues customers may experience.</p>
<p>You see the Instrumentation messages come out, then the RunTests target, then the coverage data is merged and things should be successful. </p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CommandLineMsbuildCoverageTestResults" border="0" alt="CommandLineMsbuildCoverageTestResults" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/CommandLineMsbuildCoverageTestResults.png" width="685" height="433" /></p>
<p>If that worked, it is safe to assume that the view target will also work. It will re-run all the tests and instrument again as well.</p>
<blockquote>
<p><strong><font color="#808080">msbuild </font>/t:coverageview</strong></p>
</blockquote>
<p>Now you’ll see the viewer popup, that lets you drill into types and methods to see what is hit (cyan) or not hit (red), to spot code that your tests are missing:</p>
<h3><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="LookingAtCodeCoverage" border="0" alt="LookingAtCodeCoverage" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/LookingAtCodeCoverage.png" width="685" height="428" /></h3>
<p>You’ll find a Coverage.xml file in the same directory where the test results go. This is the data that is used by the viewer application. You’ll see in the XML file a set of ‘visited’ blocks, and other information, in the file:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CoverageXmlFile" border="0" alt="CoverageXmlFile" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/CoverageXmlFile.png" width="685" height="435" /> </p>
<p>More to come soon!</p>
<h3>Download the Silverlight Toolkit November 2009 Release Today</h3>
<p><a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36060"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Toolkit32[2][2][2]" border="0" alt="Toolkit32[2][2][2]" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/11/Toolkit32222.png" width="685" height="88" /></a> </p>
<p>The Silverlight Toolkit is a collection of Silverlight controls, components and utilities that help make Silverlight development a little easier, more fun, and add value outside the regular Silverlight release cycle.</p>
<p>The sixth release of the Silverlight Toolkit, the November 2009 release targets Silverlight 3. There is also a release available that targets the new Silverlight 4 Beta for developers.</p>
<p>Resources of note:</p>
<ul>
<li><a href="http://silverlight.codeplex.com/">Learn more about the Silverlight Toolkit</a> </li>
<li><a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36060"><strong>Download the November 2009 Release</strong></a> </li>
<li><a href="http://silverlight.net/getstarted/">Get started with Silverlight development</a> </li>
<li>Participate in the <a href="http://silverlight.net/forums/35.aspx">controls community at Silverlight.net</a> </li>
<li>Check out questions and answers on Stack Overflow using the <a href="http://stackoverflow.com/questions/tagged/silverlight-toolkit">‘silverlight-toolkit’ tag</a> </li>
<li>The <a href="http://silverlight.codeplex.com/WorkItem/List.aspx">Issue Tracker</a> can be used to report issues, add to the feature wish list, and vote on the work to be done by the Microsoft team </li>
</ul>
<p><em>Hope you enjoy our new release!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/11/november-walkthrough/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>Round-tripping Silverlight 3 projects with Visual Studio 2008 and Visual Studio 2010</title>
		<link>http://www.jeff.wilcox.name/2009/10/roundtripping-silverlight-with-2010/</link>
		<comments>http://www.jeff.wilcox.name/2009/10/roundtripping-silverlight-with-2010/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 04:39:28 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/10/roundtripping-silverlight-with-2010/</guid>
		<description><![CDATA[Here's a simple tool that I use to round-trip Silverlight solutions and projects between Visual Studio 2008 and Visual Studio 2010 Beta. Use it at your own risk, but enjoy!]]></description>
			<content:encoded><![CDATA[<p>Now that Visual Studio 2010 Beta 2 is out, it is a lot of fun to use the fully interactive design surface for Silverlight. However, it comes at a cost: you need to use the conversion wizard to bring your Visual Studio 2008 solutions and projects up to the expected format for the designer tools and new build environment.</p>
<p>If you deliver your source ultimately to a Visual Studio 2008-targeted source project, or have issue adopting a beta product until its release, this is a pain.</p>
<p><a href="http://www.jeff.wilcox.name/wp-content/uploads/2009/10/ThereAndBackAgain.zip"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VsConversion" border="0" alt="VsConversion" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/10/VsConversion.png" width="680" height="379" /></a> </p>
<p>I wrote a tool last month for round-trip converting Silverlight-specific solutions and .csproj files between the versions, and want to share it as-is, with no warranty, hoping someone finds it useful.</p>
<p>Here are two potential solutions for dealing with the conversion issue, actually the second builds from the first.</p>
<h3>Use Source Control</h3>
<p>If your project is not churning that often in added and removed files, source control is the easiest solution to this problem!</p>
<ul>
<li>Open your solution in Visual Studio 2010</li>
<li>Allow the conversion wizard to complete</li>
<li>When checking in, carefully revert the .csproj and .sln files (assuming no changes to their contents)</li>
</ul>
<p>Easy enough. But not crisp enough!</p>
<h3>Use my hacky program</h3>
<p>Now assuming you are already using source control, then you can consider using my script/tool for performing the round-trip conversion. You <strong>still</strong> want to have everything in source control – you just never know.</p>
<h4>Before we start</h4>
<ul>
<li>This program will work on the <strong>current directory</strong> and <strong>all subdirectories</strong></li>
<li>It will <strong>modify read-only files</strong></li>
<li>It will consider <strong>all .csproj and .sln files</strong>, potentially destroying non-Silverlight project files – so use caution if the current directory or sub-directory contains other project types</li>
<li>This is <strong>C#-only</strong>, though a similar exercise for .vbproj files would not be that bad</li>
<li>This will <strong>delete</strong> .suo and .user files that may contain version-specific binary data, so you may lose your local settings (such as the current startup project you have set locally)</li>
<li>This ‘works on my machine’ and I am not responsible for data loss in any way</li>
<li>This code is not efficient nor elegant. Get over it! I did!</li>
</ul>
<h4>Download the binary and source</h4>
<p><a href="http://www.jeff.wilcox.name/wp-content/uploads/2009/10/ThereAndBackAgain.zip"><strong>ThereAndBackAgain.zip</strong></a> [21.8K, Zip]</p>
<p>I have included the source, Ms-PL licensed, because though awful, maybe someone can do something much better with it!</p>
<h4>Convert all C# projects and solutions to Visual Studio 2010</h4>
<p>Move into the root directory of your solution in a command prompt window, and provide the path to the ThereAndBackAgain.exe file. It will recurse the current directory.</p>
<blockquote><p>pushd c:\myEnlistment\myProject\Silverlight\</p>
<p>c:\tools\ThereAndBackAgain.exe <strong>2010</strong> &lt;enter&gt;</p>
</blockquote>
<p>You’ll see a quick list of what is changed. You can run this on a directory tree that is already converted, and it should not be affected.</p>
<h4>Convert back to Visual Studio 2008</h4>
<p>Pretty similar:</p>
<blockquote><p>pushd c:\myEnlistment\myProject\Silverlight\</p>
<p>c:\tools\ThereAndBackAgain.exe <strong>2008</strong> &lt;enter&gt;</p>
</blockquote>
<h4>Final note</h4>
<p>This works for me. Uh and so no promises beyond that. I <strong>literally just diff’d a new VS 08 and VS 2010 Silverlight project and wrote something to move between the two. </strong>Nothing fancy.</p>
<p><em>If you go this route, remember to convert back your projects and solutions using the tool before checking in! You don’t want to break the build, or a teammates’ development experience.</em></p>
<p>Hope this helps. Again, I wrote this script specifically to meet my needs, but it is FAR from production-ready. You are on your own, feel free to take and run with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/10/roundtripping-silverlight-with-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 unit test framework binaries updated</title>
		<link>http://www.jeff.wilcox.name/2009/07/silverlight-2-unit-test-framework-binaries-updated/</link>
		<comments>http://www.jeff.wilcox.name/2009/07/silverlight-2-unit-test-framework-binaries-updated/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 19:45:19 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=421</guid>
		<description><![CDATA[If you're doing Silverlight 2 development with the unit test framework, you might want to check out the latest release that includes bug fixes and a few small new features.]]></description>
			<content:encoded><![CDATA[<p>The Silverlight Unit Test Framework ships officially inside of the <a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a>, since the team has a dependency on it for thousands and thousands of unit tests.</p>
<p>I recently did hear a few complaints that the <a href="http://code.msdn.microsoft.com/silverlightut">Silverlight Unit Test Framework site</a> on the MSDN Code Gallery is a little out of date. I hear you, and am going to try to refresh the wiki and documentation a little bit.</p>
<p>In the meantime, I&#8217;ve updated the site with the latest Silverlight 2 Unit Test Framework binaries for download. Here&#8217;s a <a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightut&#038;DownloadId=6400">direct link to the download</a>. I don&#8217;t have any updated bits available for the Silverlight 3 Beta at this time.</p>
<h3>What&#8217;s new in the July 2009 bits of the Silverlight Unit Test Framework?</h3>
<ul>
<li>Support for the [Timeout(...)] attribute on test methods.</li>
<li>Improvements to the Test Service interface. The service now has an asynchronous reporting phase that allows for more robust automation options (details coming soon).</li>
<li>Minor interface changes</li>
<li>Minor bug fixes</li>
</ul>
<p>I&#8217;ll try and get updated templates produced this month as well. Hope this is useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/07/silverlight-2-unit-test-framework-binaries-updated/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Building Silverlight 2 and Silverlight 3 Beta applications on the same machine</title>
		<link>http://www.jeff.wilcox.name/2009/03/sxs-sl2-sl3-building/</link>
		<comments>http://www.jeff.wilcox.name/2009/03/sxs-sl2-sl3-building/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 01:23:59 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=344</guid>
		<description><![CDATA[Although the Silverlight Tools don't have a multi-targeting story, you can build Silverlight 2 and Silverlight 3 Beta applications on the same machine. Here's information on how we do this within the Silverlight Toolkit team.]]></description>
			<content:encoded><![CDATA[<p>The Silverlight Tools don&#8217;t have multi-targeting support today, so if you want to continue building Silverlight 2 applications (for production sites), while experimenting and learning about the Silverlight 3 Beta, it isn&#8217;t that easy.</p>
<p>On the Silverlight Toolkit team, we leave it up to individual team members to decide what core development environment they want. By having the Silverlight 2 and Silverlight 3 SDKs checked into our source enlistment, our TFS build server can produce Silverlight 2 <i>and</i> Silverlight 3 binaries, and we can also msbuild the same bits on our machines, regardless of the Silverlight Tools, SDK, or runtime installed on our machines.</p>
<p>I <a href="http://www.jeff.wilcox.name/2009/01/independent-silverlight-msbuild/">blogged about this back in late January</a> about &#8220;building Silverlight code on machines without the SDK installed,&#8221; though really it was more about &#8220;building Silverlight code for multiple Silverlight versions.&#8221;</p>
<h3>Select your primary development environment</h3>
<p>Decide whether you would like to do primarily Silverlight 2 or 3 development. Then, install the accompanying tools install, and Expression Blend version.</p>
<p>It is time consuming to move between the two environments, but you can actually uninstall/reinstall the shipping runtime or developer runtime versions of Silverlight if you need to test an app in a specific configuration, without having to do a full reinstall of the <i>tools</i>.</p>
<h3>Preparing your source enlistment</h3>
<p>On the Toolkit, we have a directory of external tools and engineering resources. One of these contains the Silverlight SDK’s assemblies, libraries, and build scripts, as shown in the video.</p>
<ul>
<li>Create a directory to store the MsBuild assets for Silverlight, and copy in the files from %programfiles%MSBuild\Microsoft\Silverlight\v2.0. </li>
<li>Copy the “Reference Assemblies” directory from %programfiles%\Microsoft SDKs\Silverlight\v2.0\ into the tools directory. </li>
<li>Copy the “Libraries” directory from %programfiles%\Microsoft SDKs\Silverlight\v2.0\ into the directory. </li>
</ul>
<p>You can then use relative paths in your projects or custom build targets to get things rolling.</p>
<h3>How we use a custom &lt;Import /&gt; element in projects</h3>
<p>Our source code enlistment is broken up into a Silverlight 2 and a Silverlight 3 branch of nearly-identical trees of code. By using a centralized msbuild .targets file, we&#8217;re able to leave it up to a single file in the branch to select which verison of Silverlight the application should build with.</p>
<p>This actually even works when building in Visual Studio, so opening a project that uses this method, while using the Silverlight 3 Tools, but building a Silverlight 2 app, will build with the verison 2 SDK. Do note that the design-time experience won&#8217;t work in this scenario.</p>
<h4>Silverlight.CSharp.targets</h4>
<p>All of our VB and C# source projects for Silverlight, within the source enlistment, reference a relative path, typically something like ..\..\Silverlight.CSharp.targets, instead of the standard Silverlight CSharp targets from the Silverlight MSBuild scripts.</p>
<p>Inside this relative path, it defines the properties. For Silverlight 2:</p>
<pre name="code" class="xml">
&lt;Project
  ToolsVersion=&quot;3.5&quot;
  DefaultTargets=&quot;Build&quot;
  xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;

  &lt;PropertyGroup&gt;
    &lt;!-- Define the ExternalTools property first --&gt;
    &lt;SilverlightBuildResources&gt;$(ExternalTools)\Silverlight\v2.0\&lt;/SilverlightBuildResources&gt;
    &lt;TargetFrameworkDirectory&gt;$(SilverlightBuildResources)Reference Assemblies\&lt;/TargetFrameworkDirectory&gt;
    &lt;TargetFrameworkSDKDirectory&gt;$(SilverlightBuildResources)Libraries\Client\&lt;/TargetFrameworkSDKDirectory&gt;
    &lt;SilverlightRuntimeVersion&gt;2.0.31005.0&lt;/SilverlightRuntimeVersion&gt;
  &lt;/PropertyGroup&gt;
  &lt;Import Project=&quot;$(SilverlightBuildResources)Microsoft.Silverlight.CSharp.targets&quot;/&gt;

&lt;/Project&gt;
</pre>
<p>And for Silverlight 3 Beta:</p>
<pre name="code" class="xml">
&lt;Project
  ToolsVersion=&quot;3.5&quot;
  DefaultTargets=&quot;Build&quot;
  xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;

  &lt;PropertyGroup&gt;
    &lt;!-- Define the ExternalTools property first --&gt;
    &lt;SilverlightBuildResources&gt;$(ExternalTools)\Silverlight\v3.0\&lt;/SilverlightBuildResources&gt;

    &lt;TargetFrameworkDirectory&gt;$(SilverlightBuildResources)Reference Assemblies\&lt;/TargetFrameworkDirectory&gt;
    &lt;TargetFrameworkSDKDirectory&gt;$(SilverlightBuildResources)Libraries\Client\&lt;/TargetFrameworkSDKDirectory&gt;
    &lt;SilverlightRuntimeVersion&gt;3.0.40217.0&lt;/SilverlightRuntimeVersion&gt;
  &lt;/PropertyGroup&gt;
  &lt;Import Project=&quot;$(SilverlightBuildResources)Microsoft.Silverlight.CSharp.targets&quot;/&gt;
&lt;/Project&gt;
</pre>
<p>Hope this helps and is useful to you and your development team.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/03/sxs-sl2-sl3-building/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Silverlight Toolkit grows up a little with an install experience</title>
		<link>http://www.jeff.wilcox.name/2009/03/silverlight-toolkit-installer/</link>
		<comments>http://www.jeff.wilcox.name/2009/03/silverlight-toolkit-installer/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 08:06:24 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[MIX]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=330</guid>
		<description><![CDATA[The Silverlight Toolkit's March 2009 release is out, now with an installation experience that adds controls to the Visual Studio and Expression Blend toolbox, and improves the design experience.]]></description>
			<content:encoded><![CDATA[<p><img alt="Silverlight 3 Visual Studio Toolbox" src="http://media.jeff.wilcox.name/blog/mix09/Silverlight3Toolbox.png" title="Silverlight 3 Visual Studio Toolbox" width="240" height="1946" align="right" hspace="4" vspace="4" />The <a href="http://silverlight.codeplex.com/">Silverlight Toolkit March 2009</a> includes an install experience for the first time. Instead of having to download a Zip file with all the bits and little instruction, we now have a complete installation experience for Windows.</p>
<p>This provides a very nice experience when using Visual Studio 2008 and Expression Blend 3, since the Toolkit&#8217;s controls appear alongside all other Silverlight SDK controls now.</p>
<p>I wanted to take a few minutes and record a few questions and answers about the new experience. Let me know if there are some other questions you&#8217;d like answered.</p>
<h3>Why are there two setup downloads for the March 2009 release?</h3>
<p>The March 2009 release is available for targeting Silverlight 2 applications (recommended for most developers and designers working on current production Silverlight 2 apps), and a Silverlight 3 Beta release.</p>
<p>Since the target platform is important, you can make a choice. Of course, both the Silverlight 2 and Silverlight 3 Beta installs for the Silverlight Toolkit support side-by-side; however, the Visual Studio 2008&#8242;s Silverlight Tools do not support &#8220;multi-targeting,&#8221; so you really should decide and stick to a single target development environment for Silverlight coding today.</p>
<h3>What are the system requirements?</h3>
<p>The Silverlight Toolkit only requires a recent version of the .NET framework to install. However, for the best experience, you should have one of these development environments installed and configured:</p>
<ul>
<li>Visual Studio 2008 SP1 with the Silverlight Tools (Silverlight 2 or Silverlight 3 Beta)</li>
<li>Visual Web Developer Express with the Silverlight Tools (Silverlight 2 or Silverlight 3 Beta)</li>
<li>Expression Blend 2 SP1 with Silverlight 2</li>
<li>Expression Blend 3 MIX &#8217;09 Preview with Silverlight 3 Beta</li>
</ul>
<p>More information about these tools and downloads is available at <a href="http://silverlight.net/getstarted/silverlight3/default.aspx">http://silverlight.net/getstarted/silverlight3/default.aspx</a>.</p>
<p>You can install the Silverlight Toolkit before or after the Silverlight Tools installation.</p>
<h3>What&#8217;s with the namespace change to System.Windows.Controls?</h3>
<p>As the Silverlight Toolkit has begun delivering controls into the official Silverlight SDK, it became apparent that we should be consistent across the Silverlight platform with regard to the namespace used for the Microsoft controls. As a result, we decided to make this namespace change along with the new &#8220;.Toolkit&#8221; assembly name scheme.</p>
<h3>Where&#8217;s the AutoCompleteBox control? How about TreeView?</h3>
<p>Some of the &#8220;Stable&#8221; controls were moved to the official Microsoft Silverlight 3 Beta SDK, since they are trending towards the &#8220;Mature&#8221; quality band. As a result, the controls live in different assemblies depending on whether you are performing Silverlight 2 or Silverlight 3 Beta development.</p>
<p>In the Silverlight 2 Toolkit March 2009 release, AutoCompleteBox is in System.Windows.Controls.Input.Toolkit. TreeView is in System.Windows.Controls.Toolkit.</p>
<p>In the Silverlight 3 Toolkit March 2009 release, AutoCompleteBox is in System.Windows.Controls.Input. TreeView is in System.Windows.Controls. <i>These assemblies are part of the Silverlight 3 Beta SDK and DO NOT require installation of the Silverlight Toolkit.</i></p>
<p>The Silverlight 2 controls are compatible with Silverlight 3, so existing applications will continue to work &#8211; but we do highly recommend that you update to the appropriate Silverlight Toolkit for your target Silverlight version, since we  do add version-enhanced features, such as animation easing for the Silverlight Toolkit charts in the Silverlight 3 Beta.</p>
<p>More information about the assembly and namespace name changes is available in <a href="http://blogs.msdn.com/sburke/archive/2009/03/20/silverlight-toolkit-march-2009-release.aspx">this post by Shawn Burke</a>.</p>
<h3>What is installed with the Silverlight Toolkit now?</h3>
<p>You&#8217;ll find the same basics as before, plus some. You&#8217;ll find these in the &#8220;Microsoft Silverlight 3 Toolkit March 2009&#8243; (or similarly named folder for the Silverlight 2 version) folder in your Start Menu.<br />
<img alt="" src="http://media.jeff.wilcox.name/blog/mix09/StartMenu.png" title="Start Menu" class="alignnone" width="267" height="295" /></p>
<ul>
<li>New &#8220;Welcome&#8221; page with general information about the release, plus a link to the breaking changes and release notes for the release.</li>
<li>Links to the CodePlex site for the Toolkit, plus the Silverlight.net discussion forums</li>
<li>A link to the sample application for the Toolkit, served from the local system</li>
<li>Links to Zip files containing the control source code and/or the sample source code</li>
<li>The documentation for the Toolkit controls in CHM format. The documentation file no longer requires the &#8220;Unlock&#8221; workaround step on Windows Vista and Windows 7. Do note that the documentation for former Silverlight Toolkit controls that now appear in the Silverlight 3 SDK, such as AutoCompleteBox, are now located in the official Silverlight documentation. An <a href="http://blogs.msdn.com/silverlight_sdk/archive/2009/03/18/silverlight-3-beta-offline-msdn-docs-chm-is-available.aspx">offline download of the SDK documentation</a> is also available.</li>
</ul>
<h3>What rocked about the Zip?</h3>
<p>Well, in my mind, it was:</p>
<ul>
<li>Transparent experience</li>
<li>Nothing fancy</li>
<li>Lightweight. Nothing to install, so if you didn&#8217;t want it anymore, you could just delete the files, for instance.</li>
</ul>
<h3>What was so bad about the Zip?</h3>
<ul>
<li>No integration into Visual Studio or Expression Blend out-of-the-box, without doing some manual file copy or registry work</li>
<li>Confusing to users used to a setup experience</li>
<li>CHM documentation files downloaded in a Zip require &#8220;Unlocking&#8221; before they work. Until then, they appear broken.</li>
</ul>
<h3>Would you consider offering releases in a Zip file, optionally, still?</h3>
<p>We&#8217;re open to the idea. Especially now that there&#8217;s an Eclipse Silverlight development experience, we do need to be mindful of the need to use the releases on other platforms.</p>
<p>Since our packaging infrastructure was initially designed to output these nice .Zip files, it wouldn&#8217;t be too tough for us to get this going. We&#8217;ll see what the customer requests look like.</p>
<h3>How do I select whether I want to get the source code to the controls?</h3>
<p>There is an installation option for a feature called &#8220;Source code,&#8221; you can click on the box to the left of the item and remove the component if you would not like to install the source package.</p>
<p>If you do select this feature (per the default), a .Zip file is placed on the system that contains the source code. You can extract the zip file into a location of your selection to build or view the source.</p>
<p><img alt="Setup Options" src="http://media.jeff.wilcox.name/blog/mix09/SetupOptions.png" title="Setup Options" class="alignnone" width="509" height="398" /></p>
<p>As always, the source is also available on the <a href="http://silverlight.codeplex.com/">Silverlight Toolkit CodePlex site</a>.</p>
<h3>What about Microsoft Expression Blend integration?</h3>
<p>The Blend 3 MIX09 Preview release includes support for having the Silverlight Toolkit appear in the &#8220;Custom Controls&#8221; tab of the Asset Library. This is only available for Silverlight 3 Beta, not the Silverlight 2 / Expression Blend 2 product.</p>
<p><img alt="" src="http://media.jeff.wilcox.name/blog/mix09/Blend3Toolbox.png" title="Blend 3 Toolbox" class="alignnone" width="685" height="323" /></p>
<p>There is some really great design time support in this release. For instance, if you just drop a &#8220;Chart&#8221; control onto your Blend design canvas, you&#8217;re greeted with a chart that has simple design time data! It might look a little like one of those &#8220;the most bars anywhere&#8221; cell phone commercials, but it is very helpful for styling.</p>
<p><img alt="" src="http://media.jeff.wilcox.name/blog/mix09/ChartDesignTime.png" title="Chart design time" class="alignnone" width="685" height="347" /></p>
<h3>What powers the installer?</h3>
<p>We leveraged the open source <a href="http://wix.sourceforge.net/">Windows Installer XML (WiX) toolset</a>, an excellent and easy way to build Windows Installer packages. Kudos to Eric St. John, a Microsoft developer who contributes to WiX, for excellent advice, btw!</p>
<p><img alt="" src="http://media.jeff.wilcox.name/blog/mix09/SilverlightToolkitInstaller.png" title="Silverlight Toolkit Installer" class="alignnone" width="509" height="398" /></p>
<p>This was important to our small development team, since we wanted to spend time working on new features like <b>awesome design-time integration</b> and new controls like <b>accordion</b> instead of assigning a developer to the setup full-time.</p>
<p>Hope you like the new experience. Let us know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/03/silverlight-toolkit-installer/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A prototype tool for designers and developers: converting XAML to ISM themes and back again</title>
		<link>http://www.jeff.wilcox.name/2009/03/themetool/</link>
		<comments>http://www.jeff.wilcox.name/2009/03/themetool/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:50:37 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=300</guid>
		<description><![CDATA[The Silverlight Toolkit contains implicit style management features that let you create a nice theme – buttons, checkboxes, you name it – and have it automatically applied to an application. Nearly half a year ago, I worked with Mehdi to create a rather simple, but functional, tool prototype for working with Xaml theme files and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a> contains implicit style management features that let you create a nice theme – buttons, checkboxes, you name it – and have it automatically applied to an application. Nearly half a year ago, I worked with <a href="http://blogs.msdn.com/mehdis/">Mehdi</a> to create a rather simple, but functional, tool prototype for working with Xaml theme files and ISM-consumable implicit style definitions. </p>
<p>Great stuff for designers, this prototype tool enables designers to use Blend day-to-day for getting immediate feedback and excellent tooling support, while being able to round-trip themes, from Blend to ISM to Blend again.</p>
<p>This tool is not guaranteed to be lossless. Use it at your own risk. It will take a XAML file that Blend appreciates (details on <a href="http://blogs.msdn.com/mehdis/archive/2008/11/18/creating-new-ism-compatible-themes.aspx">Mehdi&#8217;s blog</a>):</p>
<ul>
<li>No x:Key attributes</li>
<li>References to other styles by key name become fully qualified resource lookups: from ScrollViewerStyle to System.Windows.Controls.ScrollViewer</li>
<li>There are some assumption about naming</li>
<li>Adding explicit references to other styles</li>
</ul>
<p>&#8230; and convert it into an ISM theme.</p>
<p>Today I’m finally blogging a prototype version of the app, a work-in-progress, hoping that maybe others will have the time to make better use of it than I have. I have grand visions for the tool: add a file system watcher, monitor file saves in Blend, and then immediately msbuilding updated ISM theme assembly files. Updating sample apps behind the scenes. Real-time theme previews. None of those grand features are in the download. Give it time.</p>
<p><a href="http://media.jeff.wilcox.name/blog/view/ToolkitTheme.zip">Download a VS&#8217;08 console project with the source (Ms-PL)</a><br />
<a href="http://blogs.msdn.com/mehdis/archive/2008/11/18/creating-new-ism-compatible-themes.aspx">Read Mehdi&#8217;s guide on ISM styles</a></p>
<p>To run, use either:<br />
ToolkitTheme.exe App.xaml /t:ism MyIsmTheme.xaml<br />
ToolkitTheme.exe MyIsmTheme.xaml /t:blend App.xaml</p>
<p>Since this is a proof-of-concept prototype, I&#8217;m only releasing source for now, assuming you&#8217;re a developer at heart &#8211; no designer binaries. Let me know if you have any feedback on the tool!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/03/themetool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CloudFront. Cloud Files. Others?</title>
		<link>http://www.jeff.wilcox.name/2009/02/other-cloud-services/</link>
		<comments>http://www.jeff.wilcox.name/2009/02/other-cloud-services/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 08:04:30 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=282</guid>
		<description><![CDATA[In the interest of offloading my dedicated web server, and experimenting with the latest in distributed computing and storage, I find myself switching between different web file storage technologies quite often. The availability of distributed content delivery network (CDN)-like services for files to developers has only just started to begin. S3 was a first step; [...]]]></description>
			<content:encoded><![CDATA[<p>In the interest of offloading my dedicated web server, and experimenting with the latest in distributed computing and storage, I find myself switching between different web file storage technologies quite often.</p>
<p>The availability of distributed content delivery network (CDN)-like services for files to developers has only just started to begin. <a href="http://aws.amazon.com/s3/">S3</a> was a first step; <a href="http://streaming.live.com/">Silverlight Streaming</a> provided some interesting concepts.</p>
<p>I am wondering now if anyone else is experimenting with two very recent areas pushing this space:</p>
<p><strong><a href="http://www.mosso.com/index.jsp">Mosso</a></strong>: &#8220;The Rackspace Cloud&#8221; &#8211; offers distribution on Limelight. $0.22/GB for the first few terabytes.</p>
<p><strong><a href="http://aws.amazon.com/cloudfront/">CloudFront</a></strong> by Amazon: varies by edge location, starts at $0.17/GB for most locations.</p>
<p>I&#8217;ve been able to host Silverlight content and applications just great with these, and the costs are so very  affordable.</p>
<p>CloudFront connects directly to your S3 storage. S3 is in use in so many places now that I can write a simple Silverlight application, use S3 for all of its data needs, and make the application independent of its host application server. In fact, it can be entirely served and hosted through S3.</p>
<p>Are there other services I should be aware of? I figure that Limelight and Akamai directly only deal with large customers, and do not cater to a development audience.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/02/other-cloud-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unscientific SSD build time comparison</title>
		<link>http://www.jeff.wilcox.name/2009/02/comparing-toolkit-build-times/</link>
		<comments>http://www.jeff.wilcox.name/2009/02/comparing-toolkit-build-times/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 19:50:16 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/02/comparing-toolkit-build-times/</guid>
		<description><![CDATA[A few days ago I mentioned that I’ve been using an SSD drive in my desktop workstation at home, with pretty great success. The Intel X25-M is where it is at – give it another half year for the prices to become reasonable and I bet you’ll see more folks adopting it. Eric Hexter was [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I mentioned that I’ve been <a href="http://www.jeff.wilcox.name/2009/02/thanks-to-ssd/">using an SSD drive in my desktop workstation</a> at home, with pretty great success. The <a href="http://www.amazon.com/gp/product/B001F4YIYY?ie=UTF8&#038;tag=jwilcoxblog-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001F4YIYY">Intel X25-M</a> is where it is at – give it another half year for the prices to become reasonable and I bet you’ll see more folks adopting it.</p>
<p>Eric Hexter was wondering if I could figure out any build time differences, and so what I did was download the Silverlight Toolkit source code from <a href="http://www.codeplex.com/Silverlight/">http://www.codeplex.com/Silverlight/</a> and build on a few different systems.</p>
<p>This isn’t scientific, but the machines were all similar enough (Core 2 Duo or Quad Core; building on a single core only, not a parallelized build) that I feel OK at least sharing the numbers I received in a single build attempt.</p>
<table border="0" cellspacing="0" cellpadding="2" width="670">
<tbody>
<tr>
<td valign="top" width="167">&#160;</td>
<td valign="top" width="167">7200rpm</td>
<td valign="top" width="167">10000rpm Raptor</td>
<td valign="top" width="167">Intel X25-M SSD</td>
</tr>
<tr>
<td valign="top" width="167">Clean Toolkit build</td>
<td valign="top" width="167">3:23.11</td>
<td valign="top" width="167">2:41.22</td>
<td valign="top" width="167">1:44.97</td>
</tr>
</tbody>
</table>
<p>Not conclusively awesome; a lot of the build time is actually spent performing code analysis, and so your own build might be more or less disk read dependent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/02/comparing-toolkit-build-times/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight MsBuild tricks &#8211; video</title>
		<link>http://www.jeff.wilcox.name/2009/01/silverlight-msbuild-tricks-video/</link>
		<comments>http://www.jeff.wilcox.name/2009/01/silverlight-msbuild-tricks-video/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 09:23:05 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=262</guid>
		<description><![CDATA[Build Silverlight apps and libraries without having to install the SDK in your build lab, following this video. A re-post.]]></description>
			<content:encoded><![CDATA[<p>A re-post, I had to switch video streaming services&#8230;</p>
<p>Part of the Silverlight SDK can be copied into your source tree to build projects on machines without requiring Silverlight or the SDK. This is great for continuous integration environments and build labs where having an independent build is key.</p>
<p>I’ve compiled a quick screencast (6:07) that demonstrates preparing a directory to check in the proper SDK components, updating a C# project file, and then proving the result by uninstalling the Silverlight SDK.</p>
<h3>Walkthrough video</h3>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="685" height="385"><param name="source" value="http://media.jeff.wilcox.name/video/VideoPlayerM.xap" /><param name="background" value="white" /><param name="initParams" value="m=http://media.jeff.wilcox.name/video/SilverlightMsBuild.wmv" /><param name="enableHtmlAccess" value="true" /><param name="minruntimeversion" value="2.0.31005.0" />Your machine either needs Silverlight, or your feed reader does not permit embedded Silverlight content.  Please click-through to the post to view the video.<br />		<a href="http://go.microsoft.com/fwlink/?LinkId=124807" style="text-decoration: none;"><img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a></object><br /><em>6:07, 60MB, HD 720p (<a href="http://media.jeff.wilcox.name/video/SilverlightMsBuild.wmv">Download WMV</a>)</em></p>
<h3>Properties respected by the Silverlight MsBuild targets</h3>
<p>The Silverlight build system respects these build properties that can override the standard SDK locations:</p>
<table border="0" cellspacing="0" cellpadding="2" width="670">
<tbody>
<tr>
<td valign="top" width="335"><strong>Property</strong></td>
<td valign="top" width="335"><strong>Standard value</strong></td>
</tr>
<tr>
<td valign="top" width="335">TargetFrameworkDirectory</td>
<td valign="top" width="335">[Silverlight SDK]\Reference Assemblies\</td>
</tr>
<tr>
<td valign="top" width="335">TargetFrameworkSDKDirectory</td>
<td valign="top" width="335">[Silverlight SDK]\Libraries\Client\</td>
</tr>
<tr>
<td valign="top" width="335">SilverlightRuntimeVersion</td>
<td valign="top" width="335">2.0.31005.0</td>
</tr>
</tbody>
</table>
<p>The runtime version is used when generating the application manifest and HTML test page.</p>
<h3>Preparing your source enlistment</h3>
<p>On the Toolkit, we have a directory of external tools and engineering resources. One of these contains the Silverlight SDK’s assemblies, libraries, and build scripts, as shown in the video.</p>
<ul>
<li>Create a directory to store the MsBuild assets for Silverlight, and copy in the files from %programfiles%MSBuild\Microsoft\Silverlight\v2.0. </li>
<li>Copy the “Reference Assemblies” directory from %programfiles%\Microsoft SDKs\Silverlight\v2.0\ into the tools directory. </li>
<li>Copy the “Libraries” directory from %programfiles%\Microsoft SDKs\Silverlight\v2.0\ into the directory. </li>
</ul>
<p>You can then use relative paths in your projects or custom build targets to get things rolling.</p>
<h3>Updating projects</h3>
<p>Depending on your build system, you’ll want to update your custom targets or project files. In the video I’m simply modifying the .csproj file to add the necessary properties and modify the import statement.</p>
<h4>Add properties</h4>
<p>I’d scroll through the .csproj and insert the new properties right before the Import statement that pulls in the Silverlight build targets. Here are the properties defined; the SilverlightBuildResources property is my own made-up name that I’m using to store the relative path to the new building bits:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:1d721b58-bf73-4637-8135-1f7136b44119" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;PropertyGroup&gt;
    &lt;SilverlightBuildResources&gt;..\Build\&lt;/SilverlightBuildResources&gt;
    &lt;TargetFrameworkDirectory&gt;$(SilverlightBuildResources)Reference Assemblies\&lt;/TargetFrameworkDirectory&gt;
    &lt;TargetFrameworkSDKDirectory&gt;$(SilverlightBuildResources)Libraries\Client\&lt;/TargetFrameworkSDKDirectory&gt;
    &lt;SilverlightRuntimeVersion&gt;2.0.31005.0&lt;/SilverlightRuntimeVersion&gt;
  &lt;/PropertyGroup&gt;</pre>
</div>
<h4>Import the new Silverlight build target</h4>
<p>Silverlight projects import the Silverlight MsBuild targets from the central MsBuild extensions directory, so we just need to update the import to instead come from the source tree:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:21a1f393-b551-49ae-9ae0-e960ab17809f" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;Import Project="$(SilverlightBuildResources)Microsoft.Silverlight.CSharp.targets" /&gt;
  &lt;!--
	This is the default provided for new Silverlight projects:
  &lt;Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" /&gt;
  --&gt;</pre>
</div>
<h4>Build</h4>
<p>You’re all set! And, for future reference: you can use this to build applications targeting multiple versions of Silverlight from the same tree. But more on that later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/01/silverlight-msbuild-tricks-video/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://media.jeff.wilcox.name/video/SilverlightMsBuild.wmv" length="60999705" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Building Silverlight code on machines without the SDK (guide &amp; video)</title>
		<link>http://www.jeff.wilcox.name/2009/01/independent-silverlight-msbuild/</link>
		<comments>http://www.jeff.wilcox.name/2009/01/independent-silverlight-msbuild/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 08:09:23 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/01/independent-silverlight-msbuild/</guid>
		<description><![CDATA[A guide and walkthrough video showing how to setup a source enlistment to build Silverlight apps on machines without Silverlight or the SDK installed.]]></description>
			<content:encoded><![CDATA[<p>Part of the Silverlight SDK can be copied into your source tree to build projects on machines without requiring Silverlight or the SDK. This is great for continuous integration environments and build labs where having an independent build is key.</p>
<p>I’ve compiled a quick screencast (6:07) that demonstrates preparing a directory to check in the proper SDK components, updating a C# project file, and then proving the result by uninstalling the Silverlight SDK.</p>
<h3>Walkthrough video</h3>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="685" height="385"><param name="source" value="http://media.jeff.wilcox.name/video/VideoPlayerM.xap" /><param name="background" value="white" /><param name="initParams" value="m=http://silverlight.services.live.com/56373/SilverlightIndependentBuild/video.wmv" /><param name="enableHtmlAccess" value="true" /><param name="minruntimeversion" value="2.0.31005.0" />Your machine either needs Silverlight, or your feed reader does not permit embedded Silverlight content.  Please click-through to the post to view the video.<br />		<a href="http://go.microsoft.com/fwlink/?LinkId=124807" style="text-decoration: none;"><img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a></object><br /><em>6:07, 60MB, HD 720p (<a href="http://silverlight.services.live.com/56373/SilverlightIndependentBuild/video.wmv">Download WMV</a>)</em></p>
<h3>Properties respected by the Silverlight MsBuild targets</h3>
<p>The Silverlight build system respects these build properties that can override the standard SDK locations:</p>
<table border="0" cellspacing="0" cellpadding="2" width="670">
<tbody>
<tr>
<td valign="top" width="335"><strong>Property</strong></td>
<td valign="top" width="335"><strong>Standard value</strong></td>
</tr>
<tr>
<td valign="top" width="335">TargetFrameworkDirectory</td>
<td valign="top" width="335">[Silverlight SDK]\Reference Assemblies\</td>
</tr>
<tr>
<td valign="top" width="335">TargetFrameworkSDKDirectory</td>
<td valign="top" width="335">[Silverlight SDK]\Libraries\Client\</td>
</tr>
<tr>
<td valign="top" width="335">SilverlightRuntimeVersion</td>
<td valign="top" width="335">2.0.31005.0</td>
</tr>
</tbody>
</table>
<p>The runtime version is used when generating the application manifest and HTML test page.</p>
<h3>Preparing your source enlistment</h3>
<p>On the Toolkit, we have a directory of external tools and engineering resources. One of these contains the Silverlight SDK’s assemblies, libraries, and build scripts, as shown in the video.</p>
<ul>
<li>Create a directory to store the MsBuild assets for Silverlight, and copy in the files from %programfiles%MSBuild\Microsoft\Silverlight\v2.0. </li>
<li>Copy the “Reference Assemblies” directory from %programfiles%\Microsoft SDKs\Silverlight\v2.0\ into the tools directory. </li>
<li>Copy the “Libraries” directory from %programfiles%\Microsoft SDKs\Silverlight\v2.0\ into the directory. </li>
</ul>
<p>You can then use relative paths in your projects or custom build targets to get things rolling.</p>
<h3>Updating projects</h3>
<p>Depending on your build system, you’ll want to update your custom targets or project files. In the video I’m simply modifying the .csproj file to add the necessary properties and modify the import statement.</p>
<h4>Add properties</h4>
<p>I’d scroll through the .csproj and insert the new properties right before the Import statement that pulls in the Silverlight build targets. Here are the properties defined; the SilverlightBuildResources property is my own made-up name that I’m using to store the relative path to the new building bits:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:1d721b58-bf73-4637-8135-1f7136b44119" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;PropertyGroup&gt;
    &lt;SilverlightBuildResources&gt;..\Build\&lt;/SilverlightBuildResources&gt;
    &lt;TargetFrameworkDirectory&gt;$(SilverlightBuildResources)Reference Assemblies\&lt;/TargetFrameworkDirectory&gt;
    &lt;TargetFrameworkSDKDirectory&gt;$(SilverlightBuildResources)Libraries\Client\&lt;/TargetFrameworkSDKDirectory&gt;
    &lt;SilverlightRuntimeVersion&gt;2.0.31005.0&lt;/SilverlightRuntimeVersion&gt;
  &lt;/PropertyGroup&gt;</pre>
</div>
<h4>Import the new Silverlight build target</h4>
<p>Silverlight projects import the Silverlight MsBuild targets from the central MsBuild extensions directory, so we just need to update the import to instead come from the source tree:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:21a1f393-b551-49ae-9ae0-e960ab17809f" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;Import Project="$(SilverlightBuildResources)Microsoft.Silverlight.CSharp.targets" /&gt;
  &lt;!--
	This is the default provided for new Silverlight projects:
  &lt;Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" /&gt;
  --&gt;</pre>
</div>
<h4>Build</h4>
<p>You’re all set! And, for future reference: you can use this to build applications targeting multiple versions of Silverlight from the same tree. But more on that later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/01/independent-silverlight-msbuild/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://silverlight.services.live.com/56373/SilverlightIndependentBuild/video.wmv" length="60999705" type="audio/x-ms-wmv" />
		</item>
		<item>
		<title>MergeDefaultStyles build task improves control development (w/source)</title>
		<link>http://www.jeff.wilcox.name/2009/01/default-style-task/</link>
		<comments>http://www.jeff.wilcox.name/2009/01/default-style-task/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 07:17:55 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/?p=247</guid>
		<description><![CDATA[The Silverlight Toolkit team uses a custom MsBuild task called “MergeDefaultStyleTasks” to merge multiple XAML resource dictionaries into generic.xaml. Here’s the details on it, and the source.]]></description>
			<content:encoded><![CDATA[<p>When we first introduced the <a href="http://www.codeplex.com/Silverlight">Silverlight Toolkit</a>, we highlighted our agile, customer feedback-focused, transparent way of working. We talked about our open source model. And we’ve made a commitment to share what we’ve learned while developing the toolkit, whether that is knowledge, guides, blog posts, or sharing code. Today, I offer infrastructure in blog post format!</p>
<p>The task presented here is used (along with others) to help improve developer efficiency, cut down on simple coding mistakes, and specialize a number of functions to automation and tasks. This post is kind of like learning about how sausage is made: this is for power users and control developers who have an interest in geek’n out with this.</p>
<p>This particular post helps improve the development process for controls by letting us separate out the actual styles, so we don’t spend so much time worrying about merge conflicts and diffs.</p>
<h3>Merging resources into generic.xaml</h3>
<p>As recently <a href="http://silverlight.net/forums/t/60635.aspx">noted on the Silverlight.net forums</a>, the source code download for the Silverlight Toolkit sheds some light on an interesting “MergeDefaultStyles” task (and DefaultStyle item type) used to merge all the different control .Xaml files into one build file.</p>
<p>This allows us to bundle several controls in a single library, but not worry about merging source code changes for several templates in a single generic.xaml: TreeView, AutoCompleteBox, and other controls each have their own XAML resource dictionaries that contain their default styles and template: AutoCompleteBox.xaml is merged at build time into the generic.xaml, and so on.</p>
<p>I am assuming that you’re already familiar enough with msbuild to <a href="http://msdn.microsoft.com/en-us/library/t9883dzc.aspx">create your own tasks</a>… here goes. Also, do <a href="http://www.codeplex.com/Silverlight/Release/ProjectReleases.aspx?ReleaseId=19172">download the toolkit source code package</a> – although the package does not include the custom targets to use this task, it does include the individual resource dictionaries used by the controls.</p>
<h3>The MergeDefaultStylesTask</h3>
<p>The task has a few inputs:</p>
<ul>
<li>ProjectDirectory, required; sets the directory of the project where the generic.xaml resides.</li>
<li>DefaultStyles array of ITaskItem’s; represents the items that are marked with the DefaultStyle build action.</li>
</ul>
<p>And the eventual output is the updating of the generic.xaml file.</p>
<p>The task references the typical MsBuild libraries, including Microsoft.Build.Framework, engine, and utilities. In our implementation, we also interact with our Visual Studio Team Foundation Server (TFS): however I’ve stripped that from this example, for simplicity sake, and instead just removed the read-only flag on the generic.xaml file when writing it.</p>
<p>Here’s MergeDefaultStylesTask.cs:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:37153f81-4dc9-4f37-a63c-f528a7a8bc28" class="wlWriterEditableSmartContent">
<pre class="c-sharp" name="code">// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Engineering.Build.Tasks
{
    /// &lt;summary&gt;
    /// Build task to automatically merge the default styles for controls into
    /// a single generic.xaml file.
    /// &lt;/summary&gt;
    public class MergeDefaultStylesTask : Task
    {
        /// &lt;summary&gt;
        /// Gets or sets the root directory of the project where the
        /// generic.xaml file resides.
        /// &lt;/summary&gt;
        [Required]
        public string ProjectDirectory { get; set; }

        /// &lt;summary&gt;
        /// Gets or sets the project items marked with the "DefaultStyle" build
        /// action.
        /// &lt;/summary&gt;
        [Required]
        public ITaskItem[] DefaultStyles { get; set; }

        /// &lt;summary&gt;
        /// Initializes a new instance of the MergeDefaultStylesTask class.
        /// &lt;/summary&gt;
        public MergeDefaultStylesTask()
        {
        }

        /// &lt;summary&gt;
        /// Merge the project items marked with the "DefaultStyle" build action
        /// into a single generic.xaml file.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;
        /// A value indicating whether or not the task succeeded.
        /// &lt;/returns&gt;
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Task should not throw exceptions.")]
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.Low, "Merging default styles into generic.xaml.");

            // Get the original generic.xaml
            string originalPath = Path.Combine(ProjectDirectory, Path.Combine("themes", "generic.xaml"));
            if (!File.Exists(originalPath))
            {
                Log.LogError("{0} does not exist!", originalPath);
                return false;
            }
            Log.LogMessage(MessageImportance.Low, "Found original generic.xaml at {0}.", originalPath);
            string original = null;
            Encoding encoding = Encoding.Default;
            try
            {
                using (StreamReader reader = new StreamReader(File.Open(originalPath, FileMode.Open, FileAccess.Read)))
                {
                    original = reader.ReadToEnd();
                    encoding = reader.CurrentEncoding;
                }
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                return false;
            }

            // Create the merged generic.xaml
            List&lt;DefaultStyle&gt; styles = new List&lt;DefaultStyle&gt;();
            foreach (ITaskItem item in DefaultStyles)
            {
                string path = Path.Combine(ProjectDirectory, item.ItemSpec);
                if (!File.Exists(path))
                {
                    Log.LogWarning("Ignoring missing DefaultStyle {0}.", path);
                    continue;
                }

                try
                {
                    Log.LogMessage(MessageImportance.Low, "Processing file {0}.", item.ItemSpec);
                    styles.Add(DefaultStyle.Load(path));
                }
                catch (Exception ex)
                {
                    Log.LogErrorFromException(ex);
                }
            }
            string merged = null;
            try
            {
                merged = DefaultStyle.Merge(styles).GenerateXaml();
            }
            catch (InvalidOperationException ex)
            {
                Log.LogErrorFromException(ex);
                return false;
            }

            // Write the new generic.xaml
            if (original != merged)
            {
                Log.LogMessage(MessageImportance.Low, "Writing merged generic.xaml.");

                try
                {
                    // Could interact with the source control system / TFS here
                    File.SetAttributes(originalPath, FileAttributes.Normal);
                    Log.LogMessage("Removed any read-only flag for generic.xaml.");

                    File.WriteAllText(originalPath, merged, encoding);
                    Log.LogMessage("Successfully merged generic.xaml.");
                }
                catch (Exception ex)
                {
                    Log.LogErrorFromException(ex);
                    return false;
                }
            }
            else
            {
                Log.LogMessage("Existing generic.xaml was up to date.");
            }

            return true;
        }
    }
}</pre>
</div>
<p>With the task in place, now we just need to add the DefaultStyle implementation and build the task assembly.</p>
<h3>DefaultStyle does the heavy lifting</h3>
<p>The type DefaultStyle is very LINQ-y and uses XLinq to handle parsing XAML, managing namespaces, and also the merging of multiple instances. Here’s DefaultStyle.cs, that should be included in the project (author: Ted Glaza):</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:6fe09b59-adac-4ec2-bea8-14e4a87e50d2" class="wlWriterEditableSmartContent">
<pre class="c-sharp" name="code">// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Linq;

namespace Engineering.Build
{
    /// &lt;summary&gt;
    /// DefaultStyle represents the XAML of an individual Control's default
    /// style (in particular its ControlTemplate) which can be merged with other
    /// default styles).  The XAML must have a ResourceDictionary as its root
    /// element and be marked with a DefaultStyle build action in Visual Studio.
    /// &lt;/summary&gt;
    public partial class DefaultStyle
    {
        /// &lt;summary&gt;
        /// Root element of both the default styles and the merged generic.xaml.
        /// &lt;/summary&gt;
        private const string RootElement = "ResourceDictionary";

        /// &lt;summary&gt;
        /// Gets or sets the file path of the default style.
        /// &lt;/summary&gt;
        public string DefaultStylePath { get; set; }

        /// &lt;summary&gt;
        /// Gets the namespaces imposed on the root element of a default style
        /// (including explicitly declared namespaces as well as those inherited
        /// from the root ResourceDictionary element).
        /// &lt;/summary&gt;
        public SortedDictionary&lt;string, string&gt; Namespaces { get; private set; }

        /// &lt;summary&gt;
        /// Gets the elements in the XAML that include both styles and shared
        /// resources.
        /// &lt;/summary&gt;
        public SortedDictionary&lt;string, XElement&gt; Resources { get; private set; }

        /// &lt;summary&gt;
        /// Gets or sets the history tracking which resources originated from
        /// which files.
        /// &lt;/summary&gt;
        private Dictionary&lt;string, string&gt; MergeHistory { get; set; }

        /// &lt;summary&gt;
        /// Initializes a new instance of the DefaultStyle class.
        /// &lt;/summary&gt;
        protected DefaultStyle()
        {
            Namespaces = new SortedDictionary&lt;string, string&gt;(StringComparer.OrdinalIgnoreCase);
            Resources = new SortedDictionary&lt;string, XElement&gt;(StringComparer.OrdinalIgnoreCase);
            MergeHistory = new Dictionary&lt;string, string&gt;(StringComparer.OrdinalIgnoreCase);
        }

        /// &lt;summary&gt;
        /// Load a DefaultStyle from the a project item.
        /// &lt;/summary&gt;
        /// &lt;param name="path"&gt;
        /// Path of the default style which is used for reporting errors.
        /// &lt;/param&gt;
        /// &lt;returns&gt;The DefaultStyle.&lt;/returns&gt;
        public static DefaultStyle Load(string path)
        {
            DefaultStyle style = new DefaultStyle();
            style.DefaultStylePath = path;

            string xaml = File.ReadAllText(path);
            XElement root = XElement.Parse(xaml, LoadOptions.PreserveWhitespace);
            if (root.Name.LocalName == RootElement)
            {
                // Get the namespaces
                foreach (XAttribute attribute in root.Attributes())
                {
                    if (attribute.Name.LocalName == "xmlns")
                    {
                        style.Namespaces.Add("", attribute.Value);
                    }
                    else if (attribute.Name.NamespaceName == XNamespace.Xmlns.NamespaceName)
                    {
                        style.Namespaces.Add(attribute.Name.LocalName, attribute.Value);
                    }
                }

                // Get the styles and shared resources
                foreach (XElement element in root.Elements())
                {
                    string name = (element.Name.LocalName == "Style") ?
                        GetAttribute(element, "TargetType", "Key", "Name") :
                        GetAttribute(element, "Key", "Name");
                    if (style.Resources.ContainsKey(name))
                    {
                        throw new InvalidOperationException(string.Format(
                            CultureInfo.InvariantCulture,
                            "Resource \"{0}\" is used multiple times in {1} (possibly as a Key, Name, or TargetType)!",
                            name,
                            path));
                    }
                    style.Resources.Add(name, element);
                    style.MergeHistory[name] = path;
                }
            }

            return style;
        }

        /// &lt;summary&gt;
        /// Get the value of the first attribute that is defined.
        /// &lt;/summary&gt;
        /// &lt;param name="element"&gt;Element with the attributes defined.&lt;/param&gt;
        /// &lt;param name="attributes"&gt;
        /// Local names of the attributes to find.
        /// &lt;/param&gt;
        /// &lt;returns&gt;Value of the first attribute found.&lt;/returns&gt;
        private static string GetAttribute(XElement element, params string[] attributes)
        {
            foreach (string name in attributes)
            {
                string value =
                    (from a in element.Attributes()
                     where a.Name.LocalName == name
                     select a.Value)
                     .FirstOrDefault();
                if (name != null)
                {
                    return value;
                }
            }
            return "";
        }

        /// &lt;summary&gt;
        /// Merge a sequence of DefaultStyles into a single style.
        /// &lt;/summary&gt;
        /// &lt;param name="styles"&gt;Sequence of DefaultStyles.&lt;/param&gt;
        /// &lt;returns&gt;Merged DefaultStyle.&lt;/returns&gt;
        public static DefaultStyle Merge(IEnumerable&lt;DefaultStyle&gt; styles)
        {
            DefaultStyle combined = new DefaultStyle();
            if (styles != null)
            {
                foreach (DefaultStyle style in styles)
                {
                    combined.Merge(style);
                }
            }
            return combined;
        }

        /// &lt;summary&gt;
        /// Merge with another DefaultStyle.
        /// &lt;/summary&gt;
        /// &lt;param name="other"&gt;Other DefaultStyle to merge.&lt;/param&gt;
        private void Merge(DefaultStyle other)
        {
            // Merge or lower namespaces
            foreach (KeyValuePair&lt;string, string&gt; ns in other.Namespaces)
            {
                string value = null;
                if (!Namespaces.TryGetValue(ns.Key, out value))
                {
                    Namespaces.Add(ns.Key, ns.Value);
                }
                else if (value != ns.Value)
                {
                    other.LowerNamespace(ns.Key);
                }
            }

            // Merge the resources
            foreach (KeyValuePair&lt;string, XElement&gt; resource in other.Resources)
            {
                if (Resources.ContainsKey(resource.Key))
                {
                    throw new InvalidOperationException(string.Format(
                        CultureInfo.InvariantCulture,
                        "Resource \"{0}\" is used by both {1} and {2}!",
                        resource.Key,
                        MergeHistory[resource.Key],
                        other.DefaultStylePath));
                }
                Resources[resource.Key] = resource.Value;
                MergeHistory[resource.Key] = other.DefaultStylePath;
            }
        }

        /// &lt;summary&gt;
        /// Lower a namespace from the root ResourceDictionary to its child
        /// resources.
        /// &lt;/summary&gt;
        /// &lt;param name="prefix"&gt;Prefix of the namespace to lower.&lt;/param&gt;
        private void LowerNamespace(string prefix)
        {
            // Get the value of the namespace
            string @namespace;
            if (!Namespaces.TryGetValue(prefix, out @namespace))
            {
                return;
            }

            // Push the value into each resource
            foreach (KeyValuePair&lt;string, XElement&gt; resource in Resources)
            {
                // Don't push the value down if it was overridden locally or if
                // it's the default namespace (as it will be lowered
                // automatically)
                if (((from e in resource.Value.Attributes()
                      where e.Name.LocalName == prefix
                      select e).Count() == 0) &#038;&#038;
                    !string.IsNullOrEmpty(prefix))
                {
                    resource.Value.Add(new XAttribute(XName.Get(prefix, XNamespace.Xmlns.NamespaceName), @namespace));
                }
            }
        }

        /// &lt;summary&gt;
        /// Generate the XAML markup for the default style.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;Generated XAML markup.&lt;/returns&gt;
        public string GenerateXaml()
        {
            // Create the ResourceDictionary
            string defaultNamespace = XNamespace.Xml.NamespaceName;
            Namespaces.TryGetValue("", out defaultNamespace);
            XElement resources = new XElement(XName.Get(RootElement, defaultNamespace));

            // Add the shared namespaces
            foreach (KeyValuePair&lt;string, string&gt; @namespace in Namespaces)
            {
                // The default namespace will be added automatically
                if (string.IsNullOrEmpty(@namespace.Key))
                {
                    continue;
                }
                resources.Add(new XAttribute(
                    XName.Get(@namespace.Key, XNamespace.Xmlns.NamespaceName),
                    @namespace.Value));
            }

            // Add the resources
            foreach (KeyValuePair&lt;string, XElement&gt; element in Resources)
            {
                resources.Add(
                    new XText(Environment.NewLine + Environment.NewLine + "    "),
                    new XComment("  " + element.Key + "  "),
                    new XText(Environment.NewLine + "    "),
                    element.Value);
            }

            resources.Add(new XText(Environment.NewLine + Environment.NewLine));

            // Create the document
            XDocument document = new XDocument(
                // TODO: Pull this copyright header from some shared location
                new XComment(Environment.NewLine +
                    "// (c) Copyright Microsoft Corporation." + Environment.NewLine +
                    "// This source is subject to the Microsoft Public License (Ms-PL)." + Environment.NewLine +
                    "// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details." + Environment.NewLine +
                    "// All other rights reserved." + Environment.NewLine),
                new XText(Environment.NewLine + Environment.NewLine),
                new XComment(Environment.NewLine +
                    "// WARNING:" + Environment.NewLine +
                    "// " + Environment.NewLine +
                    "// This XAML was automatically generated by merging the individual default" + Environment.NewLine +
                    "// styles.  Changes to this file may cause incorrect behavior and will be lost" + Environment.NewLine +
                    "// if the XAML is regenerated." + Environment.NewLine),
                new XText(Environment.NewLine + Environment.NewLine),
                resources);

            return document.ToString();
        }

        /// &lt;summary&gt;
        /// Generate the XAML markup for the default style.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;Generated XAML markup.&lt;/returns&gt;
        public override string ToString()
        {
            return GenerateXaml();
        }
    }
}</pre>
</div>
<h3>Reference the task in your project or targets file</h3>
<p>Now, with your task assembly in hand (and available in your source tree), add a UsingTask element to your project.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:8812d69e-1407-4289-a9e2-0099e0da9add" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;!--
  //
  // Define our custom build tasks
  //
  --&gt;
  &lt;UsingTask
    TaskName="Engineering.Build.Tasks.MergeDefaultStylesTask"
    AssemblyFile="$(EngineeringResources)\Engineering.Build.dll" /&gt;</pre>
</div>
<p><strong>Note:</strong> We’ve already defined the EngineeringResources property value elsewhere. You can substitute it with your own relative path as need be.</p>
<p>Next up, add an item group that Visual Studio recognizes to add the DefaultStyle item to the property grid:</p>
<p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:7999d807-b19f-4574-8ae1-4a7b929f9271" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;!-- Add "DefaultStyle" as a Build Action in Visual Studio --&gt;
  &lt;ItemGroup Condition="'$(BuildingInsideVisualStudio)'=='true'"&gt;
    &lt;AvailableItemName Include="DefaultStyle" /&gt;
  &lt;/ItemGroup&gt;</pre>
</div>
<p>Finally, we have two overridden (and custom) targets for merging the default styles, and for “touching” the default styles:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:497fc194-b9b6-4f29-9a74-ec232f9b7051" class="wlWriterEditableSmartContent">
<pre class="xml" name="code">  &lt;!--
  Merge the default styles of controls (only if any of the DefaultStyle files is
  more recent than the project's generic.xaml file) before compilation
  dependencies are processed.
  --&gt;
  &lt;PropertyGroup&gt;
    &lt;PrepareResourcesDependsOn&gt;
      MergeDefaultStyles;
      $(PrepareResourcesDependsOn);
    &lt;/PrepareResourcesDependsOn&gt;
  &lt;/PropertyGroup&gt;
  &lt;Target
    Name="MergeDefaultStyles"
    Inputs="@(DefaultStyle)"
    Outputs="$(MSBuildProjectDirectory)\generic.xaml"&gt;
    &lt;MergeDefaultStylesTask
      DefaultStyles="@(DefaultStyle)"
      ProjectDirectory="$(MSBuildProjectDirectory)" /&gt;
  &lt;/Target&gt;
  &lt;!--
  Touch DefaultStyles on Rebuild to force generation of generic.xaml.
  --&gt;
  &lt;PropertyGroup&gt;
    &lt;RebuildDependsOn&gt;
      TouchDefaultStyles;
      $(RebuildDependsOn);
    &lt;/RebuildDependsOn&gt;
  &lt;/PropertyGroup&gt;
  &lt;Target Name="TouchDefaultStyles"&gt;
    &lt;Touch Files="@(DefaultStyle)" ForceTouch="true" /&gt;
  &lt;/Target&gt;</pre>
</div>
<h3>Use the MergeDefaultStyles task in the project</h3>
<p>Now, you can change the build actions of the appropriate control .Xaml files (that are resource dictionaries) to use this new task:</p>
<p><a href="http://www.jeff.wilcox.name/wp-content/uploads/2009/01/defaultstylebuildaction1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DefaultStyleBuildAction[1]" border="0" alt="DefaultStyleBuildAction[1]" src="http://www.jeff.wilcox.name/wp-content/uploads/2009/01/defaultstylebuildaction1-thumb.png" width="222" height="240" /></a> </p>
<p>When building, you should see the Generic.xaml file update! (Themes\generic.xaml should probably exist before using this task, btw).</p>
<p>This code is offered through the <a href="http://www.opensource.org/licenses/ms-pl.html">Ms-PL license</a>, but no support from the Silverlight Toolkit is implied. Hope this helps you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/01/default-style-task/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
