将项目添加为引用会导致“无法加载文件或程序集或其某个依赖项”的错误。

3

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

解决方案配置:

主项目:Bootstrapper
子项目:BootstrapperCustom
我试图将其作为引用添加到BootstrapperCustom的项目:LicenseCheck
部署时缺少的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。

4个回答

1

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

如果是这种情况,您可以添加一个构建步骤将dll复制到输出文件夹中(例如,请参见在编译时将文件复制到应用程序文件夹中)。


0

我知道这不是你想要的答案,但我也曾因同样的错误信息而来到这里,寻找灵感以确定问题所在。最终发现,我的引用项目比主项目的目标框架更新。


0
原来这是主项目(WiX Bootstrapper)配置中的问题。我忘记在BootstrapperApplication的Payload列表中包含LicenseCheck.dll。
在Bootstrapper\Bundle.wxs中添加: <Payload SourceFile="$(var.BootstrapperCustom.TargetDir)LicenseCheck.dll" />

0
在你的解决方案资源管理器中,右键单击并重新生成该项目。查看dll文件是否在Windows资源管理器中重新生成。要使其正常工作,只需将该项目中的dll文件复制到主项目的bin文件夹中。它应该可以工作了。这是最坏的情况下为了让程序基本运行而采取的措施。

问题明确指出在重新生成时正在生成文件。 - Maverik

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接