ReportViewer 14:面向 .NET Framework 4.0 时"The primary reference [...] could not be resolved"



我已经在我的Windows表单应用程序中安装了ReportViewer 14 Nuget软件包(targeting .NET Framwork 4.0):Microsoft.ReportingServices.ReportViewerControl.Winforms(v。140.340.80;最新稳定)

构建时,我会收到与以下几个相似的警告:

主要参考" Microsoft.ReportViewer.Design,版本= 14.0.0.0,culture =中性,publicKeyToken = 89845DCD8080CC91,processorrarchituction = msil无法解决"无法解决".14.0,版本= 14.0.0.0,culture =中性,publicKeyToken = b03f5f7f11d50a3a"是针对" .netFramework,version = v4.5"框架构建的。这是一个比当前针对的框架" .netFramework,版本= V4.0"更高的版本。

该应用程序成功构建,一切似乎都起作用,但是我仍然对警告仍然不关心。

我不确定它是否与操作系统有关,但是:我正在运行Windows 7,我的同事在Windows 10上,并且没有看到问题(两个Visual Studio 2017)

不幸的是,我们目前与.NET Framework 4.0绑定,因为我们必须支持某些Windows XP客户端。

更新:

我创建了一个新的,空的.NET 4.0项目,并且正在接收相同的警告(这次仅影响" [。net]框架组件")。

这是Vanilla项目中的警告的完整列表:

1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3258: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build.Framework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "14.0.0.0" than the version "4.0.0.0" in the current target framework.
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Diagnostics.Tracing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Diagnostics.Tracing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Collections.Concurrent, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Collections.Concurrent, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Dynamic.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Dynamic.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Threading, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Threading, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Diagnostics.Debug, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Diagnostics.Debug, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Runtime.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Diagnostics.Tools, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Diagnostics.Tools, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>C:Program Files (x86)Microsoft Visual Studio2017ProfessionalMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(1987,5): warning MSB3268: The primary reference "Microsoft.ReportViewer.Design" could not be resolved because it has an indirect dependency on the framework assembly "System.Reflection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.ReportViewer.Design" or retarget your application to a framework version which contains "System.Reflection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

我终于能够解决它:

TL; DR

核心问题似乎是分别安装 Visual Studio 2015 sql Server Management Studio 17.2 :卸载所有组件后,警告消失了!

长答案

我注意到的第一件事是,MSBUILD抱怨(例如Microsoft.VisualStudio.Shell.14.0)的组件已安装在我的全球组装缓存(GAC)中,而它们不在我的同事PC上。我通过在开发人员命令提示中运行以下操作来验证:

gacutil /l Microsoft.VisualStudio.Shell.14.0

因此,一定已经在GAC中安装了这些组件。

版本号" 14"指向Visual Studio 2015的方向(因为其内部版本编号是Visual Studio V14)。因此,我卸载了具有" Visual Studio 2015"的所有内容,包括

  • Visual Studio 2015 Shell(隔离)和
  • SQL Server Management Studio 17.2(因为我知道SSM基本上是一个视觉工作室扩展名,并且正在安装vs的" shell" vs)

这解决了所有警告。

(我假设MSBUILD然后使用参考组件,该组件适用于.NET 4.0,而不是针对4.5的GAC的参考组件)

仔细检查我的发现,我重新安装了SQL Server Management Studio 17.2,其中包括 vs2015 shell(隔离) - 返回警告。卸载了一次后,它们又消失了。

这不是一个完全令人满意的解决方案,因为我不能再安装SSM。

我已经通过删除对" Microsoft.reportviewer.design"的所有引用来修复了此问题。

(此引用由报告查看器Nuget软件包添加。在VS2010/VS2015中,我从未使用过该参考,也没有在我的应用中分发该DLL。)

因此,对我的解决方案是以下内容:

  • vs 2017,SSMS 17.x都安装了
  • Winform应用程序针对.NET 4.0
  • 添加了报告查看器掘金软件包和" Visual Studio的Microsoft RDLC Reports Designer"扩展名
  • 手动删除microsoft.repotviewer.design参考
  • 我的应用程序仅包含本地报告:带有旧格式(VS2010)的RDLC文件,以及一些经过修订的文件,由VS Report Designer转换为最新的RDLC。
  • App可以通过警告进行罚款,并且在Dev Machine上没有任何问题运行。
  • .dll

在Win10上测试没有任何问题。

用.NET 4.0在干净的XP SP3上测试的压力:报告正常。

最新更新