79705788

Date: 2025-07-18 06:50:02
Score: 1
Natty:
Report link

I've solved the problem with a slightly different approach and without the file Directory.Build.props. The tool, that calculates the version information for a deloyment build now writes a very simple XML file:

<Version>
  <File>25.7.16.17977</File>
  <Assembly>2025.7.3.0</Assembly>
</Version>

In my default targets file (where all the other properties for generating the AssemblyInfo.cs reside) I added a new target:

<Target Name="SetVersion" AfterTargets="BeforeResolveReferences" Condition="Exists('$(SolutionDir)Version.xml')">
  <XmlPeek XmlInputPath="$(SolutionDir)WBVersion.xml" Query="Version/File/text()">
    <Output TaskParameter="Result" ItemName="FileVersion" />
  </XmlPeek>
  <XmlPeek XmlInputPath="$(SolutionDir)WBVersion.xml" Query="Version/Assembly/text()">
    <Output TaskParameter="Result" ItemName="AssemblyVersion" />
  </XmlPeek>
  <Message Importance="High" Text="------ $(ProjectName): Version @(AssemblyVersion) (@(FileVersion))" />
  <PropertyGroup>
    <FileVersion>@(FileVersion)</FileVersion>
    <AssemblyVersion>@(AssemblyVersion)</AssemblyVersion>
    <InformationalVersion>@(AssemblyVersion)</InformationalVersion>
  </PropertyGroup>
</Target>

This target reads the values from the tags <File> and <Assembly> of the XML file with XmlPeek task and the read values will be stored in two items (FileVersion and AssemblyVersion). These two items will be used do define the properties "FileVersion", "AssemblyVersion" and "InformationalVersion". Executing this target directly after "BeforeResolveReferences" does exatcly what I need.

Thanks to all for the answers and comments.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Michael Hartmann