即时创建我的程序集的签名副本

Create a signed copy of my assembly on the fly

我需要即时制作我的程序集的签名副本。

我尝试通过在 post-build 事件中添加此脚本来做到这一点:

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

但是,当我引用已签名的程序集时,出现运行时异常 "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."

我试过使用反射器从 MyAssemblySignedVersion.dll 创建一个项目,但它没有编译,因为缺少一些名称空间,这可能是重新组装反汇编的 dll 的结果。这可能相关吗?

我怎样才能完成这项工作? 提前致谢。

我找到了制作程序集签名副本的方法:我创建了新的解决方案配置:"ReleaseSigned",并且在 post-build 事件中我放置了这个脚本:

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

随后进行此 post 更改: same project different solution sign configuration