Michael,

        Here's what I have found.  First of all, NUnit will load
strong-named assemblies just fine, the problem your are describing
occurs when the assemblies are delay-signed and the signing process has
not been completed.  These partially signed assemblies fail to load
because they actually have invalid signatures.  You have two options
here.  Your first option is to complete the signing process using the
<delay-sign> task.  Your second option is to disable assembly
verification using the sn utility.  The choice of which option to use is
based mostly on access to the private key.  Option #1 is the better
option since you will have to do this before deploying your assemblies
into a production environment.  However, you may not have access to the
private key, which is necessary to complete the signing.  If you do have
access go with option #1, otherwise go with option #2.  Here are the
details for both.

Here is the relevant portion of my AssemblyInfo.cs:

#if (STRONG_NAME)
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile(@"my.public.snk")]
#else
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
#endif

Here is the target I use to strong name:

<target name="strong.name" depends="" description="Strong names the
implementation assemblies with the appropriate key.">
  <if test="${project.config != 'release'}">
    <fail message="Only release builds will be strong named." />
  </if>
  <delay-sign keycontainer='${key.container}' verbose="false">
    <targets refid="implementation.assemblies" />
  </delay-sign>
</target>

Here are the targets I use to disable/enable assembly verification:

<property name="key.token"                      value="XXXXXXXXXXXXXXXX"
/>

<target name="disable.verification" description="This target disables
strong name verification for .NET Commons assemblies.">
  <exec 
 
basedir="${framework::get-sdk-directory(framework::get-target-framework(
))}"
    program="sn.exe" 
    commandline='-q -Vr *,${key.token}'
    failonerror="false"
    verbose="true" />
  <echo message="Strong name verifcation is now disabled for all .NET
Commons assemblies."/>
  <echo message="Be sure to re-enable verification as soon as
possible."/>
</target>

<target name="enable.verification" description="This target enables
strong name verification for .NET Commons assemblies.">
  <exec 
 
basedir="${framework::get-sdk-directory(framework::get-target-framework(
))}" 
    program="sn.exe" 
    commandline='-q -Vu *,${key.token}'
    failonerror="false"
    verbose="true" />
</target>

You can find you public key token (a 16 digit hexadecimal number) by
executing 'sn -t my.public.snk'.  Assuming the public portion of your
key pair is stored in 'my.public.snk'

Good Luck,
Tom

---------
Date: Wed, 9 Mar 2005 20:56:51 -0800 (PST)
From: Michael Dang <[EMAIL PROTECTED]>
To: nant-users@lists.sourceforge.net
Subject: [Nant-users] Strong name assembly example scripts?

Hi All,

Does anyone have sample scripts or things they have done with strong
naming assemblies?

I have a number of assemblies that are strong named by using the
asminfo task and compiling.  However, when trying to Nunit test these
by dynamically loading assemblies with info from a config file they
fail becuase the public key and version info is different.  How can I
test these assemblies and by updating the config file with the
correct version and publickey info?

Maybe there is another suggestion that I am not thinking of.  Any 
help?

thanks



Michael Dang




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Nant-users mailing list
Nant-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to