升级 WCF 服务器端项目以在 .NET 6 上使用 CoreWCF

重要

本文是在 Visual Studio 升级助手扩展发布之前编写的,它使用的是旧版 CLI 工具。 有关详细信息,请参阅使用旧版 .NET 升级助手

.NET 升级助手是一个命令行工具,可帮助升级 .NET Framework 上的现有 WCF 服务器端项目,以在 .NET 6 上使用 CoreWCF 服务。 本文将提供:

  • 开始前的注意事项。
  • 演示如何针对 .NET Framework 上的 WCF 服务器端项目运行该工具。
  • 疑难解答提示。

若要详细了解如何安装此工具,请参阅使用旧版 .NET 升级助手

开始前的注意事项

此工具当前支持 C# 项目,并使用 CoreWCF 将自托管 WCF 服务器端项目移植到 .NET 6。

若要使 WCF 项目适用于此升级,必须满足以下要求:

  1. 包括一个引用 System.ServiceModel 并创建新 ServiceHost 的 .cs 文件。

    如果 WCF 项目有多个 ServiceHost,则需要使用相同的方法创建所有主机。

  2. 包括一个存储 System.ServiceModel 属性的 .config 文件。

此工具的当前版本不支持通过 .svc 文件托管的 WCF 项目。

注意

如果项目不适用于此工具,我们建议查看 CoreWCF 演练指南BeanTrader 示例演示,并手动更新项目。

演示应用

可以使用基本计算器示例项目通过升级助手测试升级,这也是本文档中使用的演示。

如果要尝试更复杂的示例,请查看 Mike Rousos 创建的 BeanTrader 示例

运行升级助手

打开终端,导航到目标项目或解决方案所在的文件夹。 运行 upgrade-assistant upgrade 命令,传入正在升级的项目或解决方案的名称。

如果提供了项目,升级过程将立即在该项目上启动。 如果提供了解决方案,你将选择通常运行的项目,称为升级入口点。 根据该项目,将创建一个依赖项关系图,并提供有关升级项目的顺序的建议。

upgrade-assistant upgrade .\CalculatorSample.sln

该工具将运行并显示它将执行的步骤列表。 完成每个步骤后,该工具将提供一组命令,让用户应用或跳过下一步或其他选项,例如:

  • 获取有关此步骤的详细信息。
  • 更改项目。
  • 调整日志记录设置。
  • 停止升级并退出。

Enter 而不选择数字会选择列表中的第一项。

每个步骤初始化后,如果应用该步骤,它可能会提供有关其认为会发生的情况的信息。

选择要升级的入口点和项目

升级基本计算器示例的第一步是选择解决方案中的哪个项目作为入口点项目。

Upgrade Steps

1. [Next step] Select an entrypoint
2. Select project to upgrade

Choose a command:
   1. Apply next step (Select an entrypoint)
   2. Skip next step (Select an entrypoint)
   3. See more step details
   4. Configure logging
   5. Exit

选择“命令 1”开始该步骤。 结果显示:

[10:25:42 INF] Applying upgrade step Select an entrypoint
Please select the project you run. We will then analyze the dependencies and identify the recommended order to upgrade projects.
   1. CalculatorClient
   2. CalculatorService

列出了 2 个项目。 由于我们的工具会升级服务器端项目,因此我们将选择命令 2 来选择服务项目作为入口点。

升级项目

选择某个项目后,将列出该工具将执行的升级步骤的列表。

重要

根据正在升级的项目,你可能会也可能不会看到此示例中列出的每个步骤。

以下输出描述了升级项目所涉及的步骤:

Upgrade Steps

Entrypoint: C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj
Current Project: C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj

1. [Next step] Back up project
2. Convert project file to SDK style
3. Clean up NuGet package references
    a. Duplicate reference analyzer
    b. Package map reference analyzer
    c. Target compatibility reference analyzer
    d. Upgrade assistant reference analyzer
    e. Windows Compatibility Pack Analyzer
    f. MyDotAnalyzer reference analyzer
    g. Newtonsoft.Json reference analyzer
    h. Windows App SDK package analysis
    i. Transitive reference analyzer
4. Update TFM
5. Update NuGet Packages
    a. Duplicate reference analyzer
    b. Package map reference analyzer
    c. Target compatibility reference analyzer
    d. Upgrade assistant reference analyzer
    e. Windows Compatibility Pack Analyzer
    f. MyDotAnalyzer reference analyzer
    g. Newtonsoft.Json reference analyzer
    h. Windows App SDK package analysis
    i. Transitive reference analyzer
