In Visual Studio Code, i would like to keep a local copy of a referenced Nuget package in the project folder for the case the package will not be available online for some reason in the future.
nuget restore shall still be able to download it from the internet if the local copy is not yet there.
I think thats exactly the behaviour with Visual Studio, but i can't get this running with Visual Studio Code
I think i found a solution myself.
Adding a file called nuget.config with the following content to the project folder does exactly what I wanted. The packages are now put into the local packages folder.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="packages" />
<add key="repositoryPath" value="packages" />
</config>
</configuration>
Related
I am trying to add packages from https://github.com/orgs/DKE-Data/packages to my asp.net project. Here are the things I have tried
Download the package.nupkg file and add the location to the package manager source but it does not allow me to install the package.
Add the PackageReference to .csproj file and did a restore - did not work
As these packages are publicly available isn't there a straight forward approach to add them to my packages?
Appreciate any help here!
In order to use this feed you need to configure it. I suggest creating a nuget.config file next your solution file (.sln) with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="github-DKE-Data" value="https://nuget.pkg.github.com/DKE-Data/index.json" />
</packageSources>
</configuration>
Then (maybe after re-opening the solution in visual studio or other IDEs) you should be able to add the pacakge via the NuGet UI or directly in the csproj file.
For more information on how to use GitHub packages for NuGet see Configuring dotnet CLI for use with GitHub Packages as you may need to set up authentication as well.
I'm having issue with visual studio 2017,
where new solution keeps referencing the Nuget.config file in unexpected location in 'C:\Users\yopa\AppData\Roaming\NuGet\Nuget.config'.
I've added '/.nuget/Nuget.config' file to my solutions folder.
However, the solution is still referencing the nuget configuration file in the 'C:\', and the nuget packages are being restored in 'C:\' package folder as well.
How do I configure my solution to honour package.config file in its directory?
I've tried deleting the nuget.config file in the roaming folder, but the solution re-creates the file when nuget package restore is done.
How do I configure my solution to honour package.config file in its directory?
To make sure your solution to honor the package.config file in the .nuget folder, you should configure this file correctly, for example, I created a test sample solution, then add a Nuget.config inside .nuget folder:
My NuGet.Config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="D:\Test" />
</config>
</configuration>
Then, another important info is remember restart Visual Studio after adding the Nuget.config file.
As test result, the nuget packages are being restored in 'D:\Test' package folder:
Looks like solution wide Nuget.config inside .nuget folder is no longer supported.
NuGet 3.3 and earlier used a .nuget folder for solution-wide settings. This file is not used in NuGet 3.4+.
Config file should be placed at the project level or any folder in the project path instead, check documentation for additional details
Configuring nuget behavior.
I am wondering where is NuGet.Config file located in Visual Studio 2017 project? I tried to create my own NuGet.Config file in the root of the project, but I didn't find any new repositories (NuGet sources). Does some one have any idea?
Here is the file I am trying to achieve for my .Net Core project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
<add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Visual Studio reads NuGet.Config files from the solution root. Try moving it there instead of placing it in the same folder as the project.
You can also place the file at %appdata%\NuGet\NuGet.Config and it will be used everywhere.
https://learn.microsoft.com/en-us/nuget/schema/nuget-config-file
There are multiple nuget packages read in the following order:
First the NuGetDefaults.Config file. You will find this in %ProgramFiles(x86)%\NuGet\Config.
The computer-level file.
The user-level file. You will find this in %APPDATA%\NuGet\nuget.config.
Any file named nuget.config beginning from the root of your drive up to the directory where nuget.exe is called.
The config file you specify in the -configfile option when calling nuget.exe
You can find more information here.
If you use proxy, you will have to edit the Nuget.config file.
In Windows 7 and 10, this file is in the path:
C:\Users\YouUser\AppData\Roaming\NuGet.
Include the setting:
<config>
<add key = "http_proxy" value = "http://Youproxy:8080" />
<add key = "http_proxy.user" value = "YouProxyUser" />
</config>
In addition to the accepted answer, I would like to add one info, that NuGet packages in Visual Studio 2017 are located in the project file itself. I.e., right click on the project -> edit, to find all package reference entries.
no matter where these files are here is a way to edit them via the dotnet CLI
verify 'file' to get current entries:
dotnet nuget list source
add new source:
dotnet nuget add source https://nuget.example.com -n SomeName
I am trying to change the default location of nuget packages
I have a nuget.config file in the same location as the solution file.
Its contents are
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="Lib" />
</config>
</configuration>
But the problem is still when I go to Manage Nuget Packages and click Restore, the libraries go to packages folder but not to lib folder.
This only happens to the WebAPI project file but not to any other projects in the same solution.
Any ideas why ?
Should any thing be changed to the web.config files ?
Turns out that after placing the nuget.config file, close and re-open the visual studio (restart it).
It will now read the nuget.config file and then will understand that it needs to download all the packages to the configured folder in the nuget.config file.
MY Task is to generate a NuGet package of one project containing static content and binaries. Then means by which this NuGet package can be consumed in another Project/ Solution.
I have completed the first half of the task where i was able to generate a NuGet package out of a project, but not sure how to consume this inside another project/ solution. I see only option of adding already published Projects from NuGet repository but not anything which is out there on file system/ hard drive.
Any help is appreciated.
Thanks in advance.
You need to add the directory which contains the package as a NuGet Package Source. In Visual Studio do the following
Tools -> Options
Package Manager -> Package Sources
Add the file system location and hit "Update"
After this the local package should appear in the Package Library Manager
If you are looking to change the NuGet.exe command line then create a Nuget.exe.config file and add the following
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="LocalName" value="path/to/your/package" />
</packageSources>
</configuration>