views:

823

answers:

1

Is it possible to change the assembly name based on the project configuration?

I have tried conditional pragmas on the assemblyinfo.cs file, but that only changes the assembly attributes, not the name itself.

+7  A: 

If you right click on your project and choose "Edit Project File" (I'm in 2008 here and it may be a new option, if it is then just open the project file in any old text editor) you should see something similar to the following:

  <PropertyGroup>
    ...
    <AssemblyName>ClassLibrary1</AssemblyName>
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    ...
  </PropertyGroup>

Basically any properties that aren't overriden in a more specific property group are inherited from the more general, first group. So to achieve what you want just edit the file so that the AssemblyName tag is defined in each of the specific groups:

  <PropertyGroup>
    ...
    <AssemblyName>ClassLibrary1</AssemblyName>
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    ...
    <AssemblyName>ClassLibrary1Debug</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    ...
    <AssemblyName>ClassLibrary1Release</AssemblyName>
  </PropertyGroup>

This will change the assembly name on a per config basis.

Martin Harris
Thanks, Martin. The "Edit Project File" context option looks to be connected to this addon: http://code.msdn.microsoft.com/PowerCommands
frou
Works very well! I wish the Visual Studio 2005 interface had allowed this directly.
Rob Hunter
Curiously the C++ interface has a very powerful system for things like this (property sheets), and UI that makes it doable even if tricky. I really miss property sheets in C#...
romkyns