dotnet migratedotnet migrate

本主題適用於:✓ .NET Core 1.x SDK 和更新版本This topic applies to: ✓ .NET Core 1.x SDK and later versions

名稱Name

dotnet migrate - 將 Preview 2 .NET Core 專案移轉至 .NET Core SDK 型專案。dotnet migrate - Migrates a Preview 2 .NET Core project to a .NET Core SDK-style project.

注意

在下一個預覽版本中,dotnet migrate 會從 .NET Core 3.0 SDK 中移除。dotnet migrate will be removed from the .NET Core 3.0 SDK in the next preview release.

概要Synopsis

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

說明Description

dotnet migrate 命令會將有效的 Preview 2 project.json 型專案移轉至有效的 .NET Core SDK 型 csproj 專案。The dotnet migrate command migrates a valid Preview 2 project.json-based project to a valid .NET Core SDK-style csproj project.

根據預設,命令會移轉根專案和根專案包含的任何專案參考。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 runtime.

可針對下列資產進行移轉: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 命令會在 backup 目錄 (若目錄不存在則會建立) 中保留移轉的 project.json 檔案。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 命令只支援有效的 Preview 2 project.json 型專案。The dotnet migrate command only supports valid Preview 2 project.json-based projects. 這表示您無法使用它將 DNX 或 Preview 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. 您必須先手動將專案移轉到 Preview 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