VS2008 - Outputting a different file name for Debug/Release configurations

13,678

Solution 1

You can achieve this by editing your project file by hand. Locate the <AssemblyName> node and add a conditional attribute to it:

<AssemblyName Condition="'$(Configuration)'=='Debug'">MyApp_Debug.exe</AssemblyName>
<AssemblyName Condition="'$(Configuration)'=='Release'">MyApp_Release.exe</AssemblyName>

You'll have to duplicate it also to add another conditional attribute for the release version.

Whilst it is possible, it may cause problems. There is an AssemblyConfiguration attribute that can be applied to your assembly. In AssemblyInfo.cs, put:

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

This will add a property to your compiled assembly that will tell you which build configuration your application was built using.

Solution 2

As adrianbanks mentioned, you can edit your .csproj file by hand to accomplish this.

I would, however reccomend the simpler form of:

<AssemblyName>MyApp_$(Configuration).exe</AssemblyName>

If you ever edit the properties of this project however, this change will very likely be lost. It's something you will have to manually stay on top of, as it's not going to be a supported setup.

To manually edit your project definition, right click the project in Visual Studio, and select "Unload", then right click the unloaded project, and select "Edit" and it will open the XML definition for you.

Share:
13,678

Related videos on Youtube

xyz
Author by

xyz

Updated on April 19, 2022

Comments

  • xyz
    xyz about 2 years

    When building a C# application with Visual Studio 2008, is it possible to set a different output filename per configuration?

    e.g.
    
    MyApp_Debug.exe
    MyApp_Release.exe
    

    I tried a post-build step to rename the file by appending the current configuration, but that seems a scrappy approach. Plus it meant that Visual Studio could no longer find the file when pressing F5 to start debugging.

  • adrianbanks
    adrianbanks almost 15 years
    That's the problem with all of the possible solutions. Visual Studio does not let you edit the project file to include the full capabilities of MSBuild. Any change you make has to be managed outside of Visual Studio. At least with this change you can see it's effect in Visual Studio.
  • cecilphillip
    cecilphillip almost 10 years
    Curious ... Doesn't Visual Studio already add AssemblyConfiguration then do you a build?
  • Denise Skidmore
    Denise Skidmore almost 9 years
    I didn't have to add the manual AssemblyConfiguration lines to make this work. AssemblyInfo.cs uses [assembly: AssemblyConfiguration("")] I did however have to move the AssemblyName statements into existing property groups with conditions rather than putting conditions directly on AssemblyName.
  • adrianbanks
    adrianbanks almost 9 years
    @DeniseSkidmore: It's not clear from my original answer, but those are two alternatives to achieve the same result. Personally, I prefer the code-only apporach.