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.
An assembly qualified name is the internal name of the assembly, combained with the Assebly Version, Culture, and public Key: these cobination make it unique. An assembly's name is stored in metadata and has a significant impact on the assembly's scope and use by an application.
visual studio change assembly name * Right-click the project again and select Properties. Change the "Assembly name" and "Default namespace" on the Application tab. * Right-click the project again and select Refactor -> Adjust Namespaces. Accept the changes.
The assembly identity, which consists of the assembly name, version, culture, and strong name, must be clear to the runtime. For example, if you have an assembly called myAssembly.exe that references an assembly called myAssembly. dll, binding occurs correctly if you execute myAssembly.exe.
Open Visual Studio Go to Tools –> External Tools –> Add Title: Get Qualified Assembly Name Command: Powershell.exe Arguments: -command "[System. Reflection. AssemblyName]::GetAssemblyName(\"$(TargetPath)\"). FullName" Check "Use Output Window".
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With