Lesson 10 / 26
Solutions and Project References
Organise an API, a class library and tests into one solution.
One solution, many projects
A solution file lets you build and test several projects together. A project reference makes one project use another's code, for example the API using a shared Core library.
Wire it together
Create three projects, group them in a solution and reference the library from the API and the tests.
dotnet new sln -n Shop
dotnet new classlib -o src/Shop.Core
dotnet new web -o src/Shop.Api
dotnet new xunit -o tests/Shop.Tests
dotnet sln add src/Shop.Core src/Shop.Api tests/Shop.Tests
dotnet add src/Shop.Api reference src/Shop.Core
dotnet add tests/Shop.Tests reference src/Shop.CoreAvoid circular references
Project A cannot reference B if B already references A. If you hit this, move the shared code into a third, lower-level project.
Quick check: What does `dotnet sln add` do?
- Adds a NuGet package
- Adds a project to the solution file
- Publishes the solution
- Adds a database
Answer
Adds a project to the solution file — It registers existing projects in the `.sln` so they build together.