我有以下项目结构:
- 类库
- 引用 Telerik 控件
- 主持申请
- 引用类库
类库有几个用户控件,其中有 telerik 组件。我有一个主机应用程序,它托管来自类库的这些用户控件。
现在的问题是,尽管在库中引用了 telerik dll,但我仍然必须在我的主机应用程序中引用 telerik dll。否则它会在运行时抛出 XamlParseException
。它编译没有错误。
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Could not load file or assembly 'Telerik.Windows.Controls.GridView, PublicKeyToken=5803cfa389c90ce7' or one of its dependencies. The system cannot find the file specified.
为什么会这样?为什么需要复制 dll。
我正在使用版本为 2015.2.623.45
要重现此问题: 我们可以只用一个用户控件创建一个库
<UserControl>
<Grid>
<telerik:RadGridView></telerik:RadGridView>
</Grid>
</UserControl>
然后创建另一个引用这个类库的项目
<Window>
<Grid>
<wpfApplication1:UserControl1/>
</Grid>
</Window>
并尝试运行它。
(为简洁起见,我省略了 xmlns 定义)
最佳答案
取自以下解决方案:
DLL reference not copying into project bin
A) 添加对您的主机应用程序的引用
B) 在你的类库中添加伪代码,这样编译器就会检测到 正在使用引用,然后将其复制到您的主机应用程序 Bin 文件夹中。
C) 添加构建事件以强制复制 DLL。
仅仅拥有 XAML 代码是不够的,原因是编译器不会评估它以查看您的 XAML 依赖于哪个 DLL。
我现在选择了选项 B,但我更倾向于选项 A) 作为最佳实践。
如果您开始在 C# 中操作您的 telerik 控件,一切都会按预期开始工作。
关于c# - 使用 Telerik 组件正确部署应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376573/