I have some .nupkg files from a C# book. How can I install them?
相关问题
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
- Visual Studio 2019 - error MSB8020: The build tool
- 'System.Threading.ThreadAbortException' in
- VS2017 RC - The following error occurred when tryi
相关文章
- dotnet restore还原nuget包时无法加载 https://api.nuget.org/
- How to show location of errors, references to memb
- How to track MongoDB requests from a console appli
- Visual Studio Hangs on Loading UI Library
- How to use Mercurial from Visual Studio 2010?
- Copy different file to output directory for releas
- Edit & Continue doesn't work
- “Csc.exe” exited with code -1073741819
For Visual Studio 2017 and its new .csproj format
You can no longer just use Install-Package to point to a local file. (That's likely because the
PackageReference
element doesn't support file paths; it only allows you to specify the package's Id.)You first have to tell Visual Studio about the location of your package, and then you can add it to a project. What most people do is go into the NuGet Package Manager and add the local folder as a source (menu Tools → Options → NuGet Package Manager → Package Sources). But that means your dependency's location isn't committed (to version-control) with the rest of your codebase.
Local NuGet packages using a relative path
This will add a package source that only applies to a specific solution, and you can use relative paths.
You need to create a
nuget.config
file in the same directory as your.sln
file. Configure the file with the package source(s) you want. When you next open the solution in Visual Studio 2017, any .nupkg files from those source folders will be available. (You'll see the source(s) listed in the Package Manager, and you'll find the packages on the "Browse" tab when you're managing packages for a project.)Here's an example
nuget.config
to get you started:Backstory
My use case for this functionality is that I have multiple instances of a single code repository on my machine. There's a shared library within the codebase that's published/deployed as a .nupkg file. This approach allows the various dependent solutions throughout our codebase to use the package within the same repository instance. Also, someone with a fresh install of Visual Studio 2017 can just checkout the code wherever they want, and the dependent solutions will successfully restore and build.
You can also use the Package Manager Console and invoke the
Install-Package
cmdlet by specifying the path to the directory that contains the package file in the-Source
parameter: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, right click and select "Manage NuGet Packages" and select your new package source.
Here is the documentation.
Create a file called NuGet.config next to your solution file with the following contents
If the solution is open in Visual Studio, close it, then re-open it.
Now your packages should appear in the browser, or be installable using Install-Package
If you have a .nupkg file and just need the .dll file all you have to do is change the extension to .zip and find the lib directory.
For .nupkg files I like to use: