Kontrollera versionsnummer med MSBuild
Filen med versionsnummer, version.txt i det här fallet, innehåller bara en enkel sträng, till exempel 4.0.2.0. Revisionsnumret i filen uppdateras automatiskt under byggprocessen. Det nya fyrställiga versionsnumret skrivs till alla AssemblyInfo.cs i projekten, de måste checkas ut innan du kör.
Projektfilen batchas eller anropas på kommandoprompten:
MSBuild solution.msbuild /t:BuildSolution /p:Configuration=Release
Projektfilen använder MSBuild Community Tasks för att hantera versionsnummer.
<?xml version="1.0" encoding="utf-8"?>
<!--
================================================
MSBuild project file with version handling.
This project file increases the build revision,
updates the version file, updates all AssemblyInfo.cs
files in all projects, and finally builds the entire
solution.
Note: make sure version.txt and all AssemblyInfo.cs
are checked out before running the build.
Changes:
2006-10-11, Johan Dewe, Created.
================================================
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<SolutionRoot>..</SolutionRoot>
</PropertyGroup>
<ItemGroup>
<ProjectReferences Include="$(SolutionRoot)\TMWebApps.sln" />
<AssemblyInfoFiles Include="$(SolutionRoot)\**\AssemblyInfo.cs" />
</ItemGroup>
<Target Name="BuildSolution">
<!-- Update version number revision -->
<Version VersionFile="version.txt" RevisionType="Increment">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="Revision" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
<!-- Update AssemblyInfo files -->
<FileUpdate
Files='@(AssemblyInfoFiles)'
Regex='(?<ver>assembly: Assembly.*?Version\(")\d+\.\d+\.\d+\.\d+'
ReplacementText='${ver}$(Major).$(Minor).$(Build).$(Revision)' />
<!-- Rebuild projects -->
<MSBuild
Projects="@(ProjectReferences)"
Targets="Rebuild">
<Output TaskParameter="TargetOutputs"
ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
</Target>
</Project>
Technorati tags: development, .net, msbuild
0 Comments:
Skicka en kommentar
Links to this post:
Skapa en länk
<< Home