question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet restore fails to resolve local dependencies with a certain folder structure

See original GitHub issue

Steps to reproduce

  1. Create folder testlib and testapp under the same directory

  2. Inside testlib run dotnet new

  3. Inside project.json change the frameworks from netcoreapp1.0 to netstandard1.5

  4. Create folder src inside testlib

  5. Move Program.cs and project.json inside src

  6. Create global.json (not inside src) with contents

    {
        "projects": ["src"]
    }
    
  7. Inside testlib run dotnet restore

  8. Inside testlib/src run dotnet build

  9. Now inside testapp run dotnet new

  10. Create global.json with contents

    {
        "projects": [".", "../testlib"]
    }
    
  11. Inside project.json add testlib as a dependency

    "testlib": {
      "target": "project",
      "version": "1.0.0"
    }
    
  12. Now run dotnet restore

Directory structure should look like

testlib
  global.json
  /src
    /bin
    /obj
    Program.cs
    project.json
    project.lock.json
testapp
  global.json
  Program.cs
  project.json

This also might be related to dotnet/sdk#6211

Expected behavior

dotnet restore restores dependencies including the local project testlib

Actual behavior

dotnet restore is unable to resolve the local dependecty testlib Example output

C:\Users\Sanders\testapp
#! dotnet restore
log  : Restoring packages for C:\Users\Sanders\testapp\project.json...
info :   CACHE https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json
info :   CACHE https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json
error: Unable to resolve 'testlib (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
info : Committing restore...
log  : Lock file has not changed. Skipping lock file write. Path: C:\Users\Sanders\testapp\project.lock.json
log  : C:\Users\Sanders\testapp\project.json
log  : Restore failed in 656ms.

Errors in C:\Users\Sanders\testapp\project.json
    Unable to resolve 'testlib (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.

NuGet Config files used:
    C:\Users\Sanders\AppData\Roaming\NuGet\NuGet.Config
    C:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    https://api.nuget.org/v3/index.json
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview1-002702)

Product Information:
 Version:     1.0.0-preview1-002702
 Commit Sha:  6cde21225e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14342
 OS Platform: Windows
 RID:         win10-x64

Workaround steps

  1. Inside testlib rename src folder to testlib
  2. Inside global.json change “src” to “testlib” (this step doesn’t seem to matter as dotnet restore seems to ignore global.json)
  3. Inside testapp create folder src
  4. Move project.json and Program.cs inside src
  5. Run dotnet restore
  6. dotnet restore can now find and restore testlib

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
emgartencommented, May 23, 2016

This is expected, global.json needs to be in a parent folder.

0reactions
TheRealPiotrPcommented, May 26, 2016

@golf1052 for project-to-project references to work the projects must be in the domain of a single global.json. It is the global.json that describes where peer projects can be found. Please restructure your projects like this:


global.json
/src
  /testlib
    ~~global.json~~
    /bin
    /obj
    Program.cs
    project.json
    project.lock.json
  /testapp
    ~~global.json~~
    Program.cs
    project.json
Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet restore fails to resolve local dependencies with a ...
Workaround steps. Inside testlib rename src folder to testlib; Inside global.json change "src" to "testlib" (this step doesn't seem ...
Read more >
Dotnet restore from local folder Net Core
Package Restore feature will install all referenced packages before a project is built, thereby ensuring that all dependencies are available to ...
Read more >
dotnet restore command - .NET CLI
Learn how to restore dependencies and project-specific tools with the dotnet restore command.
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
This article focuses on common errors when restoring packages and steps to resolve them. Package Restore tries to install all package ...
Read more >
NuGet Package Restore
NuGet Package Restore restores all of a project's dependencies that are listed in either a project file or a packages.config file. You can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found