Installing private feed Nuget packages from packages.config - nuget

I have a private nuget feed on one of our internal servers.
I can install packages in this feed from command line like this
nuget install "PackageName" -source "\\DevServer\NugetFeed"
However if I try to install the packages from our packages.config file like this
nuget install "MyProject\Packages.config" -source "\\DevServer\NugetFeed"
It errors with can't find package for each of the packages in my packages.config file. It looks like it's ignoring the -Source switch and looking in a different nuget feed.
My packages.config looks like this
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Package1" version="1.0.0" />
<package id="Package2" version="1.0.0" />
</packages>
Any ideas how I can make this work? Can you include the source location in packages.config or something similar?

This is likely to be related to the naming of files on the feed. Your first command line doesn't specify a version number, so it will pick up anything named "PackageName".
Make sure the files in your feed are called "Package1.1.0.0" and "Package2.1.0.0", and that should do the trick.

Related

Changing name for Nuget Package

I have a Nuget package. Example: 'Sample'.
I have generated a .nupkg file using nuspec file.
and then pushed 'Sample' nuget package to feed using Nuget push azure build task.
my nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Sample</id>
<version>1.0.0.0</version>
<title>Sample</title>
<authors>Name</authors>
<copyright>Copyright © 2009-2019. All rights reserved.</copyright>
<tags>Sample</tags>
<description>This package is for testing.</description>
<owners>Name</owners>
</metadata>
<files>
<file src="./Sample.dll" target="lib\net46\Sample.dll"/>
</files>
</package>
Now I want to change the name of my nuget package, For example: 'SamplePackageForTesting'.
Nuget pakage name is not updated eventhough I change the title, and then pushed.
But when I change the id and push, then it is updating as new package.
Can you provide any solution how to change the name of my nuget package 'Sample' to 'SamplePackageForTesting'.
A rename is not possible: from NuGet's perspective, Sample and SamplePackageForTesting are two different packages as they have different IDs.
If you're using nuget.org, a workaround would be to deprecate your package (see here).
And if the NuGet feed is under your control you could also delete the Sample package. But for this, you have to make sure that nobody ever consumed it because otherwise deterministic builds won't be possible when going back in Git history.

Nuget Packages Not Restoring

I recently migrated my projects from using PackageReferences to a package.config file. For awhile I've been able to call nuget.exe restore ...\Solution.sln and everything has looked fine. Now when I build I appear to be missing references to my packages used in my package.config files.
I removed all of the 'PackageReferences' from the .csproj file and added a 'packages.config' to each project that look like the following:
Ex 1:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net31"/>
</packages>
Ex 2:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AspNetCore.HealthChecks.SqlServer" version="3.2.0" targetFramework="net31"/>
<package id="Newtonsoft.Json" version="13.0.0" targetFramework="net31"/>
<package id="System.ServiceModel.Security" version="4.9.0" targetFramework="net31"/>
</packages>
I have Automatically check for missing packages during build in Visual Studio checked in the NuGet Package Manager options of Visual Studio. I am using Visual Studio 2019 16.11.15 and NuGet 6.2.0.
Going to package manager and putting in update-package -reinstall outputs No package updates are available from the current package source for project 'ProjectName'.
If I right-click a packages.config file and select Migrate packages.config to PackageReference... I get an Operation Failed error. Is something wrong with my packages.config files? Is there anything else I can check?
Edit: I have attempted to delete all of my .vs, obj, and bin files. Also my csproj files begin with either <Project Sdk="Microsoft.NET.Sdk"> or <Project Sdk="Microsoft.NET.Sdk.Web">
We can only see migrate from packages.config to PackageReference in offical documatation because PackageReference is something newer. Reverse migration is not a good option.
You said you want to use packages.config with nuget restore so all dependencies can always be downloaded/updated after a fresh pull. You can refer to this page, it gives us many methods to restore packages.
For example, you can use “msbuild -t:restore” in PackageReference to restore packages. See this.

