Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NuGet doesn't handle conflicts of versions in an install request when HighestVersion dependency #507

Closed
ferventcoder opened this issue Dec 15, 2015 · 19 comments

Comments

@ferventcoder
Copy link
Member

The NuGet dependency walker doesn't seem to be able to handle the scenario where a package has a dependency constraint on a package version and another dependency has a similar, but looser constraint on a package version.

It fails with Already referencing a newer version of 'x'.

Related to #227 and #506.

From: https://groups.google.com/d/msgid/chocolatey/ad9e0b37-a81d-4c75-98c7-c84c787b8859%40googlegroups.com?utm_medium=email&utm_source=footer

Hasdependency.nuspec:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>hasdependency</id>
    <version>1.0.0</version>
    <authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
    <owners>__REPLACE_YOUR_NAME__</owners>
    <description>__REPLACE__</description>
    <dependencies>
      <dependency id="isdependency" version="[1.0.0]" />
      <dependency id="isexactversiondependency" version="[1.0.0]" />
    </dependencies>
  </metadata>
</package>

isdependency.nuspec

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>isdependency</id>
    <version>1.0.0</version>
    <authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
    <owners>__REPLACE_YOUR_NAME__</owners>
    <description>__REPLACE__</description>
    <dependencies>
      <dependency id="isexactversiondependency" version="[1.0.0, 2)" />
    </dependencies>
  </metadata>
</package>

isexactversiondependency.nuspec (with one file so it will build) - 1.0.0

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>isexactversiondependency</id>
    <version>1.0.0</version>
     <authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
    <owners>__REPLACE_YOUR_NAME__</owners>
    <description>__REPLACE__</description>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>

isexactversiondependency.nuspec (with one file so it will build) - 1.1.0

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>isexactversiondependency</id>
    <version>1.1.0</version>
     <authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
    <owners>__REPLACE_YOUR_NAME__</owners>
    <description>__REPLACE__</description>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>
@ferventcoder
Copy link
Member Author

Similar to #116 (although in this case it does).

@ferventcoder ferventcoder changed the title NuGet doesn't handle conflicts of versions in a single tree when HighestVersion dependency NuGet doesn't handle conflicts of versions in an install request when HighestVersion dependency Dec 15, 2015
@ferventcoder
Copy link
Member Author

@timbrown5

@ferventcoder
Copy link
Member Author

@maartenba / @xavierdecoster Did NuGet v3 fix this problem? I am working on reproducing it all the way up.

@ferventcoder
Copy link
Member Author

Of course I need to install VisualStudio 2015 to verify this as it doesn't seem that the command line version of NuGet (up to 3.3.0) respects the DependencyVersion attribute in the NuGet.config file. I've set it to highest and it ignores it.

image

@ferventcoder
Copy link
Member Author

Here is a reproduction - repro.zip

Unzip this and add it to a local folder, then add that local folder in visual studio nuget manager.

Run this command install-package toplevelhasexactversiondependency -DependencyVersion Highest

It fails in VS2013 which looks like it includes up to 2.8.7 in the latest available extension. I'm curious if it also fails in VS2015 (which includes 3.x).

image

ferventcoder added a commit that referenced this issue Dec 16, 2015
Add packages that present an error when one of the dependencies depend
on a less constrained but still appropriate version of a dependency
that the top level package also depends on for an exact version. This
is a scenario that should absolutely work but does not.
ferventcoder added a commit that referenced this issue Dec 16, 2015
NuGet should walk a dependency tree and find the most appropriate
package by falling back down the dependency tree until it finds an
appropriate version that is suitable for all dependency sets and then
fail appropriately if no suitable version can be found.

Unfortunately when you use a Dependency Version Behavior of Highest,
NuGet just fails completely and refuses to work at all. I've been able
to verify this as high as the latest version of NuGet package manager
that is available with VS2013. I'm hopeful this is fixed in the v3.x of
NuGet.Core.
ferventcoder added a commit that referenced this issue Dec 16, 2015
* ticket/stable/GH-507-specs:
  (GH-507)(specs) Failing dependency version single tree
  (GH-507)(spec) add constrained versions to project
  (GH-507)(spec) Pkg Dependency single chain
  (spec) build packages at test time
