Determine assembly version during a post-build event

后端 未结 10 1635
故里飘歌
故里飘歌 2020-11-27 11:58

Let\'s say I wanted to create a static text file which ships with each release. I want the file to be updated with the version number of the release (as specified in A

10条回答
  •  广开言路
    2020-11-27 12:30

    I looked for the same feature and i found the solution on MSDN. https://social.msdn.microsoft.com/Forums/vstudio/de-DE/e9485c92-98e7-4874-9310-720957fea677/assembly-version-in-post-build-event?forum=msbuild

    $(ApplicationVersion) did the Job for me.

    Edit:

    Okay I just saw the Problem $(ApplicationVersion) is not from AssemblyInfo.cs, its the PublishVersion defined in the project Properties. It still does the job for me in a simple way. So maybe someone needs it too.

    Another Solution:

    You can call a PowerShell script on PostBuild, here you can read the AssemblyVersion directly from your Assembly. I call the script with the TargetDir as Parameter

    PostBuild Command:

    PowerShell -ExecutionPolicy Unrestricted $(ProjectDir)\somescript.ps1 -TargetDir $(TargetDir)
    

    PowerShell Script:

    param(
        [string]$TargetDir
    )
    
    $Version = (Get-Command ${TargetDir}Example.exe).FileVersionInfo.FileVersion
    

    This way you will get the Version from the AssemblyInfo.cs

提交回复
热议问题