【发布时间】:2022-01-27 06:47:16
【问题描述】:
我的 Visual Studio 项目中有当前文件结构:
- 我的项目/
- 我的启动项目/
- 斌/
- 调试/
- Program.cs
- 斌/
- 依赖项目/
- bin/
- dll/
- MyAssembly.dll
- 代码.cs
- 我的启动项目/
我的Main() 函数在MyProject/MyStartupProject/Program.cs 中。在Code.cs 里面有一行var assembly = Assembly.Load("MyAssembly");,它应该加载MyProject/DependencyProject/dlls/MyAssembly.dll,但是却导致了错误
System.IO.FileNotFoundException: 'Could not load file or assembly 'MyAssembly' or one of its dependencies.
The system cannot find the file specified.'
但是,如果我将 MyAssembly.dll 复制到 MyProject/MyStartupProject/bin/Debug 中,一切都会运行良好。如何修复此引用,以便项目可以在 dlls 目录下找到它?
【问题讨论】:
-
您需要将其添加为项目资源,然后将其复制到配置文件中
-
如何将其添加为项目资源? @Jazb
-
构建系统不知道你对这个DLL有依赖,所以不会为你复制它。你have to help。或者使用 LoadFrom() 而不是 Load()。或者只是使用项目引用并在代码中使用程序集中的类型。
-
很高兴知道您找到了解决此问题的解决方案!请考虑接受它作为答案以将其状态更改为已回答。它还将帮助其他人解决类似的问题。见can I answer my own question..,只是一个提醒:)
标签: c# visual-studio dll .net-assembly