25

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.

xyz
  • 27,223
  • 29
  • 105
  • 125
  • 2
    See here: http://stackoverflow.com/questions/893003/change-assembly-name-based-on-configuration-visual-studio-2005/893238#893238 – Martin Harris Jul 07 '09 at 16:27

3 Answers3

34

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.

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
  • Curious ... Doesn't Visual Studio already add AssemblyConfiguration then do you a build? – cecilphillip Sep 22 '14 at 14:03
  • 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. – Denise Skidmore Sep 16 '15 at 14:11
  • @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. – adrianbanks Sep 16 '15 at 17:40
11

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.

  • 2
    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. – adrianbanks Jul 08 '09 at 08:52
-1

I'm sure there is, however in my experience having different filenames for debug / release configurations is a bad idea as it can cause all sorts of problems (very much like the issue VS has when it tries to execute the renamed app)

Why not simply indicate whether or not its debug / release in the Assembly attributes (for example in the comments)

Justin
  • 84,773
  • 49
  • 224
  • 367