MSB4062:无法从程序集 Microsoft.ReportViewer.WebForms 加载 "Microsoft.Reporting.RdlCompile" 任务,版本 =15.0.0.0

MSB4062: The "Microsoft.Reporting.RdlCompile" task could not be loaded from the assembly Microsoft.ReportViewer.WebForms, Version=15.0.0.0

有几个类似的 Stack Overflow 帖子与此问题相似但不完全相同:

我们有 Microsoft RDLC Report Designer (https://marketplace.visualstudio.com/items?itemName=ProBITools.MicrosoftRdlcReportDesignerforVisualStudio-18001) 并且正在使用 Visual Studio 2019。

当尝试使用 64 位版本的 MSBuild 构建我们的一些 RDLC 报告时,我们未能构建并出现以下错误:

C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\ReportingServices\Microsoft.ReportingServices.targets(24,2):
error MSB4062: The "Microsoft.Reporting.RdlCompile" task could not be loaded from the assembly Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91.
Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.
The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

加载 fuslogvw 显示以下绑定日志:

*** Assembly Binder Log Entry  (5/13/2020 @ 4:06:22 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/amd64/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/amd64/Microsoft.ReportViewer.WebForms.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/amd64/Microsoft.ReportViewer.WebForms/Microsoft.ReportViewer.WebForms.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/amd64/Microsoft.ReportViewer.WebForms.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/amd64/Microsoft.ReportViewer.WebForms/Microsoft.ReportViewer.WebForms.EXE.
LOG: All probing URLs attempted and failed.

查看 VSIX 安装日志 (dd_setup_20200513155525_001_617ad572-c5b7-415c-b166-b2969077f719) 并筛选已安装的 DLL 显示:

Completed: Copying file /$MSBuild/15.0/bin/Microsoft.ReportViewer.Common.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild.0\bin\Microsoft.ReportViewer.Common.dll
Completed: Copying file /$MSBuild/15.0/bin/Microsoft.ReportViewer.ProcessingObjectModel.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild.0\bin\Microsoft.ReportViewer.ProcessingObjectModel.dll
Completed: Copying file /$MSBuild/15.0/bin/Microsoft.ReportViewer.WebForms.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild.0\bin\Microsoft.ReportViewer.WebForms.dll
Completed: Copying file /$MSBuild/15.0/bin/Microsoft.SqlServer.Types.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild.0\bin\Microsoft.SqlServer.Types.dll
Completed: Copying file /$MSBuild/Current/Bin/Microsoft.ReportViewer.Common.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.ReportViewer.Common.dll
Completed: Copying file /$MSBuild/Current/Bin/Microsoft.ReportViewer.ProcessingObjectModel.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.ReportViewer.ProcessingObjectModel.dll
Completed: Copying file /$MSBuild/Current/Bin/Microsoft.ReportViewer.WebForms.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.ReportViewer.WebForms.dll
Completed: Copying file /$MSBuild/Current/Bin/Microsoft.SqlServer.Types.dll to C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.SqlServer.Types.dll

根本原因似乎是 64 位版本的 MSBuild 探测路径期望任务存在于 64 位文件夹中,但 VSIX 安装程序没有将它们放在那里。

要手动解决此问题,请复制以下文件:

C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.ReportViewer.Common.dll
C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.ReportViewer.ProcessingObjectModel.dll
C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.ReportViewer.WebForms.dll
C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\Microsoft.SqlServer.Types.dll

C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\amd64

进入 64 位版本的 MSBuild Bin

这已报告给 Microsoft(BI 组 [通过电子邮件] 和 MSBuild 以了解探测位置预期)。