在.Net Core 2.2 Web API中添加WCF引用失败

问题描述 投票:0回答:2

我正在使用 VS 2017、.Net Core 2.2 API 项目,以及一些对其他服务的 WCF 引用。一切都工作正常,直到我在同一台机器上安装了 VS 2019。

现在尝试

Add Connected Service
,它在步骤上卡住了一段时间:

Restoring NuGet packages for bootstrapper...

然后失败并显示以下错误消息。

Importing web service metadata ...
Number of service endpoints found: 1
Scaffolding service reference code ...
Restoring NuGet packages for bootstrapper ...
Warning:Warning: Determining projects to restore...
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605: Detected package downgrade: Microsoft.Extensions.DependencyInjection from 3.1.2 to 2.2.0. Reference the package directly from the project to select a different version. 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Serilog.AspNetCore 3.4.0 -> Microsoft.Extensions.DependencyInjection (>= 3.1.2) 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Microsoft.Extensions.DependencyInjection (>= 2.2.0)
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605: Detected package downgrade: Microsoft.Extensions.Logging from 3.1.2 to 2.2.0. Reference the package directly from the project to select a different version. 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Serilog.AspNetCore 3.4.0 -> Microsoft.Extensions.Logging (>= 3.1.2) 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Microsoft.Extensions.Logging (>= 2.2.0)
  Failed to restore C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj (in 8.33 sec).
Building bootstrapper project ...
Error:Error: Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605: Detected package downgrade: Microsoft.Extensions.DependencyInjection from 3.1.2 to 2.2.0. Reference the package directly from the project to select a different version. 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Serilog.AspNetCore 3.4.0 -> Microsoft.Extensions.DependencyInjection (>= 3.1.2) 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Microsoft.Extensions.DependencyInjection (>= 2.2.0)
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605: Detected package downgrade: Microsoft.Extensions.Logging from 3.1.2 to 2.2.0. Reference the package directly from the project to select a different version. 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Serilog.AspNetCore 3.4.0 -> Microsoft.Extensions.Logging (>= 3.1.2) 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Microsoft.Extensions.Logging (>= 2.2.0)

Build FAILED.

C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605: Detected package downgrade: Microsoft.Extensions.DependencyInjection from 3.1.2 to 2.2.0. Reference the package directly from the project to select a different version. 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Serilog.AspNetCore 3.4.0 -> Microsoft.Extensions.DependencyInjection (>= 3.1.2) 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Microsoft.Extensions.DependencyInjection (>= 2.2.0)
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605: Detected package downgrade: Microsoft.Extensions.Logging from 3.1.2 to 2.2.0. Reference the package directly from the project to select a different version. 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Serilog.AspNetCore 3.4.0 -> Microsoft.Extensions.Logging (>= 3.1.2) 
C:\Users\midrees\AppData\Local\Temp\WCFConnectedService\2021_Feb_23_10_27_37\svcutil_bootstrap\SvcutilBootstrapper.csproj : error NU1605:  SvcutilBootstrapper -> Microsoft.Extensions.Logging (>= 2.2.0)
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:02.97

An error occurred while bootstrapping svcutil. This usually happens when processing references.  You might be able to work around this problem by not providing reference parameters, and manually removing any types redefined in the generated proxy code.
Done.

wcf asp.net-core-webapi asp.net-core-2.2
2个回答
0
投票

这是Visual Studio的问题,github上也有同样的问题,可以参考it

除了使用Add Connected Service生成代理类外,我们还可以使用dotnet-svcutil命令生成代理类。

Windows Communication Foundation (WCF) dotnet-svcutil 工具是一个 .NET 工具,它从网络位置上的 Web 服务或 WSDL 文件检索元数据,并生成包含访问 Web 服务操作的客户端代理方法的 WCF 类。

与 .NET Framework 项目的服务模型元数据 - svcutil 工具类似,dotnet-svcutil 是一个命令行工具,用于生成与 .NET Core 和 .NET Standard 项目兼容的 Web 服务引用。

我建议你使用dotnet-svcutil来生成代理类,有关dotnet-svcutil的更多信息,你可以参考这个link


0
投票

按照 https://github.com/dotnet/wcf/issues/1445 的建议,确保以下 NuGet 包源已启用且可用:

还要确保您使用 v3 而不是 v2 作为 nuget 源。

© www.soinside.com 2019 - 2024. All rights reserved.