简体   繁体   中英

How to embed the version information in the executable file name when building C# application in Visual Studio?

This question is a complement for the post How to change the output name of an executable built by Visual Studio .

After reading this post I did the following:

  1. Firstly, I followed the answer for this post and I could define the executable file name successfully.

  2. Now, I would like to know if instead of only define the name as "Demo.exe" as mentioned in the example post above, it would be possible to embed the version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute in the built file, resulting in something like "Demo_v1.0.0.0.exe"?

I'm developing my application in C# WinForms, using Visual Studio Express 2017.

Why would you want to change the name of the executable? Whenever you try building a Setup for your application, you need to change the Setup to include the new file. And when you install an update, your Setup needs to know all versions of your executable in order to delete the old version. That's just not what you want to do.

If you want to keep all versions of the software for yourself, come up with a different solution, eg moving the executable into a folder which has the version number.

That said, I have done this for Setups, so customers can download different versions of the Setup. I did that using a commercial tool called Visual Build , but there are other build automation tools available. So, my answer is: set up a continuous integration / continuous delivery pipeline (CI/CD) and automate the step there, not in Visual Studio.

From the project properties, you can add Post build event command line to rename your exe

后期构建事件

pseudo

  1. Maybe you can create another console renamer.exe which reads version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute of your app and renames it and then call that renamer.exe from Post build event command line
  2. write a powershell script to rename the newly built exe and call that script from Post build event command line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM