Skip to content

Commit

Permalink
Automatic AssemblyFileVersion and zip file naming based on 'git descr…
Browse files Browse the repository at this point in the history
…ibe'.
  • Loading branch information
enyim committed Aug 12, 2010
1 parent ffed5eb commit f53b1e7
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Enyim.Caching/Enyim.Caching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<GitTagMatch>emc*</GitTagMatch>
</PropertyGroup>
<Import Project="..\VersionInfo.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
3 changes: 2 additions & 1 deletion Enyim.Caching/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
[assembly: Guid("a8cd3f39-7731-4ee8-a7ce-444d540d4a4d")]

[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
// generated by the build script
//[assembly: AssemblyFileVersion("2.3.0.0")]

#if SIGN
[assembly: AssemblyKeyName("enyim")]
Expand Down
4 changes: 4 additions & 0 deletions Northscale.Store/Northscale.Store.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<GitTagMatch>ns*</GitTagMatch>
</PropertyGroup>
<Import Project="..\VersionInfo.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
3 changes: 2 additions & 1 deletion Northscale.Store/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
[assembly: Guid("8460330E-5027-4e2c-AA84-FC8539780160")]

[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.0.0")]
// generated by the build script
//[assembly: AssemblyFileVersion("2.4.0.0")]

#if SIGN
[assembly: AssemblyKeyName("enyim")]
Expand Down
31 changes: 31 additions & 0 deletions VersionInfo.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BeforeBuild" Condition=" $(Configuration) == 'Release' " DependsOnTargets="CreateAssemblyInfo;IncludeGeneratedAssemblyInfo">

</Target>

<PropertyGroup>
<GeneratedAssemblyInfo>obj\$(Configuration)\.assemblyinfo</GeneratedAssemblyInfo>
<GitDescribe>obj\$(Configuration)\.describe</GitDescribe>
<GitTagMatch Condition=" '$(GitTagMatch)' == '' ">*</GitTagMatch>
</PropertyGroup>

<Target Name="CreateAssemblyInfo">

<MakeDir Directories="obj\$(Configuration)" />

<Exec Command="git describe --tags --match $(GitTagMatch) > $(GitDescribe)" />
<ReadLinesFromFile File="$(GitDescribe)">
<Output TaskParameter="Lines" PropertyName="_AssemblyFileVersion"/>
</ReadLinesFromFile>

<Delete Files="$(GeneratedAssemblyInfo)" />
<WriteLinesToFile File="$(GeneratedAssemblyInfo)" Lines="[assembly: System.Reflection.AssemblyFileVersion(&quot;$(_AssemblyFileVersion)&quot;)]" />
</Target>

<Target Name="IncludeGeneratedAssemblyInfo">
<CreateItem Include="$(GeneratedAssemblyInfo)">
<Output TaskParameter="Include" ItemName="Compile"/>
</CreateItem>
</Target>

</Project>
40 changes: 30 additions & 10 deletions build-release.msbuild
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

<UsingTask TaskName="GetFileVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<AssemblyPath ParameterType="System.String" Required="true" />
<FileVersion ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Reflection" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var a = Assembly.LoadFrom(AssemblyPath);
var afv = Attribute.GetCustomAttribute(a, typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute;

FileVersion = afv == null ? "NULL" : afv.Version;
]]>
</Code>
</Task>
</UsingTask>

<Target Name="BeforeBuild">
<RemoveDir Directories="Enyim.Caching\bin;Enyim.Caching\obj;NorthScale.Store\bin;NorthScale.Store\obj" ContinueOnError="true" />
</Target>

<Target Name="Compile" DependsOnTargets="BeforeBuild">
<MSBuild Projects="Enyim.Caching\Enyim.Caching.csproj" Targets="Rebuild" Properties="Configuration=Release;DefineConstants=SIGN=true" />
<MSBuild Projects="NorthScale.Store\NorthScale.Store.csproj" Targets="Rebuild" Properties="Configuration=Release;DefineConstants=SIGN=true" />
<MSBuild Projects="NorthScale.Store\NorthScale.Store.csproj" Targets="Rebuild" Properties="Configuration=Release;" />
</Target>

<Target Name="PrepareFiles">
Expand All @@ -18,12 +37,12 @@
</Target>

<Target Name="Pack">
<GetAssemblyIdentity AssemblyFiles="Enyim.Caching\bin\Release\Enyim.Caching.dll">
<Output TaskParameter="Assemblies" ItemName="EnyimCachingInfo" />
</GetAssemblyIdentity>
<GetAssemblyIdentity AssemblyFiles="NorthScale.Store\bin\Release\NorthScale.Store.dll">
<Output TaskParameter="Assemblies" ItemName="NorthScaleStoreInfo" />
</GetAssemblyIdentity>
<GetFileVersion AssemblyPath="Enyim.Caching\bin\Release\Enyim.Caching.dll">
<Output TaskParameter="FileVersion" PropertyName="EnyimCachingVersion" />
</GetFileVersion>
<GetFileVersion AssemblyPath="NorthScale.Store\bin\Release\NorthScale.Store.dll">
<Output TaskParameter="FileVersion" PropertyName="NorthScaleStoreVersion" />
</GetFileVersion>

<CreateItem Include="Enyim.Caching\bin\Release\**\*.*">
<Output ItemName="EnyimItems" TaskParameter="Include" />
Expand All @@ -32,11 +51,12 @@
<Output ItemName="NorthScaleItems" TaskParameter="Include" />
</CreateItem>

<Zip Files="@(EnyimItems)" ZipFileName="Enyim.Caching.$([System.Text.RegularExpressions.regex]::Replace(%(EnyimCachingInfo.Version), `\.\d+\.\d+$`, ``)).zip" ZipLevel="9" Flatten="true" />
<Zip Files="@(NorthScaleItems)" ZipFileName="NorthScale.Store.$([System.Text.RegularExpressions.regex]::Replace(%(NorthScaleStoreInfo.Version), `\.\d+\.\d+$`, ``)).zip" ZipLevel="9" Flatten="true" />
<Zip Files="@(EnyimItems)" ZipFileName="Enyim.Caching.$([System.Text.RegularExpressions.Regex]::Replace($(EnyimCachingVersion), `^([^0-9]+)`, ``)).zip" ZipLevel="9" Flatten="true" />
<Zip Files="@(NorthScaleItems)" ZipFileName="NorthScale.Store.$([System.Text.RegularExpressions.Regex]::Replace($(NorthScaleStoreVersion), `^([^0-9]+)`, ``)).zip" ZipLevel="9" Flatten="true" />
</Target>

<Target Name="Build" DependsOnTargets="Compile;PrepareFiles;Pack"></Target>
<Target Name="Build" DependsOnTargets="Compile;PrepareFiles;Pack">
</Target>
</Project>
<!--
/* ************************************************************
Expand Down

0 comments on commit f53b1e7

Please sign in to comment.