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)" />
</Target>



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">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>
<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)" />
</Target>


Job done!


No comments: