GlobalAssemblyInfo.cs and strong name

I have a GlobalAssemblyInfo.cs file at the root of my solution, and I have something like the following entry to include a strong name for my output assemblies.

#pragma warning disable 1699 [assembly : AssemblyKeyFile("..\\keyfile.snk")] #pragma warning restore 1699 

This approach has two drawbacks. First, AssemblyKeyFileAttribute is deprecated, so to avoid compilation warnings, I need the pragma lines you see above. Secondly, I need to either keep all my projects at the same depth relative to the root in order to use the relative path, or use the absolute path that dictates the scan location on the computers of other users (and on the continuous integration servers / build agents).

Does anyone have a better solution besides this, except that each project sets a strong naming convention in the project file?

+7
c # configuration-management
source share
3 answers

These attributes for signing keys were deprecated for a good reason (information leak), which is another reason for moving along the project route.

If you have many projects, you can probably install them using a recorded macro or even directly manipulate .csproj files (make sure they are first downloaded from VS).

+1
source share

Well, to avoid a path issue, you can use [assembly:AssemblyKeyName(...)] instead (although IIRC is also deprecated); use sn -i to set the named key. Each machine (which builds) needs to add this key.

Besides; Yes, you may have to edit project files.

+2
source share

Richard makes a good conclusion about information leakage - now I have found messages from the Microsoft.NET team where they describe it. So I went for his suggestion and came up with the following NAnt goal:

  <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> 

The <namespaces> element is required to enable XPath in the csproj file - note that this is for VS2008, and something slightly different may be required in VS2005.

+1
source share

All Articles