t3chb0t
t3chb0t

Reputation: 18675

Restoring NuGet packages to the cache

I have a .net-core application that works on my machine but when I deploy it on another one, it complains about missing packages and points me to the TheApp.deps.json.


My theory is that on my machine the app looks for packages in some NuGet cache where they were probably installed by the IDE during development because the app's output-dir contains only a couple of internal dlls so the other nuget.org dependecies are definitely missing.

I'm building the app with

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>

and then xcopy it to the other machine.


Question

Is there a way to restore or install the missing packages to the cache on the target machine based on the *.deps.json file?

Upvotes: 2

Views: 1092

Answers (1)

Jamie Taylor
Jamie Taylor

Reputation: 1802

dotnet build (and the F5/Build function in Visual Studio) simply build the code that you have provided via your source files (i.e cs, fs, vb, etc.).

Whereas dotnet publish (and the Build > Publish function in Visual Studio) does a full package restore, builds your source code, and resolves any external dependencies before moving the output to a specific directory ready for publishing to another machine.

The description on the dotnet publish command documentation states:

dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory. The output includes the following assets:

  • Intermediate Language (IL) code in an assembly with a dll extension.
  • .deps.json file that includes all of the dependencies of the project.
  • .runtime.config.json file that specifies the shared runtime that the application expects, as well as other configuration options for the runtime (for example, garbage collection type).
  • The application's dependencies, which are copied from the NuGet cache into the output folder.

dotnet build is only really useful for building on your development machine, and when used in conjunction with dotnet run against a project file.

Upvotes: 1

Related Questions