【问题标题】:Adding Project as Reference results in Cannot load file or assembly or one of its dependencies添加项目作为参考导致无法加载文件或程序集或其依赖项之一
【发布时间】:2013-10-07 14:39:28
【问题描述】:

我在 Visual Studio 2012 中有一个包含多个项目的解决方案。我正在尝试将一个项目添加到另一个项目作为参考以便能够一起使用它们,但我无法弄清楚为什么添加此项目参考会导致部署/运行时缺少 DLL(下面的FusionLog)。我以前使用过这种方法没有这个问题,所以我一定是在这里遗漏了一些东西......

解决方案配置:

主项目:Bootstrapper
子项目:BootstrapperCustom
我正在尝试添加作为参考的项目:LicenseCheckBootstrapperCustom
部署时缺少 DLL:LicenseCheck.dll

[Bootstrapper]
--Installer: Configuration: N/A, Platform: N/A
--Build: Configuration: Active (Debug), Platform: Active (x86)
--Ref:
----[BootstrapperCustom]

[BootstrapperCustom]
--Application: Configuration: N/A, Platform: N/A, Target framework: .NET 4.5, Output type: Class library
--Build: Configuration: Active (Debug), Platform: Active (Any CPU), Platform target: Any CPU
--Ref:
----[BootstrapperCore] (Copy Local: True)
----[LicenseCheck] (Copy Local: True)
----[Microsoft.Deployment.WindowsInstaller] (Copy Local: True)
----[Microsoft.Practices.Prism] (Copy Local: True)

[LicenseCheck]
--Application: Configuration: N/A, Platform: N/A, Target framework: .NET 4.5, Output type: Class library
--Build: Configuration: Active (Debug), Platform: Active (x86), Platform target: Any CPU
--Ref:
----[Microsoft.Deployment.WindowsInstaller] (Copy Local: True)
----[Parse] (Copy Local: True)

错误信息:

Run Bootstrapper.exe = `Could not load file or assembly 'LicenseCheck, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.`

FusionLog(已确认 LicenseCheck.dll 缺失):

[%TEMP%\{x}\.ba1]
--BootstrapperCore.dll
--BootstrapperCustom.dll
--Microsoft.Practices.Prism.dll

=== Pre-bind state information ===
LOG: User = NOTTHOR\dirt
LOG: DisplayName = LicenseCheck, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Users/dirt/AppData/Local/Temp/{94ef2c32-a419-410e-a8a0-df404f022ff7}/.ba1/
LOG: Initial PrivatePath = NULL
Calling assembly : BootstrapperCustom, Version=1.0.5028.16514, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\dirt\AppData\Local\Temp\{94ef2c32-a419-410e-a8a0-df404f022ff7}\.ba1\BootstrapperCore.config
LOG: Using host configuration file: C:\Users\dirt\AppData\Local\Temp\{94ef2c32-a419-410e-a8a0-df404f022ff7}\.ba1\BootstrapperCore.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/dirt/AppData/Local/Temp/{94ef2c32-a419-410e-a8a0-df404f022ff7}/.ba1/LicenseCheck.DLL.
LOG: Attempting download of new URL file:///C:/Users/dirt/AppData/Local/Temp/{94ef2c32-a419-410e-a8a0-df404f022ff7}/.ba1/LicenseCheck/LicenseCheck.DLL.
LOG: Attempting download of new URL file:///C:/Users/dirt/AppData/Local/Temp/{94ef2c32-a419-410e-a8a0-df404f022ff7}/.ba1/LicenseCheck.EXE.
LOG: Attempting download of new URL file:///C:/Users/dirt/AppData/Local/Temp/{94ef2c32-a419-410e-a8a0-df404f022ff7}/.ba1/LicenseCheck/LicenseCheck.EXE.

注意:当我重建 BootstrapperCustom 项目时,我确实看到在 Bootstrapper\bin\Debug 中生成了 LicenseCheck.dll。

【问题讨论】:

    标签: c# visual-studio-2012 dll wix fusion


    【解决方案1】:

    您是否尝试查看您引用的项目是否使用 LicenseCheck dll 文件,但实际上没有引用? (例如:您引用的项目可能在初始化期间动态加载 dll)。

    如果是这种情况,您可以添加构建步骤以将 dll 复制到输出文件夹(例如,请参阅 Copying files into the application folder at compile time

    【讨论】:

      【解决方案2】:

      原来这是主项目(WiX Bootstrapper)配置中的内容。我未能在 BootstrapperApplication 的有效负载列表中包含 LicenseCheck.dll。

      添加到 Bootstrapper\Bundle.wxs:

      <Payload SourceFile="$(var.BootstrapperCustom.TargetDir)LicenseCheck.dll" />

      【讨论】:

        【解决方案3】:

        在您的解决方案资源管理器中,右键单击并重建该项目。 查看 dll 是否在 Windows 资源管理器中重新生成。 要让它工作,只需将 dll 从该项目复制到您的主项目 bin 文件夹。它应该工作。 这是启动和运行的最坏情况

        【讨论】:

        • 问题在注释中明确指出,文件是在重建时生成的。
        【解决方案4】:

        我知道这不是你的答案,但我带着同样的错误信息来到这里,寻找寻找什么的灵感。事实证明,我引用的项目是一个比我的主项目更新的目标框架。

        【讨论】:

          猜你喜欢
          • 2021-12-12
          • 2012-01-14
          • 1970-01-01
          相关资源
          最近更新 更多