Add a package with a local package file in 'dotnet'
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
dotnet pack ouput and Visual Studio's local package source
Here's how I handle packages locally in my development environment:
Step 1: Set up a local NuGet source. You need a copy of the NuGet CLI if you don't already have it. Follow the instructions on creating a local NuGet feed: basically, create an empty folder. I chose C:\Users\Nate\Documents\LocalNuget
.
Step 2: Add packages to the local source with nuget add [file] -source [folder]
. I added an environment variable called local_nuget_path
that pointed to the folder so I wouldn't have to type it all the time:
> setx local_nuget_path "C:\Users\<you>\Documents\LocalNuget"
For even more convenience, I wrote a simple PowerShell cmdlet to add packages automatically:
nuget-functions.ps1
Function Nuget-AddLocal {
Param([string]$file)
nuget add $file -Source $env:local_nuget_path
}
Function Nuget-AddAllLocal {
Param([string]$path)
Get-ChildItem $path -Recurse -Filter *.nupkg | `
Foreach-Object {
Nuget-AddLocal $_.FullName
}
}
Add this to your PowerShell profile so it is available in every console window:
> notepad $profile
Add this line to profile.ps1
(substituting the real path of the file):
. C:\Users\<you>\Documents\nuget-functions.ps1
Step 3: Add the local source to NuGet as a feed.
> nuget sources add -Name Local -Source $env:local_nuget_path
Step 4: Profit!
Produce packages and add them to your local source in two simple steps:
> dotnet pack
> Nuget-AddAllLocal
How do I install a NuGet package .nupkg file locally?
Menu Tools → Options → Package Manager
Give a name and folder location. Click OK. Drop your NuGet package files in that folder.
Go to your Project in Solution Explorer, right click and select "Manage NuGet Packages". Select your new package source.
Here is the documentation.
Install .nupkg locally on macOS using dotnet or nuget
Try this one
dotnet add package A.B -s "<here_your_path_to_nupkg>"
Or add local source like
nuget sources add -name FeedName -Source "<here_your_path_to_nupkg>"
then
dotnet add package A.B -s FeedName
How to make local nuget packages and refference them across solutions locally in dotnet core
This is the result of what I came up with, maybe someone have a better way.
https://twitter.com/pksorensen/status/761590754301079552
https://gist.github.com/pksorensen/df61ded634bad99f85cc68f91c230361
"scripts": {
"postcompile": [
"nuget delete -Verbosity detailed -noninteractive -source %USERPROFILE%\\.nuget\\packages %project:name% %project:version%",
"nuget delete -Verbosity detailed -noninteractive -source c:\\localpackages %project:name% %project:version%",
"dotnet pack --no-build --configuration %compile:Configuration% -o ../../artifacts/",
"nuget add -Verbosity detailed -NonInteractive -source c:\\localpackages ../../artifacts/%project:name%.%project:version%.nupkg"
]
}
Using local feeds I added a feed according to : https://docs.nuget.org/create/hosting-your-own-nuget-feeds
at c:\localpackages.
- Then on each build I pack and push the package to this local source
- To do so i also must delete the same version if its already there (one of the delete).
- Due to nuget also caches packages in the user folder global folder, it must also be deleted there.
When the build completes, i simply can right click and restore packages in the solutions that depends on these local packages.
When the issue is fixed, its simply to commit both solutions to the CI system again and it will resolve packages from the normal feed rather than the local feed that is only available on my dev machine.
Related Topics
Correct Way to Get the Coredispatcher in a Windows Store App
Log4Net, How to Add a Custom Field to My Logging
Entity Framework Core Using Multiple Dbcontexts
Xml Parsing - Read a Simple Xml File and Retrieve Values
How to Display a Windows Form in Full Screen on Top of the Taskbar
How to Find the Assembly System.Web.Extensions Dll
How to Fill Forms and Submit with Webclient in C#
How to Get the Available Wifi Aps and Their Signal Strength in .Net
What Is the Command to Exit a Console Application in C#
Wcf Gives an Unsecured or Incorrectly Secured Fault Error
Reading the Registry and Wow6432Node Key
Differencebetween Streamwriter.Flush() and Streamwriter.Close()
String Format Numbers Thousands 123K, Millions 123M, Billions 123B