部署C# ReportViewer遇到的坑

前些天临时给客户做个工具,统计具体时间点各种车型数据的数量及比重,为了显示方便就用C#来做,因为它有现成的reportviwer控件提供了显示,打印,导出功能。原本我以为这个控件是.netframework里的,做完后直接就发给客户了。但昨天客户打电话来说工具打不开,我一看系统日志,是一个未能加载microsoft.ReportViewer.Winforms库的错误,于是我就把项目中自动引用的Microsoft.ReportViewer.Winforms和Microsoft.ReportViewer.Common一并拷过去,软件是能正常打开了,但是在呈现报表是崩溃。

后来折腾了两个小时,终于搞明白了。ReportViewer不是.netframework提供了,而是visual studio提供的组件,它依赖如下组件:

  • Microsoft.ReportViewer.Winforms.dll
  • Microsoft.ReportViewer.Common.dll
  • Microsoft.ReportViewer.ProcessingObjectModel.dll
  • Microsoft.ReportViewer.DataVisualization.dll
  • Microsoft.SqlServer.Types.dll
  • Microsoft.ReportViewer.WinForms.resources.dll
  • Microsoft.ReportViewer.DataVisualization.resources.dll

只要将这些组件拷到exe目录就行了,去哪里获取呢?可以去微软官网下载reportviewer.exe安装,也可以在自己开发环境下手动找到这些库。下面介绍的是手动找的:

1、可在visual studio的目录/ReportViewer下找到Microsoft.ReportViewer.Winforms.dll和Microsoft.ReportViewer.WinForms.resources.dll,Microsoft.ReportViewer.WinForms.resources.dll是一个文本资源库,有许多语言版本,选择其中一个版本就行了,如zh-CHS.

2、其它的库可以在windows的库全局缓存目录(C:WindowsassemblyGAC_MSIL)里找到,直接用资源管理器进去是不能拷贝的,需要用shell进去用cp指令拷贝.注意库的版本。

原文地址:https://www.cnblogs.com/zxtceq/p/8302390.html