Visual Studio 2017 RC中缺少Reportviewer工具

38

我刚开始使用名为Visual Studio 2017 RC的新版本编写报表软件,但发现在Windows Forms和WPF应用程序模板中都缺少核心报表查看工具。有人能告诉我为什么报表查看器工具在Visual Studio 2017中消失了吗?没有它真的很困扰。在新的Visual Studio中是否有任何替代方法来处理此工具?

5个回答

71

**更新**: 2019年11月19日

微软在他们的Nuget库中发布了控件150.1400.0的新版本。我的简短测试显示,它再次在表单设计器中工作,而150.1357.0150.1358.0则没有。这包括能够调整大小和修改报表查看器任务。

**更新**: 2019年8月18日

将最新版本删除并回滚到150.900.148.0似乎在我使用VS2017和VS2019的多台计算机上都有效。

您可以在Nuget解决方案包管理器中回滚到150.900.148。它的使用方式类似于以前的版本。使用下拉框选择旧版本即可。

enter image description here

手动删除对 ReportViewer 版本为 150.900 的引用并重新添加它们可能比修复它们更容易。

记得在更改工具箱条目后重新启动 Visual Studio。

更新: 2019年8月7日

新版本的 ReportViewer 控件已发布,可能与 Visual Studio 2019 同步。我正在使用 V150.1358.0。

按照此答案中的说明可以将控件放入设计器的工具箱中。但是一旦放置在表单上,控件就不会显示。该控件显示为非可视组件,出现在表单下方。

根据 Microsoft SQL BI 支持团队的说法,这是按设计进行的操作。该团队负责该控件。

虽然您仍然无法直接与该控件交互,但这些附加步骤提供了一种解决方法,使该控件可以在表单上调整大小。虽然现在可见,但设计器将该控件视为不存在。

我已根据 Microsoft SQL BI 支持团队的建议创建了一个反馈请求。请考虑投票以引起 Microsoft 的注意。

Microsoft Azure反馈页面 - 恢复WinForms ReportViewer控件的设计时特性

其他步骤:

  • After adding the reportviewer to the WinForm
  • Add a Panel Control to the WinForm.
  • In the form's form.designer.cs file, add the Reportviewer control to the panel.

      // 
      // panel1
      // 
      this.panel1.Controls.Add(this.reportViewer1);
    
  • Return to the form's designer, you should see the reportViewer on the panel

  • In the Properties panel select the ReportViewer in the controls list dropdown
  • Set the reportViewer's Dock property to Fill
现在您可以通过与面板实际交互来定位reportViewer。
更新:微软于2017年4月18日发布了一份文档,介绍如何在Visual Studio 2017中配置和使用报表工具。
Visual Studio 2017默认未安装ToolBox中的ReportViewer工具。安装扩展程序Microsoft Rdlc Report Designer for Visual Studio并将其添加到ToolBox中会生成一个非可视组件,该组件出现在窗体下方。
微软支持告诉我这是一个错误,但截至2017年4月21日,它已被确认为“设计上的工作方式”。
每个需要ReportViewer的项目都需要遵循以下步骤:
  • 如果您在ToolBox中有ReportViewer,请删除它。选中,右键单击并删除。
    • 您必须打开一个带有表单的项目才能执行此操作。

编辑于2019年8月7日 - 看起来当前版本的RDLC报表设计器扩展程序不再干扰。您需要此扩展程序才能编辑报表。

  • 如果您已安装了Microsoft Rdlc Report Designer for Visual Studio扩展程序,请卸载它。

  • 关闭您的解决方案并重新启动Visual Studio。这是一个关键步骤,如果在切换解决方案时不重新启动VS,则会出现错误。

  • 打开您的解决方案。
  • 打开NuGet包管理器控制台 (工具/NuGet 包管理器/包管理器控制台)
  • 在PM>提示符下输入此命令,大小写敏感。

    Install-Package Microsoft.ReportingServices.ReportViewerControl.WinForms

    您应该会看到描述软件包安装的文本。

