C# GlobalAssemblyInfo.cs和强命名

C# GlobalAssemblyInfo.cs和强命名,c#,.net,configuration-management,C#,.net,Configuration Management,在我的解决方案的根目录中有一个GlobalAssemblyInfo.cs文件,其中有类似于以下条目的内容,可以对输出程序集进行强命名 #pragma warning disable 1699 [assembly : AssemblyKeyFile("..\\keyfile.snk")] #pragma warning restore 1699 这种方法有两个缺点。首先,不推荐使用AssemblyKeyFileAttribute,因此为了避免编译警告,我需要上面看到的pragma行。其次,我需要

在我的解决方案的根目录中有一个GlobalAssemblyInfo.cs文件,其中有类似于以下条目的内容,可以对输出程序集进行强命名

#pragma warning disable 1699
[assembly : AssemblyKeyFile("..\\keyfile.snk")]
#pragma warning restore 1699
这种方法有两个缺点。首先,不推荐使用AssemblyKeyFileAttribute,因此为了避免编译警告,我需要上面看到的pragma行。其次,我需要将所有项目保持在相对于根的相同深度,以使用相对路径,或者使用绝对路径,它指示其他用户机器(以及持续集成服务器/构建代理)上的签出位置


除了在项目文件中设置强命名外,还有谁有比这更好的解决方案吗?

为了避免路径问题,您可以使用
[assembly:AssemblyKeyName(…)]
(尽管IIRC也不推荐使用);使用
sn-i
安装命名密钥。每台机器(进行构建)都需要添加此密钥


除此之外,;是的,您可能需要编辑项目文件。

密钥签名的这些属性被弃用是有充分理由的(信息泄漏),这是执行项目路线的另一个原因


如果你有很多项目,可以通过录制的宏来设置它们,甚至可以直接操作.csproj文件(确保先从VS中卸载它们)。

Richard对信息泄漏提出了一个很好的观点-我现在找到了Microsoft的.NET团队的帖子,他们在其中描述了这一点。因此,我采纳了他的建议,并提出了以下NAnt目标:

  <target name="strongName" description="Strong names the output DLLs">
    <foreach item="File" property="filename">
      <in>
        <items>
          <include name="**/*.csproj"></include>
          <exclude name="**/*.Test.csproj"></include>
        </items>
      </in>
      <do>
        <echo message="${filename}" />
        <xmlpoke file="${filename}" xpath="/m:Project/m:PropertyGroup/m:SignAssembly" value="false">
          <namespaces>
            <namespace prefix="m" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
          </namespaces>
        </xmlpoke>
        <xmlpoke file="${filename}" xpath="/m:Project/m:PropertyGroup/m:AssemblyOriginatorKeyFile" value="..\keyfile.snk">
          <namespaces>
            <namespace prefix="m" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
          </namespaces>
        </xmlpoke>
      </do>
    </foreach>
  </target>


元素是在csproj文件中解析XPath所必需的-请注意,这是针对VS2008的,在VS2005中可能需要一些稍微不同的内容。

同意,这就解决了第二个问题。