Sdk: Migrating a pure dotnet-core project does not create a solution

Created on 15 Feb 2017  ยท  7Comments  ยท  Source: dotnet/sdk

Steps to reproduce

dotnet migrate on a project that only contains project.json projects (example)

Expected behavior

The projects are migrated to csproj and a solution is created OR the tool chain allows multiple projects to be specified as before.

Actual behavior

The projects are migrated, but a solution is not created. This means there is no easy way to restore and build, since dotnet restore only allows you to specify one project at a time and dotnet build seems to want a solution now instead of searching for projects. Perhaps I missed a communication?

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc4-004771)

Product Information:
 Version:            1.0.0-rc4-004771
 Commit SHA-1 hash:  4228198f0e

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         ubuntu.14.04-x64
 Base Path:   /opt/dotnet/sdk/1.0.0-rc4-004771

Most helpful comment

Luckily, you no longer need to hack one together manually ๐Ÿ˜„ ๐ŸŽ‰

MacBook-Pro:foobar martin$ dotnet new solution
Content generation time: 20.3027 ms
The template "Solution File" created successfully.
MacBook-Pro:foobar martin$ dotnet sln add **/*.csproj
Project `app1/app1.csproj` added to the solution.
Project `app2/app2.csproj` added to the solution.

All 7 comments

@nlowe great suggestion!

For the time being, your scenario should still work. When we migrate multiple related project.json projects we wire up appropriate references between them. That allows you to go to the root project, the one no other project depends on, and restore and build it. The tools are smart enough to determine that dependencies of that project also need to be restored & built and they do that automatically!

I'm putting the suggestion in 2.0.0 milestone. This would be cool to provide, at least as an option.

Correct, but I still have to do something like find . -type f -name '*.csproj' -exec dotnet restore {} \; whereas previously I could just issue dotnet restore from the project root. I can adapt build scripts (cake), but I still feel this is a loss of functionality.

Additionally, it seems dotnet build **/*.csproj no longer works. IIRC you used to be able to dotnet build **/project.json.

From what I understand, creating a solution should resolve this, but unless you hack one together manually I think you need to use Visual Studio (not available on linux) or Jetbrains Rider or something similar

Luckily, you no longer need to hack one together manually ๐Ÿ˜„ ๐ŸŽ‰

MacBook-Pro:foobar martin$ dotnet new solution
Content generation time: 20.3027 ms
The template "Solution File" created successfully.
MacBook-Pro:foobar martin$ dotnet sln add **/*.csproj
Project `app1/app1.csproj` added to the solution.
Project `app2/app2.csproj` added to the solution.

Is file globbing broken in linux?

[nathan@nathan-arch netcore-multiproject]$ dotnet sln add **/*.csproj
Project `**/*.csproj` does not exist.
.NET Add project(s) to a solution file Command

Usage: dotnet sln <SLN_FILE> add [options] [args]

Arguments:
  <SLN_FILE>  Solution file to operate on. If not specified, the command will search the current directory for one.

Options:
  -h|--help  Show help information

Additional Arguments:
 Add a specified project(s) to the solution.

[nathan@nathan-arch netcore-multiproject]$ tree
.
โ”œโ”€โ”€ backup
โ”‚ย ย  โ”œโ”€โ”€ global.json
โ”‚ย ย  โ”œโ”€โ”€ src
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ project.json
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject.Types
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject.Types.csproj
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ obj
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject.Types.csproj.nuget.g.props
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject.Types.csproj.nuget.g.targets
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ project.assets.json
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ project.json
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ MyProject.Web
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ project.json
โ”‚ย ย  โ””โ”€โ”€ test
โ”‚ย ย      โ””โ”€โ”€ MyProject.Tests
โ”‚ย ย          โ””โ”€โ”€ project.json
โ”œโ”€โ”€ build.cake
โ”œโ”€โ”€ build.ps1
โ”œโ”€โ”€ build.sh
โ”œโ”€โ”€ netcore-multiproject.sln
โ”œโ”€โ”€ src
โ”‚ย ย  โ”œโ”€โ”€ MyProject
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject.csproj
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Program.cs
โ”‚ย ย  โ”œโ”€โ”€ MyProject.Types
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Library.cs
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ MyProject.Types.csproj
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ obj
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ MyProject.Types.csproj.nuget.g.props
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ MyProject.Types.csproj.nuget.g.targets
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ project.assets.json
โ”‚ย ย  โ””โ”€โ”€ MyProject.Web
โ”‚ย ย      โ”œโ”€โ”€ bower.json
โ”‚ย ย      โ”œโ”€โ”€ Controllers
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ TestController.cs
โ”‚ย ย      โ”œโ”€โ”€ MyProject.Web.csproj
โ”‚ย ย      โ”œโ”€โ”€ package.json
โ”‚ย ย      โ”œโ”€โ”€ Program.cs
โ”‚ย ย      โ”œโ”€โ”€ Properties
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ launchSettings.json
โ”‚ย ย      โ”œโ”€โ”€ README.md
โ”‚ย ย      โ”œโ”€โ”€ Startup.cs
โ”‚ย ย      โ”œโ”€โ”€ Views
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ Shared
โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ _Layout.cshtml
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ Test
โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Index.cshtml
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ _ViewStart.cshtml
โ”‚ย ย      โ””โ”€โ”€ web.config
โ”œโ”€โ”€ test
โ”‚ย ย  โ””โ”€โ”€ MyProject.Tests
โ”‚ย ย      โ”œโ”€โ”€ MyProject.Tests.csproj
โ”‚ย ย      โ””โ”€โ”€ Tests.cs
โ””โ”€โ”€ tools
    โ””โ”€โ”€ nuget.exe

21 directories, 35 files

EDIT: I also tried dotnet sln netcore-multiproject.sln add **/*.csproj as suggested by the error message, same result.

This worked however:

[nathan@nathan-arch netcore-multiproject]$ find . -type f -name '*.csproj' -exec dotnet sln add {} \;
Project `backup/src/MyProject.Types/MyProject.Types.csproj` added to the solution.
Project `test/MyProject.Tests/MyProject.Tests.csproj` added to the solution.
Project `src/MyProject/MyProject.csproj` added to the solution.
Project `src/MyProject.Types/MyProject.Types.csproj` added to the solution.
Project `src/MyProject.Web/MyProject.Web.csproj` added to the solution.

Also, should the solution file really be marked executable?

-rwxr--r--  1 nathan nathan 5.5K Feb 15 14:42 netcore-multiproject.sln

The executable thing is a standing issue with .net.. there are issues both on the cli and corefx for it.

Globbing should be done by the shell here so it probably depends on the shell version and settings (bash 3.2.57(1) on Mac OS in my case).
So you could also do it via find . -type f -name '*.csproj' -exec dotnet sln add {} \;

This issue was moved to dotnet/cli-migrate#24

Was this page helpful?
0 / 5 - 0 ratings