现在我们可以暂时将ReportViewer工具添加到工具箱中。

  • 右键单击工具箱,使用Choose Items...

  • 我们需要浏览到位于解决方案Packages文件夹中的适当DLL,因此点击浏览按钮。

  • 在我们的示例中,我们可以将packages文件夹粘贴到Package Manager Console文本中显示的位置。

    C:\Users\jdoe\Documents\Projects\_Test\ReportViewerTest\WindowsFormsApp1\packages

  • 然后双击名为Microsoft.ReportingServices.ReportViewerControl.Winforms.140.340.80的文件夹。 未来版本号可能会更改。

  • 然后双击lib,再次双击net40

  • 最后,双击文件Microsoft.ReportViewer.WinForms.dll

    您应该在对话框中看到ReportViewer已选中。向右滚动,您将看到与之关联的版本14.0.0.0。

  • 点击确定。

ReportViewer现在位于工具箱中。

  • 将工具拖动到所需的表单上。

  • 完成后,从工具箱中删除ReportViewer工具。您不能将其与另一个项目一起使用。

  • 您可以保存该项目并开始使用。

请记住,每次需要打开带有ReportViewer的项目时,请重新启动Visual Studio,以便从正确的位置加载DLL。如果您尝试在没有重新启动的情况下打开带有ReportViewer的表单的解决方案,则会出现错误,指示“变量'reportViewer1'未声明或从未赋值。”。

如果您向同一解决方案添加新项目,则需要创建该项目,保存解决方案,重新启动Visual Studio,然后应该能够将ReportViewer添加到表单中。我曾经看到它第一次不起作用,并显示为非可视组件。

当发生这种情况时,从表单中删除该组件,从项目中删除Microsoft.ReportViewer.*引用,保存并重新启动通常可以解决问题。


