根据配置更改程序集名称 (Visual Studio 2005/2008) [英] Change assembly name based on configuration (Visual Studio 2005/2008)

查看:16
本文介绍了根据配置更改程序集名称 (Visual Studio 2005/2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据项目配置更改程序集名称?

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

我在 assemblyinfo.cs 文件上尝试了条件编译指示,但这只会更改程序集属性,而不是名称本身.

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

推荐答案

如果您右键单击您的项目并选择编辑项目文件"(我在 2008 年这里,它可能是一个新选项,如果是然后只需在任何旧文本编辑器中打开项目文件)您应该会看到类似以下内容:

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>

基本上,任何在更具体的属性组中未被覆盖的属性都是从更通用的第一个组继承的.因此,要实现您想要的功能,只需编辑文件,以便在每个特定组中定义 AssemblyName 标记:

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.

这篇关于根据配置更改程序集名称 (Visual Studio 2005/2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