我在具有管理员权限的 cmd 上使用以下命令:
ILMerge.exe /wildcards /log:ILMerge.log /allowdup
/targetplatform:"v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319"
/lib:"C:\SDK2016\SDK2016\Bin"
/lib:"packages\Microsoft.CrmSdk.Extensions.7.1.0.1\lib\net45"
/lib:"packages\log4net.2.0.5\lib\net45-full"
/keyfile:"Tools\Snk\XXX.snk"
/out:"c:\XXXALLMERGED.dll"
"c:\proj\alldlls\*.dll"
我在日志文件末尾收到以下错误:
An exception occurred during merging:
Unable to load DLL 'mscorsn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at System.Compiler.Writer.MscorsnStrongNameSignatureGeneration(String wszFilePath, String wszKeyContainer, Byte[] pbKeyBlob, Int32 cbKeyBlob, IntPtr ppbSignatureBlob, IntPtr pcbSignatureBlob)
at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
at ILMerging.ILMerge.Merge()
at ILMerging.ILMerge.Main(String[] args)
由于我的 targetframework 是 v4 并且我的文件夹是“v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319”,所以我检查了 mscorsn.dll 是否存在;它存在。
那么,可能是什么问题?你能帮忙吗?
最佳答案
我遇到了同样的问题并设法解决了。
最初我生成了一个 .PFX 文件以在 Visual Studio 中对我的程序集进行签名(使用项目属性窗口中的“签名”选项卡)。然后,我将 .PFX 文件中的公钥提取到 .SNK 文件中(使用 sn.exe)。
当我尝试使用 ILMerge.exe 并使用生成的 .SNK 文件时,我会得到 "Unable to load DLL 'mscorsn.dll'"
错误。
我通过删除 .PFX 和生成的 .SNK 文件来修复它。 然后我生成了一个新的 .SNK 文件,如下所示(在 VS 中):
- 项目属性 > 签名
- 选择强名称 key 文件:
<New>
- 指定 .SNK 文件的文件名。
- 取消选中“使用密码保护我的 key 文件”<这似乎成功了。
这会生成一个新的 .SNK 文件,当我将该文件与 ILMerge 一起使用时,错误消失了。
HTH
关于.net - 使用 ILMerge 时无法加载 mscorsn.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36217595/