Determine assembly version during a post-build event

后端 未结 10 1559
故里飘歌
故里飘歌 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:37

    If (1) you don't want to download or create a custom executable that retrieves the assembly version and (2) you don't mind editing the Visual Studio project file, then there is a simple solution that allows you to use a macro which looks like this:

    @(Targets->'%(Version)')

    @(VersionNumber)
    

    To accomplish this, unload your project. If the project somewhere defines a property, cut it from the project and save it elsewhere temporarily (notepad?). Then at the very end of the project, just before the end-tag, place this:

    
      
        
      
      
        
      
    
    
      
        $(PostBuildEventDependsOn);
        PostBuildMacros;
          
      echo HELLO, THE ASSEMBLY VERSION IS: @(VersionNumber)
    
    

    This snippet has an example already in it. No worries, you can reset it to your real post-build event after you have re-loaded the project.

    Now as promised, the assembly version is available to your post build event with this macro:

    @(VersionNumber)
    

    Done!

提交回复
热议问题