如何使用旧版 .NET 升级助手

您所在的位置:网站首页 如何安装node旧版本 如何使用旧版 .NET 升级助手

如何使用旧版 .NET 升级助手

2023-06-06 14:45| 来源: 网络整理| 查看: 265

使用旧版 .NET 升级助手 项目 06/06/2023

本文介绍如何安装和运行旧版 .NET 升级助手命令行接口 (CLI) 工具。 从版本 0.5.2 开始,.NET 升级助手 CLI 工具的代码库变基到了 Visual Studio 扩展。 这意味着实际上有两个不同的 CLI 工具:0.5.2 之前的版本(称为旧版本)和 0.5.2+ 版本(即当前版本)。

旧版本有一些新版本中尚不提供的功能,例如分析命令或解决方案级升级,但也缺少新 (0.5.2+) 版本中可用的新改进。 因此,在当前版本功能和范围增加之前,你可能还想使用旧版本。

提示

旧版本工具可以升级解决方案文件。

安装旧版本

旧版本工具的安装方式与当前版本相同,只不过需要指定版本 0.4.421302:

dotnet tool install upgrade-assistant -g --version 0.4.421302

重要

如果已配置其他 NuGet 源,则安装此工具可能会失败。 使用 --ignore-failed-sources 参数将这些失败处理为警告而不是错误:

dotnet tool install upgrade-assistant -g --ignore-failed-sources --version 0.4.421302 分析应用

旧版本工具包括一种分析模式,可执行升级应用的简化试运行。 它可以提供有关在升级开始之前可能需要进行的更改的见解。 打开终端,导航到目标项目或解决方案所在的文件夹。 运行 upgrade-assistant analyze 命令,传入正在升级的项目或解决方案的名称。

例如,下面是使用 .NET Framework WPF 应用运行分析模式后的输出:

> upgrade-assistant analyze .\WebSiteRatings.sln [15:39:00 INF] Loaded 9 extensions [15:39:02 INF] Using MSBuild from C:\Program Files\dotnet\sdk\7.0.201\ [15:39:02 INF] Using Visual Studio install from C:\Program Files\Microsoft Visual Studio\2022\Preview [v17] [15:39:05 INF] Writing output to C:\code\migration\AnalysisReport.sarif [15:39:06 INF] Recommending Windows TFM net7.0-windows for project WebSiteRatings.csproj because the project either has Windows-specific dependencies or builds to a WinExe [15:39:06 INF] Marking assembly reference System.Configuration for removal based on package mapping configuration System.Configuration [15:39:06 INF] Adding package System.Configuration.ConfigurationManager based on package mapping configuration System.Configuration [15:39:08 INF] Package EntityFramework, Version=6.2.0 does not support the target(s) net7.0-windows but a newer version (6.4.4) does. [15:39:09 INF] Reference to .NET Upgrade Assistant analyzer package (Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.4.410601) needs to be added [15:39:10 INF] Adding Microsoft.Windows.Compatibility 7.0.0 helps with speeding up the upgrade process for Windows-based APIs [15:39:13 INF] Recommending Windows TFM net7.0-windows for project StarVoteControl.csproj because the project either has Windows-specific dependencies or builds to a WinExe [15:39:13 INF] Reference to .NET Upgrade Assistant analyzer package (Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.4.410601) needs to be added [15:39:13 INF] Adding Microsoft.Windows.Compatibility 7.0.0 helps with speeding up the upgrade process for Windows-based APIs [15:39:13 INF] Running analyzers on WebSiteRatings [15:39:14 INF] Identified 0 diagnostics in project WebSiteRatings [15:39:14 INF] Running analyzers on StarVoteControl [15:39:15 INF] Identified 0 diagnostics in project StarVoteControl [15:39:15 INF] Analysis Complete, the report is available at C:\code\migration\AnalysisReport.sarif

输出中有很多内部诊断信息,但某些信息非常有用。 请注意,分析模式指示在升级期间,项目的目标框架名字对象 (TFM) 将设置为 net7.0-windows,而不是 net7.0。 之所以建议这样做,是因为解决方案引用的项目是 WPF 项目,是一种仅限 Windows 的技术。 控制台应用程序可能会直接升级到 TFM net7.0,除非它使用某些特定于 Windows 的库或代码。

运行升级助手

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

当工具运行时,它将显示为升级项目而执行的步骤列表。 完成每个步骤后,工具将提供一组带编号的命令,让用户应用或跳过下一步。 它可能会提供其他选项,例如:

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

按 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

提示

请注意每个步骤的输出,因为它可能包含有关工具无法升级的内容的信息。 根据应用的复杂性程度,在工具完成后,可能需要执行更多升级工作。

升级项目

选择某个项目后,将显示升级步骤列表。 第一步已选中,也就是备份项目。 步骤列表类似于以下代码片段:

[15:50:50 INF] Initializing upgrade step Back up project Upgrade Steps Entrypoint: C:\code\migration\WebSiteRatings\WebSiteRatings.csproj Current Project: C:\code\migration\WebSiteRatings\WebSiteRatings.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 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

每个步骤首先详细说明要执行的操作,然后提示你执行此操作。 当工具到达任何不适用的步骤时,会跳过该步骤。 例如,如果工具处理“7. 将 WCF 服务更新为 CoreWCF(预览版)”,但应用未定义 WCF 服务,则会跳过该步骤并处理步骤 8。 同样,如果步骤 8 不适用,也会跳过。 在工具尝试查找适用的下一步时,你可能会看到跳过许多步骤。

最终步骤

升级项目后,需要对其进行编译和测试。 很可能还有更多工作要做才能完成升级。 你的应用的 .NET Framework 版本可能包含项目实际未使用的库引用,并且会进行结转。 分析每个引用并确定它是否是必需的。 该工具可能还添加或升级了对错误版本的 NuGet 包引用。

最后,寻找实现应用现代化的方法。 有关示例,请参阅从 .NET Framework 升级到 .NET 后的现代化



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3