summaryrefslogtreecommitdiffstats
path: root/tools/DotNetOpenAuth.Versioning.targets
blob: 6a4b95a59a6c74573369e48e3997210cac64247f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
	<!-- Import this .targets file to automatically generate AssemblyVersion 
	     attribute according to DotNetOpenAuth convention. -->
	<PropertyGroup>
		<ProjectRoot Condition="'$(ProjectRoot)' == ''">$(MSBuildProjectDirectory)\..\..\</ProjectRoot>
		<VersionCsFile>$(ProjectRoot)obj\$(Configuration)\$(AssemblyName).Version.cs</VersionCsFile>
	</PropertyGroup>

	<PropertyGroup Condition="'$(SignAssembly)' == 'true'">
		<DefineConstants>$(DefineConstants);StrongNameSigned</DefineConstants>
		<DelaySign>true</DelaySign>
		<PublicKeyFile Condition="'$(PublicKeyFile)' == ''">$(ProjectRoot)src\official-build-key.pub</PublicKeyFile>
		<AssemblyOriginatorKeyFile Condition="'$(AssemblyOriginatorKeyFile)' == ''">$(PublicKeyFile)</AssemblyOriginatorKeyFile>
	</PropertyGroup>

	<Import Project="$(ProjectRoot)lib\DotNetOpenAuth.BuildTasks.targets" />
	<UsingTask AssemblyFile="$(ProjectRoot)lib\MSBuild.Community.Tasks.dll" TaskName="AssemblyInfo"/>

	<Target Name="GetBuildVersion">
		<GetBuildVersion VersionFile="$(ProjectRoot)src\version.txt" Condition=" '$(BuildVersion)' == '' ">
			<Output TaskParameter="Version" PropertyName="BuildVersion" />
		</GetBuildVersion>
		<Message Text="Building version $(BuildVersion)"/>
	</Target>
	
	<Target Name="BeforeBuild" DependsOnTargets="GetBuildVersion">
		<PropertyGroup>
			<NewVersionCsFile>$(VersionCsFile).new</NewVersionCsFile>
		</PropertyGroup>
		<MakeDir Directories="$(ProjectRoot)obj\$(Configuration)"/>
		<AssemblyInfo OutputFile="$(NewVersionCsFile)" CodeLanguage="C#" AssemblyVersion="$(BuildVersion)" />
		<!-- Avoid applying the newly generated AssemblyInfo.cs file to the build 
		     unless it has changed in order to allow for incremental building. -->
		<CompareFiles OriginalItems="$(VersionCsFile)" NewItems="$(NewVersionCsFile)">
			<Output TaskParameter="AreChanged" PropertyName="AssemblyInfoChanged" />
		</CompareFiles>
		<Copy Condition=" '$(AssemblyInfoChanged)' == 'true' " SourceFiles="$(NewVersionCsFile)" DestinationFiles="$(VersionCsFile)" />
		<ItemGroup>
			<Compile Include="$(VersionCsFile)" />
		</ItemGroup>
	</Target>
</Project>