Convert a project.json to a csproj without using V

2019-04-04 02:43发布

问题:

As of preview3 dotnet new produces a csproj, and both dotnet restore and dotnet build fail against a project.json and/or an xproj.

For instance, running dotnet restore against a directory that has both a project.json and an xproj gives this error.

...xproj(7,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.0-preview3-004056\Extensions\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

Further, running it against a directory that has only a project.json gives this error.

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

Without using Visual Studio, how can we convert an existing project.json and/or xproj to a csproj?

回答1:

There is a dotnet migrate command.

The dotnet migrate command will migrate a valid Preview 2 project.json based project to a valid Preview 3 csproj project.

We can find detailed help on this command by running dotnet migrate -h (even though dotnet -h does not list the command).