Visual studio can't restore packages from Azure Artifcats Feed - nuget

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

Related

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

which is good approach to create nuget packages?

As I developer I wonder which is the best approch to create a nuget packages ?
1.NuGet Package Project (link)
2.Use Nuget.exe use .Nuspec (add manually and update manually)
Anyone guide on this.
Currently I'm using nuget.exe and .Nuspec but problem is everytime I have to manually update .nuspec if any new project is added.
Is there any other good options to do so ?
You can also build a NuGet package by running the nuget pack command against the csproj file. More information can be found here: Creating And Publishing A Package
Create nuget package in the following manner
Download nuget.exe from here https://www.nuget.org/
Create empty spec file (execute below command under project root folder)
nuget spec
Update nuget spec file SomeLib.nuspec according to your library properties(use any text editor)
Create some folders nugetPack/lib/net46/ and then paste the dll here; which you want to make as nuget package
Create nuget package (execute below command under project root folder)
nuget pack -basepath nugetPack SomeLib.nuspec
Now use this nuget package in your project
Set the nuget package source which you have created
Goto Visual Studio > Tool > NuGet Package Manager > Package Sources > here add your nuget package source folder path
Right click and select managae nuget packages on the project where you want to consume nuget package.
Select the right package source from the top right drop down box.
search your nuget package and install.
Another cool way to create nuget package via NuGet Package Explorer
which you can download it from here https://npe.codeplex.com/ then just simply fill the form and save the nuspec file to your local nuget package source folder.
Sample nuspec file whihc has some dependencies
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>your.package.name</id>
<version>1.0.0</version>
<title>package title</title>
<authors>NG</authors>
<owners>NG</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>some description</description>
<summary>some summary</summary>
<copyright>open</copyright>
<language>en-US</language>
<tags>your package keyboards</tags>
<dependencies>
<dependency id="Microsoft.AspNet.WebApi.Core" version="5.2.3" />
<dependency id="Microsoft.AspNet.WebApi.Client" version="5.2.3" />
<dependency id="Newtonsoft.Json" version="9.0.1" />
</dependencies>
</metadata>
</package>
Github README
I'm new to developing nuget packages, (and posting on Stack Overflow). I started using the nuget.exe command-line approach, which I learned about: here. But from what I've gathered so far, there is a convention of using .NET Standard, instead of .NET Framework when developing nuget packages. Especially on nuget.org. So, when developing a .NET Standard class library, check out the project properties under the project tab in Visual Studio. There you will see multiple tabs on the left, starting with build. Click on the Package tab. Now you'll see a great way to enter all properties that you would normally have to do manually when trying to create the .nuspec file. You'll want to be sure to fill it out completely to avoid flags when uploading to nuget or wherever. Create your repository and file in github, and enter their URLs. Also, imgur.com is a great place to host your icon image. Be sure to click the Generate Nuget Package checkbox. Voila! Now build your library and you'll notice a .nupkg file. This is the best resource.

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

Is there a way to download packages from nuget.org then do an offline installation into Visual Studio?

My visual studio is installed on a machine which doesn't have internet connection so I can't download and install packages from NuGet Manager in VS.
So I am looking for a way to use another machine which has internet connection to download packages and then install on VS.
First, download the .nupkg file:
Follow the instructions at How to download a Nuget package without nuget.exe or Visual Studio extension?
Or use my Google Chrome extension NuTake
Secondly, install the .nupkg file into your project
Follow instructions at How to install a Nuget Package .nupkg file locally?
You can use the NuGet Package Explorer to download packages outside VS.
https://npe.codeplex.com/
https://npe.codeplex.com/releases/
https://github.com/NuGetPackageExplorer/NuGetPackageExplorer
Alternatively to proposed answers, you can:
Build solution to restore packages (online).
Refer to the packages folder in your NuGet.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="Offline packages" value="offline-packages" />
</packageSources>
</configuration>
NOTE that:
NuGet.config should be in the same directory as your solution (*.sln) file.
If you want to push packages to the repository, rename directory or remove **/packages/* from the .gitignore.
In the above example, packages are moved to the offline-packages directory.