Search code examples
c#dependenciesnugetclass-librarydotnet-cli

Depend on local C# project


I have two C# projects in the same directory.

.
├── MyLib
│   ├── MyLib.cs
│   ├── MyLib.csproj
│   └── bin
│       └── Debug
│           └── netstandard2.0
│               ├── MyLib.deps.json
│               ├── MyLib.dll
│               └── MyLib.pdb
└── MyApp
    ├── Program.cs
    ├── MyApp.csproj
    └── bin
        └── Debug
            └── netcoreapp2.2
                ├── MyApp.deps.json
                ├── MyApp.dll
                ├── MyApp.pdb
                ├── MyApp.runtimeconfig.dev.json
                └── MyApp.runtimeconfig.json

I would like MyApp to be able to access the classes etc. defined in MyLib.

How do I do that?

I have tried from MyApp

dotnet add package ../MyLib/MyLib.csproj
dotnet add package MyLib --source ../MyLib/bin/Debug

after dotnet pack from MyLib.

None work because the package cannot be found in the source nuget.org.

What's the easiest way for me to simply depend on my local project?


Solution

  • Nearly there. Projects are added by reference -- https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference

    Try dotnet add reference ../MyLib/MyLib.csproj