If you’ve been using .NET Core for very long, you have code based on global.json and one or more project.json files. Several months (a year?) ago Microsoft announced deprecating this approach, and a return to Visual Studio Solution (.sln) and Project (.csproj, .fsproj, . vbproj, etc.) files. This transition also involves changing from directory based to file based orientation. For example, attempting dotnet build with the 1.0.1 toolset yields:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
Specifying a project.json file doesn’t work either; it yields:
error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
After upgrading to the toolset, migrating code involves a few steps:
- Create VS Solution file. The migration process is much easier if you create this file first. Using a shell (cmd, powershell, bash, etc.), change to the directory containing the project’s global.json and run dotnet create sln. The result is a (relatively) empty .sln file.
- Migrate project.json files to VS Project files. Run dotnet migrate in the same directory as above. This command will recursively find project.json files, convert them to C# project files, and add references to them in the solution file.
- At this point you should be able to restore and build using the .sln. Recall that dotnet tool is no longer directory oriented. Include the .sln file in the restore and build commands, e.g., dotnet build <project>.sln.