views:

961

answers:

5

In Visual Studio 2008 (and others) when creating a .NET or silverlight application if you look at your project properties, it seems like you can only have one assembly name - across all configurations. I would like to compile my application as:

MyAppDebug - in debug mode and just MyApp - in release mode

Does anyone know if this is possible?

Edit:

It seems some people are questioning the reasoning behind the question, so I'll explain a little further:

I'm working on a Silverlight application which gets automatically uploaded to our test site when I to a "build solution". The trouble is, the test team are now testing the online version, whilst I work on a new one. So, I want to have a url like .\MyApp.html for the regular version that the QA team will test and then .\MyApp.html?version=debug for the current version that I'm working on.

A: 

I'm sure you could add a post build step that renames the assembly

Michael Prewecki
+2  A: 

Sure you can add a post-build event to rename the assembly. This will work if your solution has only one assembly.

But if your solution consists of several projects, you normally have one project referencing the assembly generated by another problem. Imagine your solution has has two projets: the first one creates a Windows Forms exe (MyApp.EXE), which references the assembly created by the second project (MyData.DLL).

In this example the debug EXE would be named MyAppDebug.EXE, and it needs to reference MyDataDebug.EXE. And this will not work with renaming in a post-build event.

Therefore I strongly recommend not to do any renaming.

nruessmann
There's another problem with post-build renaming: you lose a lot of the debugger integration. You basically have to run the program yourself and then attach the debugger.
romkyns
+1  A: 

If you absolutely have your heart set on doing this, then you could do something like this in your AssemblyInfo.cs file:

#if DEBUG
[assembly: AssemblyTitle("MyAssemblyDebug")]
#else
[assembly: AssemblyTitle("MyAssembly")]
#endif

However, this is pretty much a hack. Also, the MSDN documentation is pretty clear that the filename is not even considered when loading an assembly so doing a simple rename is not going to change the overall identity of your assembly.

As mentioned above this is generally going to be a bad idea as it will only introduce confusion, and issues with maintenance. If all you do is rename the files by doing a post build operation:

rename "$(ProjectDir)bin\Debug\SomeAssembly.dll" SomeAssemblyDebug.dll

Then you haven't really changed the identity of your assembly only the file name. You could name it Bob.dll and it will still have the same identity as far as the CLR is concerned. The only time this matters is when you are using a strongly named assembly that is going to be deployed to the GAC. In that case you can't have a different file name from the assembly name.

If you are truly trying to rename the assembly name, and not just the filename, then you have another issue on your hand because it is now a totally different assembly to the CLR.

I think you are better off to live with the standards that are already in place. If you find yourself having to do something really weird perhaps you should ask yourself why it is you are trying to do this. There may be a better solution.

Josh
A: 

I've managed to achieve what I was after by using a post-build script:

if "$(ConfigurationName)"=="Debug" goto debug
"$(SolutionDir)ftp.bat" "$(TargetDir)$(TargetName).xap"
:debug
"$(SolutionDir)ftp.bat" "$(TargetDir)$(TargetName).xap" "$(TargetDir)$(TargetName)Debug.xap"

My ftp script basically accepts an optional parameter at the end which is what to upload the file as. So on my local machine the filenames are always the same, but in debug mode we upload it with "Debug" at the end of the filename. Now I can choose in my webpage which version to show.

Mark Ingram
+1  A: 

I've done this by messing with the .csproj file: either move the attribute into the configuration-specific property groups, or just use Condition. Example:

<AssemblyName>MyApp</AssemblyName>
<AssemblyName Condition=" '$(Configuration)' == 'Debug' ">MyAppDebug</AssemblyName>

Visual Studio becomes somewhat crippled when you start messing with .csproj like this - for example I can no longer F5/F10 to run the project in Debug mode; it tells me that "MyApp.exe" was not found (i.e. the debugger attempts to launch the assembly with the wrong AssemblyName).

romkyns