无法使用 ILMerge 加载 DLL mscorsn.dll

Unable to load DLL mscorsn.dll with ILMerge

我正在尝试编译一个项目,该项目使用 ILMerge 将多个 DLL 组合在一起,然后对它们进行签名以部署到 CRM。代码已编译,但 ILMerge 失败。此过程适用于其他开发人员的机器,但不适用于我的机器。

我正在使用 Visual Studio 2015,Windows 10,并针对 .NET 4.5.2 进行构建。

所有项目都使用 AnyCPU 编译。

Resolved assembly reference 'System.Runtime.Caching' to 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319..\v4.0.30319\System.Runtime.Caching.dll'. (Used framework directory.)

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)

我的 Post-build 事件参数是:

if "$(ConfigurationName)" == "Debug No ILMerge" goto :exit REM **** Create ILMerge Directory **** md "$(TargetDir)IlMerge" REM **** Delete Previous Log **** del "$(TargetDir)IlMerge\Log.txt" REM **** Run IlMerge **** "$(SolutionDir)packages\ILMerge.2.14.1208\tools\ILMerge.exe" /log:"$(TargetDir)IlMerge\Log.txt" /keyfile:"$(ProjectDir)Client.Xrm.Plugins.Key.snk" /targetplatform:v4 /out:"$(TargetDir)IlMerge$(TargetFileName)" "$(TargetPath)" "$(TargetDir)DLaB.Common.dll" "$(TargetDir)DLaB.Xrm.2015.dll" "$(TargetDir)Client.Xrm.dll" "$(TargetDir)Applications.Web.Security.dll" "$(TargetDir).Domain.dll" "$(TargetDir)Newtonsoft.Json.dll" :exit

我可以在我的计算机上手动找到 mscorsn.dll 并将其放入本地文件夹。 ILMerge 选择了它,但取决于我使用的版本(Windows 中有 4-5 个不同的副本),它要么彻底失败,要么声明它无法签署最终的 dll。

我曾尝试将 targetplatform 指向具有 mscorsn.dll 文件的特定 .NET 文件夹,但无济于事。

我找到了答案。 ILMerge 似乎需要 .NET 3.5,但默认情况下 Windows 8、8.1 或 10 上不存在。安装 .NET 3.5 后,ILMerge 完美运行。

  • 程序和功能 ->
  • 打开或关闭 Windows 功能 ->
  • .NET Framework 3.5(包括 .NET 2.0 和 3.0)