2
@Rich Shealer,MVC项目的过程是相同的吗? - Kinjal Patel
1
另外一个影响我的事情是:我不得不从 .NET Framework 4 Client Profile 切换到 .NET Framework 4 - Conrad
1
这个能用。但是“每次需要打开带有ReportViewer的项目时都重新启动Visual Studio”真的是不可接受的(链接:https://www.youtube.com/watch?v=07So_lJQyqw)。 - Cee McSharpface
4
我可以确认,这些步骤不适用于 Microsoft.ReportingServices.ReportViewerControl.Winforms 150.1358.0 版本。 对我有用的是将扩展降级为 140.1000.523 版本。 - Ilyas Foo
3
谢谢确认。请查看我在此答案顶部的更新。有一个反馈链接可以投票让微软修复它。 - Rich Shealer
显示剩余3条评论

16

更新: 这个答案适用于 Visual Studio 2017 和 2019。

以下是我采取的三个步骤:

  1. 升级 Visual Studio 到最新版本。
  2. 通过以下方式将报表设计器/报表向导添加到添加/新建项目菜单中:
    • 打开 Visual Studio 菜单工具/扩展和更新
    • 从左侧面板选择在线
    • 搜索Microsoft Rdlc Report Designer for Visual Studio
    • 下载并安装它。
  3. 通过以下方式添加报表查看器控件:

    • 打开NuGet 包管理器

    • 安装Microsoft.ReportingServices.ReportViewerControl.Winforms

    • 转到包含 Microsoft.ReportViewer.WinForms.dll 的文件夹:%USERPROFILE%\.nuget\packages\microsoft.reportingservices.reportviewercontrol.winforms\140.1000.523\lib\net40
    • Microsoft.ReportViewer.WinForms.dll文件拖放到 Visual Studio 的工具箱窗口中。

对于WebForms应用程序:

  1. 相同。
  2. 相同。
  3. 通过以下方式添加报表查看器控件:

    • 打开NuGet 包管理器

    • 安装 Microsoft.ReportingServices.ReportViewerControl.WebForms

    • 进入包含 Microsoft.ReportViewer.WebForms.dll 文件的文件夹:%USERPROFILE%\.nuget\packages\microsoft.reportingservices.reportviewercontrol.webforms\140.1000.523\lib\net40
    • Microsoft.ReportViewer.WebForms.dll 文件拖拽到 Visual Studio 工具箱 窗口中。

完成!


3
请注意,在上面@Rich Shealer描述的添加报告服务的过程将在每次启动不同项目时迭代。为了避免这种情况:
1. 如果你可能需要设置不同的计算机 (例如,在没有互联网的家中),请把你从市场下载的安装程序放在一个安全的地方,即:
Microsoft.DataTools.ReportingServices.vsix和Microsoft.RdlcDesigner.vsix
2. 从包含报告服务的应用程序的包或bin文件夹中获取以下库:
Microsoft.ReportViewer.Common.dll Microsoft.ReportViewer.DataVisualization.dll Microsoft.ReportViewer.Design.dll Microsoft.ReportViewer.ProcessingObjectModel.dll Microsoft.ReportViewer.WinForms.dll
3. 安装步骤1中的2个组件。
4. 添加步骤2中的dll引用 (项目 > 引用 > 添加...)。
5. (可选) 向工具栏添加 Reporting 选项卡。
6. 向 Reporting 选项卡添加项目。
7. 浏览到 bin 文件夹或包含上述 dll 的位置,并将它们添加进去。
现在,你已经可以开始使用了! ReportViewer 图标将被添加到你的工具栏中,当你想要添加新项目时,你也会发现 Report 和 ReportWizard 模板已经添加到你的公共模板列表中... (报表)。
注: 当使用 Nuget 包管理器进行设置时,报告和报告向导模板被分组在“报告”下面。然而,使用我上面描述的方法并不会在已安装的模板中添加“报告”分组,但我认为这并不是什么问题,因为这样可以让你快速集成 rdlc,而不需要每次都从 Nuget 下载。

1
嗨,@Hannington Mambo,感谢您提供的有用解决方案。我已经按照您的步骤操作了,现在我可以在工具箱中看到报表查看器控件,并将其添加到我的窗体中,但是在“添加新项”面板中,我找不到“报表”和“报表向导”项目。您能帮助我吗? - M_Mogharrabi
很高兴能有所帮助!我成功地将它们添加到了我的“添加新项”安装模板中。我解释说,“报告”模板组将不可用。有时,您可能需要关闭 VS,移除并添加 DLL 文件。 - Hannington Mambo

2
从以下链接下载适用于Visual Studio的Microsoft Rdlc Report Designer: https://marketplace.visualstudio.com/items?itemName=ProBITools.MicrosoftRdlcReportDesignerforVisualStudio-18001 微软详细介绍了以下步骤: https://learn.microsoft.com/en-us/sql/reporting-services/application-integration/integrating-reporting-services-using-reportviewer-controls-get-started?view=sql-server-2017 以下步骤总结了上述文章。
在新的Web项目中添加报表查看器控件:
  1. Create a new ASP.NET Empty Web Site or open an existing ASP.NET project.

  2. Install the Report Viewer control NuGet package via the NuGet package manager console. From Visual Studio -> Tools -> NuGet Package Manager -> Package Manager Console

    Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms
    
  3. Add a new .aspx page to the project and register the Report Viewer control assembly for use within the page.

    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    
  4. Add a ScriptManagerControl to the page.

  5. Add the Report Viewer control to the page. The snippet below can be updated to reference a report hosted on a remote report server.

     <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Remote">
     <ServerReport ReportPath="" ReportServerUrl="" /></rsweb:ReportViewer>
    
最终页面应该如下所示。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="https://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server"></asp:ScriptManager>        
       <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Remote">
           <ServerReport ReportServerUrl="https://AContosoDepartment/ReportServer" ReportPath="/LatestSales" />
    </rsweb:ReportViewer>
    </form>
</body>


我发现的关于这个主题的最佳指导。一切都按照描述工作,直到最后一步:“ReportViewer现在位于ToolBox中”,但它并不在那里。有什么想法吗? - Nate
微软是否正在放弃SSRS? - Nate
@Nate 你的意思是微软将来不会支持SSRS吗?如果是这样,那么上面的文章来自微软。因此,微软目前仍然支持SSRS。 - Mohammed Osman

1
如果您和我一样,尝试了几种方法,但卡在了工具箱中控件可以画到窗体上,但它会从窗体消失并放置在组件中的点上,那么只需编辑设计器并在InitializeComponent()的适当区域添加以下内容即可使其可见:
this.Controls.Add(this.reportViewer1);

or

[ContainerControl].Controls.Add(this.reportViewer1);

在添加控件后,您还需要手动调整位置和大小。

这并不是一个很好的答案,但如果您卡住了,只需要暂时完成工作,直到有更多时间去弄清楚它,它应该会有所帮助。


1
我最终通过NuGet包管理器将版本降级到以下版本,并开始正常运行:Microsoft.ReportingServices.ReportViewerControl.Winforms 版本为 140.1000.523。 - Daniel P

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