6. Add template files
7. Update WCF service to CoreWCF (Preview)
8. Upgrade app config files
    a. Convert Application Settings
    b. Convert Connection Strings
    c. Disable unsupported configuration sections
9. Update source code
    a. Apply fix for UA0002: Types should be upgraded
    b. Apply fix for UA0012: 'UnsafeDeserialize()' does not exist
    c. Apply fix for UA0014: .NET MAUI projects should not reference Xamarin.Forms namespaces
    d. Apply fix for UA0015: .NET MAUI projects should not reference Xamarin.Essentials namespaces
10. Move to next project

Choose a command:
   1. Apply next step (Back up project)
   2. Skip next step (Back up project)
   3. See more step details
   4. Select different project
   5. Configure logging
   6. Exit

备注

本文的其余部分不会明确显示升级步骤,除非有重要的内容需要指出。仍显示每个步骤的结果。

创建备份

在升级 CalculatorService 项目的这一示例中,你将应用每个步骤。 第一步(命令 1)是备份项目:

[10:25:52 INF] Applying upgrade step Back up project
Please choose a backup path
   1. Use default path [C:\Users\Desktop\CalculatorSample.backup]
   2. Enter custom path

该工具选择一个以当前文件夹命名的默认备份路径,但后面追加了 .backup。 可以选择自定义路径作为默认路径的替代。 对于每个升级的项目,会将项目的文件夹复制到备份文件夹。 在此示例中,CalculatorService 文件夹在备份步骤中从 CalculatorSample\CalculatorService 复制到 CalculatorSample.backup\CalculatorService:

[10:25:53 INF] Backing up C:\Users\Desktop\CalculatorSample\CalculatorService to C:\Users\t-simonaliao\OneDrive - Microsoft\Desktop\CalculatorSample.backup\CalculatorService
[10:25:53 INF] Project backed up to C:\Users\Desktop\CalculatorSample.backup\CalculatorService
[10:25:53 INF] Upgrade step Back up project applied successfully
Please press enter to continue...

升级项目文件

项目将从 .NET Framework 项目格式升级到 .NET SDK 项目格式。

[10:25:56 INF] Applying upgrade step Convert project file to SDK style
[10:25:56 INF] Converting project file format with try-convert, version 0.4.0-dev
[10:25:56 INF] Recommending executable TFM net6.0 because the project builds to an executable
C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj contains an App.config file. App.config is replaced by appsettings.json in .NET Core. You will need to delete App.config and migrate to appsettings.json if it's applicable to your project.
[10:25:58 INF] Converting project C:\Users\CalculatorSample\CalculatorService\CalculatorService.csproj to SDK style
[10:25:58 INF] Project file converted successfully! The project may require additional changes to build successfully against the new .NET target.
[10:26:00 INF] Upgrade step Convert project file to SDK style applied successfully

注意每个步骤的输出。 请注意,示例输出表明你将在升级后完成手动步骤:

App.config 被 .NET Core 中的 appsettings.json 替换。 如果它适用于你的项目,你将需要删除 App.config 并迁移到 appsettings.json。

在此示例中,WCF 更新步骤将基于 App.config 中的 system.serviceModel 部分创建一个新的 wcf.config。我们不需要迁移到 appsettings.json。

清理 NuGet 引用

更新项目格式后,下一步是清理 NuGet 包引用。

除了你的应用引用的包,packages.config 文件还包含对这些包的依赖项的引用。 例如,如果添加了对包 A 的引用,而该包依赖于包 B,则这两个包都将在 packages.config 文件中引用。 在新的项目系统中,只需要对包 A 的引用。 此步骤分析包引用并删除不需要的包引用。

[10:26:01 INF] Initializing upgrade step Clean up NuGet package references
[10:26:01 INF] Initializing upgrade step Duplicate reference analyzer
[10:26:01 INF] No package updates needed
[10:26:01 INF] Initializing upgrade step Package map reference analyzer
[10:26:01 INF] Marking assembly reference System.configuration for removal based on package mapping configuration System.Configuration
[10:26:01 INF] Adding package System.Configuration.ConfigurationManager based on package mapping configuration System.Configuration
[10:26:01 INF] Marking assembly reference System.ServiceModel for removal based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Primitives based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Http based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Duplex based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.NetTcp based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Security based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Federation based on package mapping configuration System.ServiceModel

[10:26:01 INF] Initializing upgrade step Remove reference 'System.configuration'
[10:26:03 INF] Applying upgrade step Remove reference 'System.configuration'
[10:26:03 INF] Removing outdated assembly reference: System.configuration
[10:26:03 INF] Upgrade step Remove reference 'System.configuration' applied successfully

