visual-studio 根据配置更改程序集名称 (Visual Studio 2005/2008)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/893003/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change assembly name based on configuration (Visual Studio 2005/2008)
提问by Rob Hunter
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.
我在 assemblyinfo.cs 文件上尝试了条件编译指示,但这只会更改程序集属性,而不是名称本身。
回答by Martin Harris
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:
如果您右键单击您的项目并选择“编辑项目文件”(我在 2008 年在这里,它可能是一个新选项,如果是然后只需在任何旧的文本编辑器中打开项目文件),您应该看到类似于下列:
  <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:
基本上,在更具体的属性组中没有被覆盖的任何属性都是从更一般的第一组继承的。因此,要实现您想要的功能,只需编辑文件,以便在每个特定组中定义 AssemblyName 标记:
  <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.
这将根据每个配置更改程序集名称。