nuget pack ignores package.config dependencies

I cannot get nuget pack X.csproj to recognize package dependencies in a project. Amazingly, when packaging, the diagnostic message “Found packages.config. Using packages listed as dependencies” is printed, but in the end the <dependencies/> tag in the .nuspec file inside the package is empty.
The packages.config for the project does indeed contain references:
<packages>
<package id="SmartAction.Logger" version="1.0.2.0" targetFramework="net40" />
<package id="SmartAction.Pervasive" version="1.0.1.0" targetFramework="net40" />
</packages>
To narrow the problem down, I removed my own parallel .nuspec file, and mostly all switches from the nuget pack command:
> nuget pack libToneDetection.csproj -prop Configuration=Release
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Attempting to build package from 'libToneDetection.csproj'.
Packing files from '[snip]\Core\ToneDetection\libToneDetection\bin\Release'.
Found packages.config. Using packages listed as dependencies
Successfully created package '[snip]\Core\ToneDetection\libToneDetection\SmartAction.Audio.ToneDetection.1.0.0.0.nupkg'.
NuGet Version: 3.3.0.212
The only difference I can spot with this project is that its name is different from package name (I am trying to maintain them in sync but this is older stuff I am repackaging).
I doubt I had ever seen this before. I am finding questions on SO from people trying to prevent references in packages.config from becoming dependencies of the package, but none from those trying, like me, to beat the reverse problem. Help!
Addendum. I copied the project out of the solution with other projects to a temporary directory and rebuilt the package from there. Now one of the two dependencies from packages.config was added to the package:
<dependencies>
<dependency id="SmartAction.Logger" version="1.0.2.0" />
</dependencies>
Thinking of the differences between the two, the SmartAction.Logger package depends on SmartAction.Pervasive. But the package I am compiling really uses both.
To me, either behavior looks incorrect. Am I hitting a nuget bug, or a cryptic complex feature?
Xref: Opened https://github.com/NuGet/Home/issues/1867

An item with the same key has already been added nuget error

I am currently creating a nuget package with a nuspec file but getting the following error:
An item with the same key has already been added.
My command I am using is:
nuget pack "MyProject.csproj" -o "..\Packages"
This is my nuspec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<language>$language$</language>
</metadata>
<files>
<file src="bin\MyLibrary*.dll" target="lib\net45" />
</files>
</package>
The nuspec file I am using is also used when packaging other packages withing the same library. Could this be the reason why the above error is occurring? Any ideas?
It might be that you are adding files in nuspec that are also getting added when you call pack on the .csproj (files/dlls referenced by the csproj). If so you can remove the file references from the nuspec file and give it a try.
how does your nuspec file look like?
I created it with the following steps
1. create the Mylibrary project
2. let me add a dependency, I installed ninject package to the project
3. build
4. nuget spec mylibrary.csproj
5. nuspec file generated, I didn't add any file or dependency manually to the file
6. nuget pack mylibrary.csproj
7. nuget pack would automatically add ninject as a dependency and also add mylibrary.dll into the correct folder
8. http://npe.codeplex.com/ is a nice tool to open the nupkg file and see what got generated inside the package.
I had this error trying to use the package visualizer and it ended up that my packages.config had the same package name in it more than once with different versions.

How do I tell NuGet that I do NOT want a particular dependancy from a package?

There's a particular package that I like for my project that is on NuGet. However, the package author has decided to include several dependant packages that I don't care for and are not required by the main package. I have tried convincing the package author that these should be separate packages and not dependancies - to no avail.
Is there a way to tell NuGet that I want a package but to exclude a dependancy?
Perhaps something in the packages.config like this or similar?
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SomePackage" version="1.0.0">
<ignoredependancy id="SomePackage.UselessStuff" />
</package>
</packages>
I figured it out.
Install-Package -IgnoreDependencies
or
Uninstall-Package -Force
This is more of a feature request you should open an issue on the Nuget Codeplex site