[10:26:05 INF] Initializing upgrade step Remove reference 'System.ServiceModel'
[10:26:06 INF] Applying upgrade step Remove reference 'System.ServiceModel'
[10:26:06 INF] Removing outdated assembly reference: System.ServiceModel
[10:26:06 INF] Upgrade step Remove reference 'System.ServiceModel' applied successfully

[10:26:07 INF] Initializing upgrade step Add package 'System.Configuration.ConfigurationManager'
[10:26:09 INF] Applying upgrade step Add package 'System.Configuration.ConfigurationManager'
[10:26:09 INF] Adding package reference: System.Configuration.ConfigurationManager, Version=5.0.0
[10:26:09 INF] Upgrade step Add package 'System.Configuration.ConfigurationManager' applied successfully
[10:26:09 INF] Applying upgrade step Package map reference analyzer
[10:26:09 INF] Upgrade step Package map reference analyzer applied successfully

[10:26:10 INF] Initializing upgrade step Target compatibility reference analyzer
[10:26:10 INF] No package updates needed
[10:26:10 INF] Initializing upgrade step Upgrade assistant reference analyzer
[10:26:11 INF] Reference to .NET Upgrade Assistant analyzer package (Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.4.336902) needs to be added
[10:26:11 INF] Initializing upgrade step Add package 'Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers'
[10:26:13 INF] Applying upgrade step Add package 'Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers'
[10:26:13 INF] Adding package reference: Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.4.336902
[10:26:13 INF] Upgrade step Add package 'Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers' applied successfully
[10:26:13 INF] Applying upgrade step Upgrade assistant reference analyzer
[10:26:14 INF] Upgrade step Upgrade assistant reference analyzer applied successfully

[10:26:15 INF] Initializing upgrade step Windows Compatibility Pack Analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step MyDotAnalyzer reference analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step Newtonsoft.Json reference analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step Windows App SDK package analysis
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step Transitive reference analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Applying upgrade step Clean up NuGet package references
[10:26:15 INF] Upgrade step Clean up NuGet package references applied successfully

你的应用仍在引用 .NET Framework 程序集。 其中一些程序集可以作为 NuGet 包提供。 此步骤会分析这些程序集并引用适当的 NuGet 包。

在此示例中,包更新程序将 CalculatorService 检测为仅服务器项目,无需添加 System.ServiceModel 包。 即使根据包映射配置将它们添加到列表中,这些步骤也未应用。

处理 TFM

接下来,该工具会将 TFM 从 .NET Framework 更改为建议的 SDK。 在此示例中,它是 net6.0-windows

[10:26:17 INF] Applying upgrade step Update TFM
[10:26:17 INF] Recommending executable TFM net6.0 because the project builds to an executable
[10:26:19 INF] Updated TFM to net6.0
[10:26:19 INF] Upgrade step Update TFM applied successfully

升级 NuGet 包

接下来,该工具会将项目的 NuGet 包更新到支持更新的 TFM net6.0-windows 的版本。

[10:26:20 INF] Initializing upgrade step Update NuGet Packages
[10:26:20 INF] Initializing upgrade step Duplicate reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Package map reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Target compatibility reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Upgrade assistant reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Windows Compatibility Pack Analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step MyDotAnalyzer reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Newtonsoft.Json reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Windows App SDK package analysis
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Transitive reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Applying upgrade step Update NuGet Packages
[10:26:20 INF] Upgrade step Update NuGet Packages applied successfully

添加模板文件

更新包后,下一步是更新任何模板文件。 在此示例中,没有需要更新或添加到项目中的模板文件。 此步骤将被跳过,下一步会自动启动。

[10:26:20 INF] Initializing upgrade step Add template files
[10:26:20 INF] 0 expected template items needed

将 WCF 服务更新为 CoreWCF(预览版)

注意:在编写本文档时,WCF 更新程序扩展是作为预览版提供的。 如果对预览版有任何反馈,请在升级助手 GitHub 存储库中打开带有 area:WCF 标记的问题。

升级助手将首先初始化 WCF 更新程序步骤并检查项目是否适用于 WCF 更新。

