Merge branch 'v3.4'
[dotnetopenid.git] / tools / DotNetOpenAuth.Versioning.targets
blobcbcb76da650b60cb86b313efb165348352f78c83
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
3         <!-- Import this .targets file to automatically generate AssemblyVersion 
4              attribute according to DotNetOpenAuth convention. 
5              This file assumes DotNetOpenAuth.props and DotNetOpenAuth.targets are also imported. -->
6         <PropertyGroup>
7                 <VersionCsFile>$(IntermediatePath)\$(AssemblyName).Version.cs</VersionCsFile>
8                 <NoWarn>$(NoWarn);1607</NoWarn>
9         </PropertyGroup>
11         <UsingTask AssemblyFile="$(ProjectRoot)lib\MSBuild.Community.Tasks.dll" TaskName="AssemblyInfo"/>
13         <Target Name="GetBuildVersion">
14                 <GetBuildVersion Condition=" '$(BuildVersion)' == '' "
15                                  VersionFile="$(ProjectRoot)src\version.txt"
16                                  GitRepoRoot="$(ProjectRoot)">
17                         <Output TaskParameter="Version" PropertyName="BuildVersion" />
18                         <Output TaskParameter="SimpleVersion" PropertyName="BuildVersionSimple" />
19                         <Output TaskParameter="GitCommitId" PropertyName="AssemblyInformationalVersion" />
20                 </GetBuildVersion>
21                 <PropertyGroup>
22                         <!-- In TeamCity, the build agent doesn't get the .git directory, but the commit id is available by other means. -->
23                         <AssemblyInformationalVersion Condition=" '$(AssemblyInformationalVersion)' == '' ">$(BUILD_VCS_NUMBER)</AssemblyInformationalVersion>
24                 </PropertyGroup>
25                 <Warning Condition=" '$(AssemblyInformationalVersion)' == '' " Text="Unable to determine the git HEAD commit ID to use for informational version number." />
26                 <Message Condition=" '$(AssemblyInformationalVersion)' != '' " Text="Building version $(BuildVersion) from commit $(AssemblyInformationalVersion)"/>
27                 <Message Condition=" '$(AssemblyInformationalVersion)' == '' " Text="Building version $(BuildVersion)"/>
28         </Target>
30         <Target Name="BeforeBuild" DependsOnTargets="GetBuildVersion">
31                 <PropertyGroup>
32                         <NewVersionCsFile>$(VersionCsFile).new</NewVersionCsFile>
33                 </PropertyGroup>
34                 <MakeDir Directories="$(IntermediatePath)"/>
35                 <AssemblyInfo OutputFile="$(NewVersionCsFile)" CodeLanguage="C#"
36                               AssemblyVersion="$(BuildVersion)"
37                               AssemblyInformationalVersion="$(AssemblyInformationalVersion)" />
38                 <!-- Avoid applying the newly generated AssemblyInfo.cs file to the build 
39                      unless it has changed in order to allow for incremental building. -->
40                 <CompareFiles OriginalItems="$(VersionCsFile)" NewItems="$(NewVersionCsFile)">
41                         <Output TaskParameter="AreChanged" PropertyName="AssemblyInfoChanged" />
42                 </CompareFiles>
43                 <Copy Condition=" '$(AssemblyInfoChanged)' == 'true' " SourceFiles="$(NewVersionCsFile)" DestinationFiles="$(VersionCsFile)" />
44                 <ItemGroup>
45                         <Compile Include="$(VersionCsFile)" />
46                 </ItemGroup>
47         </Target>
48 </Project>