Friday, 20 April 2012

Getting the current framework SDK path from within MS Build

In LeaveWizard we currently use Linq To Sql and to generate a data context we use SqlMetal as part of the pre-build process of our data access assembly, the xml looks something like this:

 <Target Name="BeforeBuild">
<Exec Command="&quot;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SqlMetal.exe&quot; /server:.\HEATHERSQL01 /Database:LeaveWizard_UnitTests /code:LeaveWizardDataContext.cs /context:LeaveWizardDataContext /namespace:FeatureBase.LeaveWizard.DataAccess /views /sprocs /functions /pluralize /timeout:1200" WorkingDirectory="$(ProjectDir)" />

As you can see the path to the SDK version number was being hard coded, which has been fine for a long time until I configured a brand new build server which did not have v6.0a of the SDK installed it had v7.1, so I needed a solution.

Thankfully it seems easy enough to do this, simply get the current framework SDK path location like so:

  <Target Name="BeforeBuild">
<Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
<Exec Command="&quot;$(WindowsSdkPath)bin\SqlMetal.exe&quot; /server:.\HEATHERSQL01 /Database:LeaveWizard_UnitTests /code:LeaveWizardDataContext.cs /context:LeaveWizardDataContext /namespace:FeatureBase.LeaveWizard.DataAccess /views /sprocs /functions /pluralize /timeout:1200" WorkingDirectory="$(ProjectDir)" />

Job done!

No comments: