Search code examples
c#visual-studioversionfilenames.net-assembly

Include version number in exe file name in C# Visual Studio desktop application


I looked everywhere for a solution, and I think that it's impossible to do that !

Can I include the version number (that is in AssemblyInfo.cs) into the .exe filename ? So I don't have anymore to rename the output exe file every release build.

I just posted this question to be sure that in fact, it is impossible to do that. Otherwise, if someone has a working solution I'll be happy to know it. Thank you

EDIT

I'm not searching how to get the assembly version, which I can find, but I'm looking for how to include that version automatically into my .exe output file name


Solution

  • I made it !

    Thanks to Stinky Towel for that helpful comment. I had to modify the script to make it run under my configuration, and as you can see I worked with wmic instead of filever which I couldn't find on Windows 10. Here is my script that worked fine:

    `@echo off
    set filepath=%1
    set filename=%2
    set dblslash=%filepath:\=\\%
    
    FOR /F "tokens=2 delims==" %%I IN (
      'wmic datafile where "name='%dblslash%'" get version /format:list'
    ) DO SET "AssemblyVersion=%%I"
    ECHO %AssemblyVersion%
    move /Y %filepath% %filename%_%AssemblyVersion%.exe`