ferventcoder added a commit that referenced this issue Dec 16, 2015
* stable:
  (GH-507)(specs) Failing dependency version single tree
  (GH-507)(spec) add constrained versions to project
  (GH-507)(spec) Pkg Dependency single chain
  (spec) build packages at test time
ferventcoder added a commit that referenced this issue Dec 16, 2015
ferventcoder added a commit that referenced this issue Dec 16, 2015
* stable:
  (GH-507)(specs) fixup spelling
@maartenba
Copy link

Best to post an issue at http://github.com/nuget/home

@ferventcoder
Copy link
Member Author

@maartenba I am planning on it, but if you had any updates as to whether this was fixed ahead of time, it would be helpful.

@ferventcoder
Copy link
Member Author

Hate to post an issue for something that may have already been fixed.

@maartenba
Copy link

No idea personally, maybe @xavierdecoster

@ferventcoder
Copy link
Member Author

@maartenba / @xavierdecoster - I followed up with NuGet/Home#1839

@ferventcoder
Copy link
Member Author

image

@gep13 verified this works properly in v3.

@ferventcoder
Copy link
Member Author

This will require .NET 4.5 for the upgrade to a v3 version of NuGet so this will need to move to 0.9.11 where we are eclipsing support for .NET 4 (and Windows 2003).

@rockobonaparte
Copy link

I just got bit with this again with version 0.10.8. Is it actually still open? The packages I'm using are internal so I can't directly expose them but the dependency chain was basically:

X 1.1
(no specific dependencies)
(there is also an X 1.2 and that screws things up)

this is actually wants being specified to be installed in Chocolatey
package X-wrapper 1.1
needs X, specifically version 1.1
needs X-config 1.0

X-config 1.0
needs X, no specific version
needs X-collateral, no specific version

X-collateral 1.0
needs X, no specific version

If I install X 1.1 beforehand then we're cool. If I install X-wrapper 1.1 then X-config seems to grab X 1.2, then X-wrapper tries to get X 1.1, and the world explodes.

@ferventcoder
Copy link
Member Author

Howdy @rockobonaparte - we are typically quite good at the paperwork aspect of our tickets, so if it is still open, it's likely still an issue. There are sometimes we do have duplicates that are not caught so they get tagged for the release and older issues might be missed in that regard. We are looking to upgrade NuGet coming in the next few months (hopefully completed by mid 2021).

@gep13 gep13 modified the milestones: 0.11.x, 0.10.x Sep 17, 2021
@TheCakeIsNaOH TheCakeIsNaOH added the Requires NuGet.Client Change This issue requires a modification to something in referenced NuGet.Client library. label Feb 4, 2022
@TheCakeIsNaOH
Copy link
Member

This issue appears to be fixed as a part of #2740, by enabling/completing the below tests:

