blog:2024-01-31_c_build_execution_file_with_version_number_name
2024-01-31 C#: Build Execution File Name with Version Number
Method
Close the project
Edit the project.csproj by text editor and append this code piece on the end of XML file </project> tage
<Target Name="PostBuildMacros">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="Targets" />
</GetAssemblyIdentity>
<ItemGroup>
<VersionNumber Include="@(Targets->'%(Version)')" />
</ItemGroup>
</Target>
<PropertyGroup>
<PostBuildEventDependsOn>
$(PostBuildEventDependsOn);
PostBuildMacros;
</PostBuildEventDependsOn>
<PostBuildEvent>echo The Assembly Version is: @(VersionNumber)
copy /Y "$(TargetDir)$(TargetFileName)" "$(TargetDir)$(TargetName)_@(VersionNumber).exe"
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>del /q "$(TargetDir)$(TargetName)_*.exe"</PreBuildEvent>
</PropertyGroup>
-
This snippet has an example <PostBuildEvent> already in it. No worries, you can reset it to your real post-build event after you have re-loaded the project.
Now, the assembly version is available to your post-build event with this macro:
@(VersionNumber)
Reopen the project with Visual Studio, then you can get it
Reference
-
-
-
Link - Determine assembly version during a post-build event (stack overflow)
Link - Renaming project output in visual studio using post build event generates error (stack overflow)
Link - Visual Studio 專案建置完成後取得組件版本號並輸出在文字檔中
Permalink blog/2024-01-31_c_build_execution_file_with_version_number_name.txt · Last modified: 2024/01/31 15:02 by
jethro