Search code examples
visual-studioasp.net-corevisual-studio-codeproject.jsonsln-file

Add a project.json based project to a .sln file without using Visual Studio


We have developers that are using VS Code on Linux, Windows, and Mac. We also have developers that are using full Visual Studio on Windows. A problem arises when the former (including me) do not add their projects to the solution, and the latter therefor do not see the projects in the solution.

How can developers add their project.json projects to a sln without having to open Visual Studio?


Solution

  • Nowadays .NET Core SDK allows working with sln files.

    Imagine you have a root folder for the solution. All the projects are located under src and test folders.

    Then from the solution folder run something like this:

    dotnet sln add ./src/Insurance.Domain/Insurance.Domain.csproj
    dotnet sln add ./test/Insurance.Domain.Tests/Insurance.Domain.Tests.csproj
    

    You can list the projects in the solution runing

    dotnet sln list
    

    Note: The solution provided above is not going to work with project.json files. Anyway project.json format is obsolete now and you can easilty migrage to csprojs with the latest SDK. Just run in your project folder:

    dotnet migrate
    

    and you are good to go.