I am trying to automatically update the Version element in a .csproj file before the project is compiled so that the outputted dll has that version number.
My requirements:
- Only run on release build
- Only run if project is actually being built (not skipped via incremental build processing)
Currently, I am stuck with the version output to the file being one version behind, as if the compilation/build process read my .csproj before my MSBuild target ran and ignored my updates.
I have the following:
<PropertyGroup>
<VersionPrefix>1.0.20</VersionPrefix>
<VersionSuffix>03412bb</VersionSuffix>
</PropertyGroup>
<Target Name="ReleaseVersion" Condition="'$(Configuration)' == 'Release'" BeforeTargets="BeforeBuild">
<Exec Command="{snip of command that updates/saves VersionPrefix/Suffix of this file}" />
</Target>
Is there a better Target to use for the BeforeTargets value? Is there a way I can execute the command to return information that then sets a variable for msbuild to use when setting the Product version attribute of the generated dll?
Product versionset appropriately. And I am using thedotnet buildcommand via tasks.json. But I that uses MSBuild right?