Gáspár Nagy on software

coach, trainer and bdd addict, creator of SpecFlow; owner of Spec Solutions

Building Windows Phone 7 Applications on build server without installing the SDK

by Gáspár on March 29, 2011

I don’t like installing SDKs on build servers, especially ones that are relative new and gets updated frequently. In the new SpecFlow release, we provide support for WP7. In order to build this on our build server, I had to solve this problem. Here are my findings.

I have based my work on the post of Jeff Wilcox. The solution for WP7 is almost the same as he describes, but there is a small trick.

So I have created the following folders in the project’s lib collection:

  • lib\Silverlight\v4.0\Reference Assemblies – with the content of “C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0”, except the Profile folder. This can be also reused for normal SL4 projects.
  • lib\Silverlight for Phone\v7.0\MSBuild – with the content of “C:\Program Files (x86)\MSBuild\Microsoft\Silverlight for Phone\v4.0”.
  • lib\Silverlight for Phone\v7.0\Libraries – with the content of “C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Libraries\Silverlight”.
  • lib\Silverlight for Phone\v7.0\Reference Assemblies – with the content of “C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone”.

Unfortunately there is a special step in the WP7 Microsoft.Silverlight.Common.targets file that sets the reference paths without any condition. Because of this, you cannot specify the paths explicitly. I have duplicated this target (GetFrameworkPaths) and decorated it with a condition. This I’ve saved to a separate targets file inside lib\Silverlight for Phone\v7.0\MSBuild called Microsoft.Silverlight.Common.OverridesForBuild.targets. You can download the entire file from here, but the actual change is really just a condition:

<PropertyGroup 
Condition="'$(UseCustomWindowsPhoneSDKFolder)'!='true'">
<_FullFrameworkReferenceAssemblyPaths>
<TargetFrameworkDirectory>
PropertyGroup>

After this preparation, you can change your project file to use the dependencies from the lib folder. For this you need to open the project file in an XML editor and change the Import sections to the following:

<PropertyGroup>
<WindowsPhoneBuildResources>..\lib\Silverlight for Phone\v7.0WindowsPhoneBuildResources>
<SilverlightBuildResources>..\lib\Silverlight\v4.0SilverlightBuildResources>
<TargetFrameworkDirectory>$(WindowsPhoneBuildResources)\Reference AssembliesTargetFrameworkDirectory>
<TargetFrameworkSDKDirectory>$(WindowsPhoneBuildResources)\LibrariesTargetFrameworkSDKDirectory>
<_FullFrameworkReferenceAssemblyPaths>$(SilverlightBuildResources)\Reference Assemblies_FullFrameworkReferenceAssemblyPaths>
<UseCustomWindowsPhoneSDKFolder>trueUseCustomWindowsPhoneSDKFolder>
<SilverlightRuntimeVersion>4.0SilverlightRuntimeVersion>
PropertyGroup>
<Import Project="$(WindowsPhoneBuildResources)\MSBuild\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(WindowsPhoneBuildResources)\MSBuild\Microsoft.Silverlight.CSharp.targets" />
<Import Project="$(WindowsPhoneBuildResources)\MSBuild\Microsoft.Silverlight.Common.OverridesForBuild.targets" />

You might need to change the lib folder reference in the first two properties according to your setup.

With these I was able to build our solution on the build server.

3 thoughts on “Building Windows Phone 7 Applications on build server without installing the SDK