Change path of a NuGet package - nuget

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.

Related

How can a project get its own NuGet package instead of using the one the solution uses?

I have a C# project, TrendMasterCS2, built in VS 2019 that uses a DLL, TrendData, that relies on System.Data.SQLite.Core, which I get through the NuGet Package Manager. I opened the TrendMasterCS2 sollutio and uninstalled all NuGet packages from both the executable project and the DLL project. Then, I added the System.Data.SQLite.Core package to the TrendData project. I saved all files, and then opened the project file in Notepad. I saw this:
<Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\TrendMasterCS2\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
This looks like a problem to me. If I ever want to use the TrendData DLL in some other solution, it's going to be carrying around this dependency on the TrendMaster2 folder. I think I can open TrendData by itself in VS2019 and add the NuGet package there, but is that what I have to do to ensure that TrendData is independent of TrendMasterCS2?
Consider to migrate from packages.config to PackageReference. (In Visual Studio, right click the packages.config and select Migrate packages.config to PackageReference...).
One benefit of PackageReference is that all packages will be restored to a global package cache directory and the tooling takes care of the actual reference path at compile time.
See https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference for details.
As an alternative you could create a nuget.config file and change the repositoryPath as described here: https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#packagerestore-section
However I did not get managed to store packages in a project-local path using nuget.config.

Output Directory of native dll bundled with NuGet

I am trying to build a NuGet package that includes native DLLs which are to be placed in the output folder when a project uses the package. I have tried to use the several suggestions from this question, but I am always running in the same problem.
My current NuGet package layout is like this:
\build
packageId.targets
file1.dll
file2.dll
\lib
\netstandard1.4
assembly.dll
The contents of packageId.targets is:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)\*.dll"/>
<None Include="#(NativeLibs)" Link="$(RecursiveDir)$(Filename)$(Extension)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
This should, according to the answers of the other questions, lead to my DLLs being placed in the bin\Debug directory of the project using the package. However, they are not. Instead, they are placed in bin\Debug\packages\packageId\build.
Now I have experimented a lot, and I noticed more and more strange behavior which I cannot make any sense of:
If I move the DLLs to the root of the NuGet package (like one answer suggests) and change the .targets file accordingly, they are not copied at all. There also is no error message.
If I change the .targets file to only reference file1.dll in both Include= and Link=, both files get copied anyway.
So I wondered if some policy just ignores the .targets file and copies whatever is in build to that path in the output folder, but when I remove the .targets file, the DLL files will not get copied anymore.
Now I understand even less what's happening.
What do I need to change to get the DLLs copied right into bin\Debug?
The new way to handle runtime-specific assents in NuGet is to use the runtimes folder to place native assets:
\lib
\netstandard2.0
ManagedWrapper.dll
\runtimes
\win-x86
\native
NativeThing.dll
\win-x64
\native
NativeThing.dll
\linux-x64
\native
libNativeThing.so
\osx-x64
\native
libNativeThing.dylib
If the package is consumed from a .NET Framework project, you may need to add a reference to the Microsoft.NETCore.Platforms package wich provides the runtime graph (runtimes.json) for NuGet to provide proper RID mappings if you don't use base RIDs (e.g. win10-x64 falls back to win-x64 resources).

Why isn't there any packages folder in my .NET Core solution's containing folder?

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

Can't specify nuget package folder location [duplicate]

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.

how to tell NuGet to install package per project and not solution

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