问题描述
我有引用 ProjectB(ClassLibrary) 的 ProjectA(WPFApplication).在 ProjectB 我有 wpf 窗口,它使用来自 ThirdParty.dll 的控件,我相应地从 ProjectB 引用.
I have ProjectA(WPFApplication) that references ProjectB(ClassLibrary). Inside ProjectB i have wpf window that uses control from ThirdParty.dll wich i accordingly reference from ProjectB.
问题是它在 ProjectA 的输出文件夹中找不到 ThirdParty.dll 并且引发了 xaml 解析运行时异常.GAC 中没有ThirdParty.dll.本地复制设置为 true.如果我手动添加该库的 ProjectA 的输出文件夹,它就可以工作,如果我在我的 cs 文件中的某个地方使用该 ThirdParty.dll ,它也可以工作.
The problem is that it doesn't find ThirdParty.dll in output folder of ProjectA and xaml parse runtime exceprion is raised. There is no ThirdParty.dll in GAC. Copy Locally is set to true. It works if i manually add in output folder of ProjectA that library and it also works if i use that ThirdParty.dll somwhere right in my cs files.
我该如何解决?
推荐答案
这是因为Visual Studio只有在设置了Copy Local的情况下才会将资源复制到输出文件夹.只需将引用设置为 Copy Local 就可以了.
The reason for this is that visual studio only copies resources to the output folder if Copy Local is set. Just set the reference to Copy Local and you should be fine.
查看此链接关于这是如何工作的.
Check out this link on how this works.
当您引用 ProjectA 时,不会自动引用来自 ProjectB 的引用.为此,如果您只在 XAML 中使用它,您还需要从 ProjectA 添加对 ThirdParty.dll 的引用.编译器不会复制仅在 XAML 中使用的引用.但如果你在代码中使用它们,它们就会被复制.
When you reference ProjectA, the references from ProjectB is not automatically referenced. For this to work, you need to add a reference to ThirdParty.dll from ProjectA as well if you only use it in XAML. The compiler does not copy references that are only used in XAML. But if you use them in code, they are copied.
这与讨论的问题相同这里
这篇关于未复制引用的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!