There isn't a way to directly install a single .nupkg
package. NuGet can only install and restore from feeds, so you'll need to add the directory where the package is in as a feed.
To do this, add a NuGet.Config
file that adds the location of the directory as a feed, so you don't have to add the source parameter to each NuGet-related command (especially dotnet restore
):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="local-packages" value="../foo/bin/Debug" />
</packageSources>
</configuration>
Alternatively in .NET Core 2.0 tools / NuGet 4.3.0, you could also add the source directly to the .csproj file that is supposed to consume the NuGet feed:
<PropertyGroup>
<RestoreSources>$(RestoreSources);../foo/bin/Debug;https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
This will make all commands be able to use the package:
dotnet add package foo
(optionally add -v 1.0.0
)
dotnet restore
dotnet run
dotnet add package foo
will add a package reference (assumption here, version 1.0.0
) to *.csproj
:
<ItemGroup>
+ <PackageReference Include="foo" Version="1.0.0" />
</ItemGroup>
Note that during development, if you change the NuGet package, but don't increment its version in both the project that produces the .nupkg file and in the project that consumes it, you'll need to clear your local packages cache before restoring again:
dotnet nuget locals all --clear
dotnet restore
I have created a small example project at https://github.com/dasMulli/LocalNupkgExample
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…