views:

844

answers:

4

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.

+7  A: 

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
+1  A: 

You can set it in Project -> Properties. Different names will depend whether you're under Debug or Release setting of the build (change the status to set different names). You can also set different output folder under -> Build, Output section. Notice it is the Project properties you want, not the Solution one.

EDIT: Nop, I was wrong. As Martin mentioned you can't set the configuration section for the Application tab. Only change the output folder through the Build tab.

Tamar
Are you sure about this? For me the Configuration dropdown is greyed out on the Application tab (where you can set the assembly name). I'd be interested to know how to turn it on though, if that's possible.
Martin Harris
Sorry about this, I remembered setting it this way but now I can't figure out how :) I'll edit my answer.
Tamar
A: 

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)

Kragen
+2  A: 

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.

Christopher Karper
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