We use a custom location for our packages folder which we specify in a nuget.config file in the same folder as our solution:
<settings>
<repositoryPath>..\..\lib\packages</repositoryPath>
</settings>
Visual Studio 2013 picks this up fine and the NuGet package manager installs packages into the specified folder, lists installed packages correctly, etc.
In Visual Studio 2015 RC the NuGet package manager pops up the "Some packages are missing from this solution, click here to restore" message and if I click the button it creates a new packages folder in the same folder as the solution rather than using the location specified in the nuget.config. Installing a completely new package also puts it into a packages folder under the solution folder rather than the specified one.
How do I get Visual Studio 2015 RC to respect the repository path specified in the nuget.config?
Make sure your nuget.config is configured like this:
<configuration>
<config>
<add key="repositoryPath" value="..\..\lib\packages" />
</config>
</configuration>
I filed this bug with NuGet: https://github.com/NuGet/Home/issues/626
A fix has been made but I'm not sure when it will be released.
Related
I have published a library on Azure Artifcats Feed. I can install this dll using visual studio NuGet Package Manager manually. But using NuGet.config, I can't install the package automatically. The ' Allow NuGet to download missing packages' is checked. The folder structure of the published library is like this:
lib/
net40/my_libr.dll
my_lib.dll
My nuget.config is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- remove any machine-wide sources with <clear/> -->
<clear />
<!-- add an Azure Artifacts feed -->
<add key="CCC-FEED" value="https://pkgs.dev.azure.com/<org>/_packaging/<feed>/nuget/v3/index.json" />
<!-- also get packages from the NuGet Gallery -->
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
My project that is trying to use this lib is targeting net40. Am I doing anything wrong?
EDIT1
My solution has two projects: one is using net35, and the other is using net40. I trying to install the library into the project net40
EDIT2
packages are installed and put in the packages folder in the root folder (besides the .sln file). But the dlls are not put in the bin folder.
EDIT3
This project was originally created using visual studio 2013
You could try to remove all packages and NuGet.config file, then use NuGet Package Manager to install the packages. When you install a package, NuGet records the dependency in either your project file or a packages.config file (depending on the project format).
In Solution Explorer, right-click either References or a project and select Manage NuGet Packages..
Make sure you have added the package source (Azure Artifcats Feed) in the NuGet Package Manager settings.
Select the package and install it.
Useful links:
https://learn.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio
https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio#package-sources
There is no more packages solution folder in any csproj or project.json-based .NET Core project.
NuGet CLI gets the list of used cache folders:
nuget locals all -list
Response:
http-cache: C:\Users\<foo>\AppData\Local\NuGet\v3-cache
global-packages: C:\Users\<foo>\.nuget\packages\
temp: C:\Users\<foo>\AppData\Local\Temp\NuGetScratch
How to change or override these locations?
Cache locations
Solution-local packages folders are no longer exist for .NET Core and Visual Studio 2017.
NuGet is now fully integrated into MSBuild:
Solution-local packages folders are no longer used – Packages are now
resolved against the user’s cache at %userdata%.nuget, rather than a
solution specific packages folder. This makes PackageReference perform
faster and consume less disk space by using a shared folder of
packages on your workstation.
NuGet 4.0+ uses at least two global package locations:
User-specific: %userprofile%\.nuget\packages\
Machine-wide: %ProgramFiles(x86)%\Microsoft SDKs\NuGetPackages\"
You can list all user-specific folders using the following console command:
nuget locals all -list
Notice that the machine-wide folder isn't listed there. However, it is defined at Visual Studio settings:
Options -> NuGet Package Manager -> Package Sources
Configuration files
NuGet.config files are located here:
User-specific: %APPDATA%\NuGet\
Machine-wide: %ProgramFiles(x86)%\NuGet\Config\
It is possible to change and override NuGet settings at many levels:
project
solution
user
machine
And even more! Read more about NuGet.config hierarchical priority ordering here: How settings are applied.
For example, globalPackagesFolder parameter changes a package cache location. Look at this NuGet.config example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<clear />
<add key="globalPackagesFolder" value="c:\packages" />
</config>
</configuration>
From the MS docs:
global‑packages
Windows: %userprofile%\.nuget\packages
Mac/Linux: ~/.nuget/packages
Override using the NUGET_PACKAGES environment variable, the globalPackagesFolder or repositoryPath configuration settings (when using PackageReference and packages.config, respectively), or the RestorePackagesPath MSBuild property (MSBuild only). The environment variable takes precedence over the configuration setting.
Copying the .nuget folder (c:\users{username}.nuget) from the development pc which has an internet connection and the updated packages, to the pc which doesn't have the internet connection also worked for me.
Are packages now cached in a more shared location somewhere or what?
My solution folder is devoid of any packages folder:
Per project: References->Nuget dictates what packages are referenced and restored. But, as Eastrall mentioned, the packages folder is now global and located in your user folder: C:\Users\[YourUsername]\.nuget\packages
To force ./packages folder for Solution
To force download of packages folder to be a child of the solution folder for .NET Core projects, follow these steps:
Create a NuGet.Config file in the same directory as the .sln file.
Copy the following contents into the NuGet.Config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value=".\packages" />
</config>
</configuration>
Configure NuGet to download missing packages by:
3.1. In Visual Studio: Tools -> Options
3.2. Filter by nuget (top left in dialog). Select General
3.3. Ensure Allow NuGet to download missing packages is checked
Close and re-open the solution. NuGet will download the required packages.
Note: the NuGet.Config configuration can also be achieved by executing the following command from the NuGet Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console):
PM> nuget config -set globalPackagesFolder=.\packages -configfile "$(pwd)\NuGet.Config"
You still have packages folder in your .NET Core solution, but the global packages are located at: C:\Users\[YourUsername]\.nuget\packages
You can check out a question I asked to see if the answers do you any good.
How do I include NuGet packages in my solution for .Net Core projects?
You can get that packages folder back, but you might not be happy with the results, since .Net Core projects rely on so many NuGet packages. Mine is hovering around 1 GB.
https://learn.microsoft.com/en-us/nuget/schema/nuget-config-file#config-section
I have a problem with HtmlAgilityPack. I found solution to that problem which is changing reference to another assembly (Why can't I use htmlagilitypack with windows phone 8? What else can I use to Parse HTML in WP8?).
The problem I have that I cannot change path of the package as it is greyed out. The picture bellow shows it.
It's now possible to control which folder the packages are installed into.
http://nuget.codeplex.com/workitem/215
See Phil Haack's comment on Dec 10 2010 at 11:45 PM (in the work item/the link above). The support is partially implemented in 1.0, but is not documented.
According to #dfowler: Add a nuget.config file next to the solution with this:
{some path here}
There is a nuget package for creating the package folder override.
Update for version 2.1
There is now official documentation on how to control the package locations. The release notes for 2.1 specifies the following configuration in a nuget.config file (see the release notes for a description of valid places to put the config files and how the hierarchical configuration model works):
<configuration>
<config>
<add key="repositoryPath" value="C:\thePathToMyPackagesFolder" />
</config>
...
</configuration>
This would change the packages folder for the configuration level you put the file in (solution if you put it in the solution directory, project in project directory and so on). Note that the release notes state:
If you have an existing packages folder underneath your solution root, you will need to delete it before NuGet will place packages in the new location.
I have a class library project which is reused across different solutions.
I would like NuGet to add a toolkit reference to the class library project and store it in the project folder not in the solution folder.
Example:
I have
D:\Projects\MyClassLibrary
D:\Projects\Solution1
D:\Projects\Solution2
Using NuGet, I want to add a toolkit to the MyClassLibrary project.
Right now, if I have Solution1 open, NuGet is adding the toolkit to
D:\Projects\Solution1\packages
I would like to tell NuGet to install the toolkit in the MyClassLibrary\packages folder instead.
How to do this?
You can change the default packages folder location since nuget 2.1:
<configuration>
<config>
<add key=" repositoryPath" value=" C:\myteam\teampackages" />
</config>
...
</configuration>
reference: Specify ‘packages’ Folder Location
-----------------UPDATE-------------------------
you have to enable nuget automatic package restore for the solution.
When you do it nuget create a .nuget folder in the solution root.
Inside that folder there are the file NuGet.Config where you can put this configuration.
-----------------(last) UPDATE 2020-------------------------
nuget has changed since and this answer does not apply anymore