Dotnet Core 简明教程
.NET Core - Migrations
在本章中,我们将迁移包含 ` project.json ` 文件构建系统而不是 ` MSBuild ( .csproj` 的控制台应用程序。因此,我们有一个旧项目,其中包含以下文件。
In this chapter, we will migrate the console application which contains the project.json file build system instead of MSBuild (.csproj)*. So, we have an old project which contains the following files.
现在的问题是,我们为什么需要迁移?此项目是使用 .NET Core 1.0 Preview 2 工具创建的,现在我们已经安装了 .NET Core 2.0 Preview 1 工具。现在,当你使用 .NET Core 2.0 命令行实用工具构建此应用程序时,你将看到以下错误。
Now the question is, why do we need migration? This project is created using .NET Core 1.0 preview 2 tooling and now we have installed .NET Core 2.0 preview 1 tooling. Now when you build this application using .NET Core 2.0 command line utility, then you will see the following error.
这是因为 ` project.json ` 构建系统在 .NET Core 2.0 中不再可用,所以我们需要迁移才能正常工作。要查看可用命令,让我们运行以下命令。
This is because the project.json build system is no longer available in .NET Core 2.0, so we need migration so that it can work properly. To see the available commands, let us run the following command.
dotnet help
在命令部分,你可以看到不同的命令,你还可以看到 ` migrate ` 命令,它将基于 project.json 的项目迁移到基于 MSBuild 的项目。
In the commands section, you can see the different commands and you can also see the migrate command which will migrate a project.json based project to a MSBuild based project.
现在,让我们运行以下命令。
Let us now run the following command.
dotnet migrate
你将看到迁移过程的摘要,在这里你还可以看到项目已成功迁移。
You will see a summary of the migration process and here you can also see that a project is migrated successfully.
现在让我们使用以下命令查看目录结构。
Let us now see the directory structure by using the following command.
tree /f
你现在将在项目根目录中看到 *.csproj
文件以及 Program.cs
文件,而 project.json
已移动到备份文件夹。
You will now see the *.csproj file along with Program.cs file in the project root directory and project.json is moved to the backup folder.
让我们打开 ` console.csproj ` 文件。现在,你可以通过运行以下命令使用 MSBuild 系统还原并构建此项目。
Let us open the console.csproj file. Now you can restore and build this project using the MSBuild system by running the following command.
dotnet restore
你现在可以看到所有软件包已还原。
You can now see that all the packages are restored.
你现在可以使用以下命令构建你的项目。
You can now build your project with the following command.
dotnet build
现在你可以看到项目已使用 MSBuild 成功构建,且 ..\bin\Debug\netcoreapp1.0 文件夹中也生成了 console.dll。
You can now see that the project is built successfully using MSBuild and console.dll is also generated in ..\bin\Debug\netcoreapp1.0 folder.
以下屏幕截图显示了目录结构和文件。
The following screenshot shows the directory structure and files.