Create a signed copy of my assembly on the fly

190 views Asked by At

I need to make a signed copy of my assembly on the fly.

I've tried to do so by adding this script in the post-build event:

call "$(DevEnvDir)..\Tools\vsvars32.bat"
ildasm /all /out=MyAssemblySignedVersion.il $(TargetFileName)
ilasm /dll /key=MyAssembly.snk MyAssemblySignedVersion.il

However, when I reference the signed assembly, I get a runtime exception "Could not load file or assembly 'MyAssembly, Version=1.2.5511.31417, Culture=neutral, PublicKeyToken=b025765091e877ec' or one of its dependencies. The system cannot find the file specified."

I've tried using reflector to create a project from the MyAssemblySignedVersion.dll, and it doesn't compile because some of the namespaces are missing, possibly as a result of the reassembling of the disassembled dll. Could this be related?

How can I make this work? Thanks a lot in advance.

1

There are 1 answers

0
Shani On BEST ANSWER

I've found a way to make signed copy of my assembly: I've created new solution configuration: "ReleaseSigned", and in the post-build event I put this script:

if $(ConfigurationName) == Debug (
     echo "Building in DEBUG. Skipping signing..."
) else if $(ConfigurationName) == ReleaseSigned (
call "$(DevEnvDir)..\Tools\vsvars32.bat"
     msbuild.exe "$(ProjectPath)" /property:Configuration=Release
)

Followed by this post changes: same project different solution sign configuration