[10:26:20 INF] Initializing upgrade step Update WCF service to CoreWCF (Preview)
[10:26:20 INF] This config file is applicable for upgrade: C:\Users\Desktop\CalculatorSample\CalculatorService\App.config. System.serviceModel/services elements were found.
[10:26:20 INF] This  file is applicable for upgrade: C:\Users\Desktop\CalculatorSample\CalculatorService\service.cs. ServiceHost object was found.
[10:26:20 INF] This project file is applicable for upgrade: C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj. Reference to System.serviceModel was found.
[10:26:20 INF] This project is applicable for updating to CoreWCF. Initializing the update step...
[10:26:20 INF] Updaters are successfully constructed. Ready to start update.

Choose a command:
   1. Apply next step (Update WCF service to CoreWCF (Preview))
   2. Skip next step (Update WCF service to CoreWCF (Preview))
   3. See more step details
   4. Select different project
   5. Configure logging
   6. Exit

该步骤分别检查配置文件、源代码和项目文件,以确定项目是否适用于 WCF 更新。 如果项目不适用(例如不使用 WCF,或不满足文章开头所述的要求),日志记录消息将描述哪个文件不适用以及缺少的内容。 然后,将跳过该步骤并自动开始下一步。

在此示例中,CalculatorSample 适用于 WCF 更新,我们将选择命令 1 来应用该步骤。

[10:26:23 INF] Applying upgrade step Update WCF service to CoreWCF (Preview)
[10:26:23 INF] Finish updating project file.
[10:26:23 WRN] The mex endpoint is removed from .config file, and service metadata behavior is configured in the source code instead.
[10:26:23 INF] Finish updating configuration files.
[10:26:23 WRN] Changing void Main() to async Task Main() to enable awaiting starting and stopping the ASP.NET Core host.
[10:26:23 INF] Finish updating source code.
[10:26:23 INF] Finish writing changes to project file.
[10:26:23 INF] Finish writing changes to configuration files.
[10:26:23 INF] Finish writing changes to the source code to replace the ServiceHost instance(s).
[10:26:23 INF] Project was successfully updated to use CoreWCF services. Please review changes.
[10:26:23 INF] Upgrade step Update WCF service to CoreWCF (Preview) applied successfully

此步骤创建更新并将它们单独写入原始文件。 请注意可能会通知你从原始文件中删除或手动更新以在升级后完成的输出。

配置和代码文件更新

如果工具确定不需要对项目执行任何操作,则工具会自动跳过这些步骤。

WCF 更新完成后,下一步是更新应用配置文件。 在此示例中,应用配置文件中没有任何需要升级的内容。 WCF 步骤已更新配置文件,因此,此步骤不会报错使用不受支持的 system.serviceModel。 此步骤将被跳过,下一步会自动启动。

[10:26:43 INF] Initializing upgrade step Upgrade app config files
[10:26:43 INF] Found 0 app settings for upgrade:
[10:26:43 INF] Found 0 connection strings for upgrade:
[10:26:43 INF] 0 web page namespace imports need upgraded:

完成此项目升级之前的最后一步是更新任何过时的代码引用。 基于要升级的项目类型,将为此步骤显示一系列已知代码修补程序。 某些修补程序可能不适用于你的项目。

9. Update source code
    a. Apply fix for UA0002: Types should be upgraded
    b. Apply fix for UA0012: 'UnsafeDeserialize()' does not exist
    c. Apply fix for UA0014: .NET MAUI projects should not reference Xamarin.Forms namespaces
    d. Apply fix for UA0015: .NET MAUI projects should not reference Xamarin.Essentials namespaces

在这种情况下,没有任何建议的修补程序应用于示例项目,并且此步骤会在上一步完成后立即自动完成。

[10:26:44 INF] Initializing upgrade step Update source code
[10:26:44 INF] Running analyzers on CalculatorService
[10:26:48 INF] Identified 0 diagnostics in project CalculatorService
[10:26:51 INF] Initializing upgrade step Move to next project

完成升级

如果还有更多项目要迁移,该工具可让你选择接下来要升级的项目。 当没有更多项目要升级时,该工具会将你带到“完成升级”步骤:

1. [Next step] Finalize upgrade

Choose a command:
   1. Apply next step (Finalize upgrade)
   2. Skip next step (Finalize upgrade)
   3. See more step details
   4. Configure logging
   5. Exit
>
[10:27:15 INF] Applying upgrade step Finalize upgrade
[10:27:15 INF] Upgrade step Finalize upgrade applied successfully

理想情况下,成功运行该工具后,这些更改应该出现在原始文件中。

service.cs 文件中,using System.ServiceModel 被替换为对 CoreWCF 的引用。 ServiceHost 实例也被删除,服务托管在 ASP .NET Core 上。

