dotnet migratedotnet migrate

本文适用于:✔️ .NET Core 2.x SDKThis article applies to: ✔️ .NET Core 2.x SDK

“属性”Name

dotnet migrate - 将预览版 2 .NET Core 项目迁移到 .NET Core SDK 样式的项目中。dotnet migrate - Migrates a Preview 2 .NET Core project to a .NET Core SDK-style project.

摘要Synopsis

dotnet migrate [<SOLUTION_FILE|PROJECT_DIR>] [--format-report-file-json <REPORT_FILE>]
    [-r|--report-file <REPORT_FILE>] [-s|--skip-project-references [Debug|Release]]
    [--skip-backup] [-t|--template-file <TEMPLATE_FILE>] [-v|--sdk-package-version]
    [-x|--xproj-file]

dotnet migrate -h|--help

描述Description

此命令已弃用。This command is deprecated. 自 .NET Core 3.0 SDK 起,dotnet migrate 命令不再可用。The dotnet migrate command is no longer available starting with .NET Core 3.0 SDK. 它只能将预览版 2 .NET Core 项目迁移到不支持的 1.x .NET Core 项目。It can only migrate a Preview 2 .NET Core project to a 1.x .NET Core project, which is out of support.

默认情况下,命令迁移根项目和根项目包含的任何项目引用。By default, the command migrates the root project and any project references that the root project contains. 在运行时使用 --skip-project-references 选项禁用此行为。This behavior is disabled using the --skip-project-references option at run time.

可在下列资产上执行迁移:Migration can be performed on the following assets:

  • 通过指定 project.json 文件进行迁移的单个项目。A single project by specifying the project.json file to migrate.
  • 通过将路径传递到 global.json 文件在 global.json 文件中指定的所有目录。All of the directories specified in the global.json file by passing in a path to the global.json file.
  • 一个 solution.sln 文件,它迁移在解决方案中引用的项目。A solution.sln file, where it migrates the projects referenced in the solution.
  • 以递归方式迁移给定目录的所有子目录。On all subdirectories of the given directory recursively.

dotnet migrate 命令将迁移的 project.json 文件保存在 backup 目录中,如果该目录不存在,将创建一个。The dotnet migrate command keeps the migrated project.json file inside a backup directory, which it creates if the directory doesn't exist. 使用 --skip-backup 选项重写此行为。This behavior is overridden using the --skip-backup option.

默认情况下,迁移操作会将迁移过程的状态输出到标准输出 (STDOUT)。By default, the migration operation outputs the state of the migration process to standard output (STDOUT). 如果使用 --report-file <REPORT_FILE> 选项,输出将保存到指定的文件中。If you use the --report-file <REPORT_FILE> option, the output is saved to the file specify.

dotnet migrate 命令仅支持有效的预览版 2 基于 project.json 的项目。The dotnet migrate command only supports valid Preview 2 project.json-based projects. 这意味着,不能使用它将 DNX 或预览版 1 基于 project.json 的项目直接迁移到 MSBuild/csproj 项目。This means that you cannot use it to migrate DNX or Preview 1 project.json-based projects directly to MSBuild/csproj projects. 首先需要将项目手动迁移到预览版 2 基于 project.json 的项目,然后使用 dotnet migrate 命令迁移该项目。You first need to manually migrate the project to a Preview 2 project.json-based project and then use the dotnet migrate command to migrate the project.

自变量Arguments

PROJECT_JSON/GLOBAL_JSON/SOLUTION_FILE/PROJECT_DIR

下列路径之一:The path to one of the following:

  • 要迁移的 project.json 文件。a project.json file to migrate.
  • global.json 文件:迁移在 global.json 中指定的文件夹 。a global.json file: the folders specified in global.json are migrated.
  • solution.sln 文件:迁移该解决方案中引用的项目。a solution.sln file: the projects referenced in the solution are migrated.
  • 要迁移的目录:在指定的目录中以递归方式搜索要迁移的 project.json 文件。a directory to migrate: recursively searches for project.json files to migrate inside the specified directory.

如未指定,则默认为当前目录。Defaults to current directory if nothing is specified.

选项Options

--format-report-file-json <REPORT_FILE>

将迁移报告文件(而非用户消息)作为 JSON 输出。Output migration report file as JSON rather than user messages.

-h|--help

打印出有关命令的简短帮助。Prints out a short help for the command.

-r|--report-file <REPORT_FILE>

除控制台外,还将迁移报告输出到文件。Output migration report to a file in addition to the console.

-s|--skip-project-references [Debug|Release]

跳过迁移项目引用。Skip migrating project references. 默认情况下,以递归方式迁移项目引用。By default, project references are migrated recursively.

--skip-backup

在成功迁移后,跳过将 project.jsonglobal.json*.xproj 移动到 backup 目录的步骤。Skip moving project.json, global.json, and *.xproj to a backup directory after successful migration.

-t|--template-file <TEMPLATE_FILE>

用于迁移的模板 csproj 文件。Template csproj file to use for migration. 默认情况下,使用与被 dotnet new console 删除的模板相同的模板。By default, the same template as the one dropped by dotnet new console is used.

-v|--sdk-package-version <VERSION>

在已迁移应用中将被引用的 sdk 包的版本。The version of the sdk package that's referenced in the migrated app. 默认为 dotnet new 中 SDK 的版本。The default is the version of the SDK in dotnet new.

-x|--xproj-file <FILE>

要使用的 xproj 文件的路径。The path to the xproj file to use. 当项目目录中有多个 xproj 时需要。Required when there is more than one xproj in a project directory.

示例Examples

将当前目录中的项目及其所有项目迁移到项目依赖项:Migrate a project in the current directory and all of its project-to-project dependencies:

dotnet migrate

迁移 global.json 文件所包含的所有项目:Migrate all projects that global.json file includes:

dotnet migrate path/to/global.json

仅迁移当前项目,不迁移项目到项目 (P2P) 的依赖项。Migrate only the current project and no project-to-project (P2P) dependencies. 此外,使用特定的 SDK 版本:Also, use a specific SDK version:

dotnet migrate -s -v 1.0.0-preview4