Including MSBuild.ExtensionPack.VersionNumber.targets

Feb 22, 2011 at 9:17 AM

Hi,

we are using MSBuild Extension Pack December 2010.
The .targets file we customized with our special settings (autoincrement build/revision numbers,...).
For a single test project we included this block to our .csproj file and all works fine.

<Import Project="...MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.VersionNumber.targets"/>
<Target Name="BeforeCompile" Condition="...">
    <CreateItem Include="$(SolutionDir)\**\AssemblyInfo.*">
        <Output ItemName="AssemblyInfoFiles" TaskParameter="Include" />
    </CreateItem>
    <Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>
<Target Name="AfterCompile" Condition="...">
    <Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>
<Target Name="BeforeOnBuildBreak" Condition="...">
    <Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>


For our main team project (about 30 solution files with 240 project files) we have a problem:

We have to deploy this data to the whole project.

Is there an easy way to do this - without editing all 240 project files?

Thanks for any ideas!

 

Mar 1, 2011 at 3:29 PM

Hi,

In order to avoid editing every .target file you may implement the following trick:

1. Create one or both files:
C:\Program Files\MSBuild\v3.5\Custom.Before.Microsoft.Common.targets:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildProjectFullPath).before.targets" Condition="Exists('$(MSBuildProjectFullPath).before.targets')"/>
</Project>


C:\Program Files\MSBuild\v3.5\Custom.After.Microsoft.Common.targets:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildProjectFullPath).after.targets" Condition="Exists('$(MSBuildProjectFullPath).after.targets')"/>
</Project>

(you may be need to adjust path according to .NET framework version)

2. Create file MyVersion.targets:

<Import Project="...MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.VersionNumber.targets"/>
<Target Name="BeforeCompile" Condition="...">
    <CreateItem Include="$(SolutionDir)\**\AssemblyInfo.*">
        <Output ItemName="AssemblyInfoFiles" TaskParameter="Include" />
    </CreateItem>
    <Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>
<Target Name="AfterCompile" Condition="...">
    <Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>
<Target Name="BeforeOnBuildBreak" Condition="...">
    <Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>

3. Afterwards you may create file with name
<project>.after.targets aside you <project> file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="...\MyVersion.targets" Condition="Exists('...\MyVersion.targets"/>
</Project>

This will lead to importing of your custom targets in all projects that have <project>.after.targets defined without much editing hassle.

Mar 4, 2011 at 7:07 AM

Hi,

thank you very much for your answer.

Your solution is excellent, but also a lot of work.

So we wrote a short C# program for changing AssemblyFileVersion values and call it in our target.

Together with checkin/checkout command we have 3 lines which do the whole work.

Best regards

Von: levt [email removed]
Gesendet: Dienstag, 1. März 2011 16:29
An: Krause, Reinhard
Betreff: Re: Including MSBuild.ExtensionPack.VersionNumber.targets [MSBuildExtensionPack:247032]

From: levt

Hi,

In order to avoid editing every .target file you may implement the following trick:

1. Create one or both files:
C:\Program Files\MSBuild\v3.5\Custom.Before.Microsoft.Common.targets:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildProjectFullPath).before.targets" Condition="Exists('$(MSBuildProjectFullPath).before.targets')"/>
</Project>


C:\Program Files\MSBuild\v3.5\Custom.After.Microsoft.Common.targets:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildProjectFullPath).after.targets" Condition="Exists('$(MSBuildProjectFullPath).after.targets')"/>
</Project>

(you may be need to adjust path according to .NET framework version)

2. Create file MyVersion.targets:

<Import Project="...MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.VersionNumber.targets"/>
<Target Name="BeforeCompile" Condition="...">
<CreateItem Include="$(SolutionDir)\**\AssemblyInfo.*">
<Output ItemName="AssemblyInfoFiles" TaskParameter="Include" />
</CreateItem>
<Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>
<Target Name="AfterCompile" Condition="...">
<Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>
<Target Name="BeforeOnBuildBreak" Condition="...">
<Exec WorkingDirectory="$(SolutionDir)" Command="..." />
</Target>

3. Afterwards you may create file with name
<project>.after.targets aside you <project> file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="...\MyVersion.targets" Condition="Exists('...\MyVersion.targets"/>
</Project>

This will lead to importing of your custom targets in all projects that have <project>.after.targets defined without much editing hassle.

May 17, 2013 at 4:20 AM
Can you please tell me which line exactly modifies the assemblyinfo file?
Since i am trying to build with the flow you explained here but version is not getting updated in the versioninfo file and checkin is happeneing without modification.

Steps following:
  1. Added import tag
  2. Aded code to checkout the file using script
<Exec WorkingDirectory="$(SolutionRoot)"
      Command="$(TF) checkout /recursive $(AssemblyInfoSpec)"/>
  1. Added code to checkin the file if successful
<Exec WorkingDirectory="$(SolutionRoot)"
  Command="$(TF) checkin /comment:&quot;Auto-Build: Version Update&quot; /noprompt /override:&quot;Auto-Build: Version Update&quot; /recursive "/>
  1. Undo the file is failure.
<Exec WorkingDirectory="$(SolutionRoot)"
      Command="$(TF) undo /noprompt /recursive $(AssemblyInfoSpec)"/>
Thanks in advance.
May 17, 2013 at 6:42 AM
Hi,
a special Tool ChangeFileVersionInfo with up to 5 parameters was developed to change the version infos according to our special in-house version info settings.
The call is like <Exec WorkingDirectory="$(BuiltDir)" Command="".\ChangeFileVersionInfos.exe" "$(BuiltDir)" param1 param2 param3" /> and is placed between checkout and checkin commands.
Marked as answer by mikeFourie on 10/15/2013 at 12:17 AM
May 17, 2013 at 6:47 AM
Where can i get the exe and i dont want to generate the version by user. I want Assemblyinfotask to update the Assemblyinfo file and i would like to kno whow exactly I can do that?