我刚开始使用名为Visual Studio 2017 RC的新版本编写报表软件,但发现在Windows Forms和WPF应用程序模板中都缺少核心报表查看工具。有人能告诉我为什么报表查看器工具在Visual Studio 2017中消失了吗?没有它真的很困扰。在新的Visual Studio中是否有任何替代方法来处理此工具?
我刚开始使用名为Visual Studio 2017 RC的新版本编写报表软件,但发现在Windows Forms和WPF应用程序模板中都缺少核心报表查看工具。有人能告诉我为什么报表查看器工具在Visual Studio 2017中消失了吗?没有它真的很困扰。在新的Visual Studio中是否有任何替代方法来处理此工具?
**更新**: 2019年11月19日
微软在他们的Nuget库中发布了控件150.1400.0
的新版本。我的简短测试显示,它再次在表单设计器中工作,而150.1357.0
和150.1358.0
则没有。这包括能够调整大小和修改报表查看器任务。
**更新**: 2019年8月18日
将最新版本删除并回滚到150.900.148.0
似乎在我使用VS2017和VS2019的多台计算机上都有效。
您可以在Nuget解决方案包管理器中回滚到150.900.148。它的使用方式类似于以前的版本。使用下拉框选择旧版本即可。
手动删除对 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控件的设计时特性
其他步骤:
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
ReportViewer
工具。安装扩展程序Microsoft Rdlc Report Designer for Visual Studio并将其添加到ToolBox中会生成一个非可视组件,该组件出现在窗体下方。ReportViewer
的项目都需要遵循以下步骤:
ReportViewer
,请删除它。选中,右键单击并删除。
编辑于2019年8月7日 - 看起来当前版本的RDLC报表设计器扩展程序不再干扰。您需要此扩展程序才能编辑报表。
如果您已安装了Microsoft Rdlc Report Designer for Visual Studio扩展程序,请卸载它。
关闭您的解决方案并重新启动Visual Studio。这是一个关键步骤,如果在切换解决方案时不重新启动VS,则会出现错误。
工具/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.*
引用,保存并重新启动通常可以解决问题。
更新: 这个答案适用于 Visual Studio 2017 和 2019。
以下是我采取的三个步骤:
通过以下方式添加报表查看器控件:
打开NuGet 包管理器。
安装Microsoft.ReportingServices.ReportViewerControl.Winforms
对于WebForms应用程序:
通过以下方式添加报表查看器控件:
打开NuGet 包管理器。
安装 Microsoft.ReportingServices.ReportViewerControl.WebForms
完成!
Create a new ASP.NET Empty Web Site or open an existing ASP.NET project.
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
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" %>
Add a ScriptManagerControl to the page.
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>
this.Controls.Add(this.reportViewer1);
or
[ContainerControl].Controls.Add(this.reportViewer1);
在添加控件后,您还需要手动调整位置和大小。
这并不是一个很好的答案,但如果您卡住了,只需要暂时完成工作,直到有更多时间去弄清楚它,它应该会有所帮助。
.NET Framework 4 Client Profile
切换到.NET Framework 4
。 - Conrad