using System;
using System.Threading.Tasks;
using CoreWCF;
using CoreWCF.Configuration;
using CoreWCF.Description;
using CoreWCF.Security;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
    public static async Task Main()
    {
        var builder = WebApplication.CreateBuilder();

        // Set up port (previously this was done in configuration,
        // but CoreWCF requires it be done in code)
        builder.WebHost.UseNetTcp(8090);
        builder.WebHost.ConfigureKestrel(options =>
        {
            options.ListenAnyIP(8080);
        });

        // Add CoreWCF services to the ASP.NET Core app's DI container
        builder.Services.AddServiceModelServices()
                        .AddServiceModelConfigurationManagerFile("wcf.config")
                        .AddServiceModelMetadata()
                        .AddTransient<CalculatorSample.CalculatorService>();

        var app = builder.Build();

        // Enable getting metadata/wsdl
        var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
        serviceMetadataBehavior.HttpGetEnabled = true;
        serviceMetadataBehavior.HttpGetUrl = new Uri("http://localhost:8080/CalculatorSample/metadata");

        // Configure CoreWCF endpoints in the ASP.NET Core hosts
        app.UseServiceModel(serviceBuilder =>
        {
            serviceBuilder.AddService<CalculatorSample.CalculatorService>(serviceOptions => 
            {
                serviceOptions.DebugBehavior.IncludeExceptionDetailInFaults = true;
            });

            serviceBuilder.ConfigureServiceHostBase<CalculatorSample.CalculatorService>(serviceHost =>
            {

            });
        });
            
        await app.StartAsync();
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();
        await app.StopAsync();
    }

对于配置文件,App.config 中的 system.serviceModel 部分已移至更新期间生成的新配置文件 wcf.config

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- system.serviceModel section is moved to a separate wcf.config file located at the same directory as this file.-->
</configuration>

wcf.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="CalculatorSample.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
        <!--The host element is not supported in configuration in CoreWCF. The port that endpoints listen on is instead configured in the source code.-->
        <!--<host>
  <baseAddresses>
    <add baseAddress="net.tcp://localhost:8090/CalculatorSample/service" />
    <add baseAddress="http://localhost:8080/CalculatorSample/service" />
  </baseAddresses>
</host>-->
        <!-- this endpoint is exposed at the base address provided by host: net.tcp://localhost:8090/CalculatorSample/service  -->
        <endpoint address="/CalculatorSample/service" binding="netTcpBinding" contract="CalculatorSample.ICalculator" />
        <!-- the mex endpoint is exposed at http://localhost:8080/CalculatorSample/service/ -->
        <!--The mex endpoint is removed because it's not support in CoreWCF. Instead, the metadata service is enabled in the source code.-->
      </service>
    </services>
    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <!--The behavior element is not supported in configuration in CoreWCF. Some service behaviors, such as metadata, are configured in the source code.-->
    <!--<behaviors>
  <serviceBehaviors>
    <behavior name="CalculatorServiceBehavior">
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>-->
  </system.serviceModel>
</configuration>

最后,在项目文件 CalculatorService.csproj 中,SDK 已更新为 Microsoft.NET.Sdk.Web 以启用 ASP .NET Core 主机并添加了 CoreWCF 包引用。

  <ItemGroup>
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
    <PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.336902">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="CoreWCF.NetTcp" Version="1.1.0" />
    <PackageReference Include="CoreWCF.Primitives" Version="1.1.0" />
    <PackageReference Include="CoreWCF.ConfigurationManager" Version="1.1.0" />
    <PackageReference Include="CoreWCF.Http" Version="1.1.0" />
    <PackageReference Include="CoreWCF.WebHttp" Version="1.1.0" />
  </ItemGroup>

请注意,在 CalculatorSample 中,没有项目到项目的依赖关系,并且只需更新 CalculatorService 即可成功运行示例。 但在其他具有不同依赖项的情况下,可能还需要更新同一解决方案中的其他项目。

升级后

升级项目后,需要对其进行编译和测试。 升级助手会尽其所能,但作为项目升级的一部分,它并不能解决所有的不兼容问题。 例如,你的应用的 .NET Framework 版本可能包含项目实际未使用的库引用。 你需要分析每个引用并确定它是否是必需的。 该工具可能还添加或升级了对错误版本的 NuGet 包引用。

故障排除提示

使用 .NET 升级助手时,可能会出现一些已知问题。 某些情况下,.NET 升级助手在内部使用的 try-convert 工具会出现这些问题。

有关更多故障排除提示和已知问题,可查看此工具的 GitHub 存储库

另请参阅