public class when_installing_a_package_with_dependencies_on_an_older_version_of_a_package_than_is_already_installed : ScenariosBase
{
public override void Context()
{
base.Context();
Configuration.PackageNames = Configuration.Input = "hasdependency";
Scenario.add_packages_to_source_location(Configuration, "hasdependency.1.0.0*" + NuGetConstants.PackageExtension);
Scenario.add_packages_to_source_location(Configuration, "conflictingdependency.2.1.0*" + NuGetConstants.PackageExtension);
Scenario.add_packages_to_source_location(Configuration, "isdependency.*" + NuGetConstants.PackageExtension);
Scenario.add_packages_to_source_location(Configuration, "isexactversiondependency*" + NuGetConstants.PackageExtension);
Scenario.install_package(Configuration, "conflictingdependency", "2.1.0");
}
/*
Setup should have the following installed:
* conflictingdependency 2.1.0
* isexactversiondependency 2.0.0
* isdependency at least 2.0.0
*/
public override void Because()
{
Results = Service.install_run(Configuration);
}
[Fact]
public void should_not_install_the_conflicting_package_in_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);
DirectoryAssert.DoesNotExist(packageDir);
}
[Fact]
public void should_not_downgrade_the_exact_version_dependency()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg");
using (var packageReader = new PackageArchiveReader(packageFile))
{
packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0");
}
}
[Fact]
public void should_contain_a_message_that_it_was_unable_to_install_any_packages()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("installed 0/1")) expectedMessage = true;
}
expectedMessage.ShouldBeTrue();
}
[Fact]
public void should_not_have_a_successful_package_result()
{
foreach (var packageResult in Results)
{
packageResult.Value.Success.ShouldBeFalse();
}
}
[Fact]
public void should_not_have_inconclusive_package_result()
{
foreach (var packageResult in Results)
{
packageResult.Value.Inconclusive.ShouldBeFalse();
}
}
[Fact]
public void should_not_have_warning_package_result()
{
foreach (var packageResult in Results)
{
packageResult.Value.Warning.ShouldBeFalse();
}
}
[Fact]
public void should_have_an_error_package_result()
{
bool errorFound = false;
foreach (var packageResult in Results)
{
foreach (var message in packageResult.Value.Messages)
{
if (message.MessageType == ResultType.Error)
{
errorFound = true;
}
}
}
errorFound.ShouldBeTrue();
}
}
public class when_installing_a_package_with_a_dependent_package_that_also_depends_on_a_less_constrained_but_still_valid_dependency_of_the_same_package : ScenariosBase
{
public override void Context()
{
base.Context();
Configuration.PackageNames = Configuration.Input = "toplevelhasexactversiondependency";
Scenario.add_packages_to_source_location(Configuration, "toplevelhasexactversiondependency*" + NuGetConstants.PackageExtension);
Scenario.add_packages_to_source_location(Configuration, "childdependencywithlooserversiondependency*" + NuGetConstants.PackageExtension);
Scenario.add_packages_to_source_location(Configuration, "isexactversiondependency*" + NuGetConstants.PackageExtension);
}
public override void Because()
{
Results = Service.install_run(Configuration);
}
/*
Because should result in the following installed:
* toplevelhasexactversiondependency 1.0.0
* childdependencywithlooserversiondependency 1.0.0
* isexactversiondependency 1.0.0
*/
[Fact]
public void should_install_where_install_location_reports()
{
foreach (var packageResult in Results)
{
DirectoryAssert.Exists(packageResult.Value.InstallLocation);
}
}
[Fact]
public void should_install_a_package_in_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames);
DirectoryAssert.Exists(packageDir);
}
[Fact]
public void should_install_the_dependency_in_the_lib_directory()
{
var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "childdependencywithlooserversiondependency");
DirectoryAssert.Exists(packageDir);
}
[Fact]
public void should_install_the_expected_version_of_the_dependency()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "childdependencywithlooserversiondependency", "childdependencywithlooserversiondependency.nupkg");
using (var packageReader = new PackageArchiveReader(packageFile))
{
packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.0.0");
}
}
[Fact]
public void should_install_the_expected_version_of_the_constrained_dependency()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg");
using (var packageReader = new PackageArchiveReader(packageFile))
{
packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.0.0");
}
}
[Fact]
public void should_contain_a_message_that_everything_installed_successfully()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains("3/3")) expectedMessage = true;
}
expectedMessage.ShouldBeTrue();
}
[Fact]
public void should_have_a_successful_package_result()
{
foreach (var packageResult in Results)
{
packageResult.Value.Success.ShouldBeTrue();
}
}
[Fact]
public void should_not_have_inconclusive_package_result()
{
foreach (var packageResult in Results)
{
packageResult.Value.Inconclusive.ShouldBeFalse();
}
}
[Fact]
public void should_not_have_warning_package_result()
{
foreach (var packageResult in Results)
{
packageResult.Value.Warning.ShouldBeFalse();
}
}
}

@TheCakeIsNaOH TheCakeIsNaOH modified the milestones: Future, 2.0.0 Jan 26, 2023
@rockobonaparte
Copy link

Do you know how I can mess around with the sum of that and see what's going on? Version resolution came up recently among colleagues so we are actually still motivated over stuff like this.

@TheCakeIsNaOH
Copy link
Member

@gep13 gep13 closed this as completed Jan 27, 2023
@gep13 gep13 removed Blocked - External Requires NuGet.Client Change This issue requires a modification to something in referenced NuGet.Client library. labels Mar 21, 2023
@choco-bot
Copy link

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants