How to sign the assembly?

Topics: For MSBee Users
Aug 16, 2006 at 7:49 PM
migrated from power toy forums
originally posted by Bill Henning
------------------------------------------------------

I've gotten an MSBuild process now working with both .NET 2.0 and .NET 1.1 (using MSBee) versions of my assembly. However according to the MSBee C# targets file, it doesn't support strong name key files:

<!-- These properties only apply to csc 2.0 and are filtered for the csc task above.
Thus, if you set these flags in the VS 2005 IDE, they will be ignored when targeting
.NET 1.1. You can uncomment these properties and add them to the csc task if you wish.
You will then receive a warning or error if you set these properties because csc 1.1
won't recognize the corresponding switches.
-->

<!--
DelaySign="$(DelaySign)"
KeyContainer="$(KeyContainer)"
KeyFile="$(KeyFile)"

So my question is, how can I sign my MSBee .NET 1.1 assembly with a strong name? I need the assemblies to be placed in the GAC.

Thanks in advance!
Bill
Aug 16, 2006 at 7:49 PM
originally posted by Craig Lichtenstein - MSFT
------------------------------------------------------

Right now, your best bet may be to do it as a post build event using signcode.exe, which comes with the 1.0 and 1.1 SDK.

Our plan for this sprint does include reviewing and, if necessary, reimplementing the MSBuild SignFile task which lets you sign files using certificates.
Aug 16, 2006 at 7:49 PM
originally posted by Craig Lichtenstein - MSFT
------------------------------------------------------

Please disregard my previous reply since I was discussing authenticode signing and you asked about strong name signing.

A workaround you can try is to use the AssemblyDelaySignAttribute attribute in your AssemblyInfo file. There are also attributes for AssemblyKeyFileAttribute (to specify a .snk file) and AssemblyKeyNameAttribute (to identify the key container). You can read more about these here. Note that the attribute approach produces a compiler warning if the assembly is built using csc 2.0.

Alternatively, since Al.exe can perform strong name signing, you may be able to use the MSBee AL task.
Aug 16, 2006 at 7:49 PM
originally posted by Bill Henning
------------------------------------------------------

I added the AssemblyKeyFile attribute in a conditional #if for .NET 1.1 code. That seemed to work.

It would be a lot cleaner though if you could just read the MSBuild .NET 2.0 KeyFile property and do whatever needs to be done to get it working that way.

Nevertheless, great product guys.
Aug 16, 2006 at 7:49 PM
originally posted by Colin Bowern
------------------------------------------------------

This brings up a great point though. I ended up hacking the .targets file to add a preprocessor directive (http://geekswithblogs.net/colinbo/archive/2006/03/12/72138.aspx). Can this be made a standard part of MSBee? Seems like a quick win.

Thanks,
Colin
Aug 16, 2006 at 7:50 PM
originally posted by Craig Lichtenstein - MSFT
------------------------------------------------------

This is a good idea and we may be able to fit it in this sprint. In the meantime, you may find it helpful to open a suggestion in BugTracker on the MSBee home page. This will allow you, along with other project members, to track the status of your suggestion.

To do this, go to http://go.microsoft.com/fwlink/?LinkId=59384 and click on the "Bug Tracker" link on the left pane. This will take you to the BugTracker home page for MSBee. If you click on the "Manage bug" link in the left pane, you can add a new bug to the MSBee bug tracker.

If you get an error that your request can't be processed, then that means you need to become a project member. In that case, you can go back to the MSBee project homepage and click on "Apply to join this project" link on the right. Once you've become a project member, try submitting the suggestion again.
Aug 16, 2006 at 7:50 PM
originally posted by Colin Bowern
------------------------------------------------------

Done