Yoann
Yoann

Reputation: 576

Resolving dependencies using restore and build

I have several questions related to project.json, dependencies and the use of dotnet restore :

  1. Where are located the packages when doing dotnet restore according to dependencies declared in project.json?
  2. I have seen that one can dotnet restore --packages "myPackagesPath thus specifying where to locate its packages, but how can `dotnet build' knows where to fetch the dependencies afterwards? I have not seen any part of the project.json that specifies it.
  3. is project.json the way to go when creating new project in dotnet core?

Upvotes: 2

Views: 189

Answers (2)

jschmitter
jschmitter

Reputation: 1939

Answering question 2 (since @CaptainMat answered the others):

Running dotnet restore with the --packages parameter will create a file at <Your.Dotnet.Project.Directory>/obj/project.nuget.cache. The project.nuget.cache file contains the paths where each package was saved during restore. So dotnet build presumably reads project.nuget.cache to find where it was saved.

The contents of the file looks something like this:

{
  "version": 2,
  "dgSpecHash": "cb5yhEzNUCTzbh1NqPX+bh8d9KsTks7Z1nVUC7nCSTjMjwyYc5Rlwj7TSx1njWRrykjnltRBMw5id0Qu1F0UEQ==",
  "success": true,
  "projectFilePath": "/Users/josh/myRepo/src/coffee/lightroast/src/lightroast.WebApi/lightroast.WebApi.csproj",
  "expectedPackageFiles": [
    "/Users/josh/myRepo/src/coffee/lightroast/packages/azure.core/1.35.0/azure.core.1.35.0.nupkg.sha512",
    "/Users/josh/myRepo/src/coffee/lightroast/packages/azure.data.appconfiguration/1.2.0/azure.data.appconfiguration.1.2.0.nupkg.sha512",
    "/Users/josh/myRepo/src/coffee/lightroast/packages/azure.extensions.aspnetcore.configuration.secrets/1.2.1/azure.extensions.aspnetcore.configuration.secrets.1.2.1.nupkg.sha512",
    "/Users/josh/myRepo/src/coffee/lightroast/packages/azure.identity/1.10.1/azure.identity.1.10.1.nupkg.sha512",
    "..."
  ]
}

Upvotes: 0

CaptainMat
CaptainMat

Reputation: 148

1: depending on your OS, it is in $USERDIR/.nuget/packages/

2: sorry, no idea on this one

3: yes, try it by doing: dotnet new it'll create a project.json

Upvotes: 1

Related Questions