Nuget cannot find newer dependency
Asked Answered
C

2

6

I've just created a new project in ASP 5 MVC 6 beta8 and a compatible class library for tests. The problem occurs in this new "Web Class Library" project that I intended to use for tests.

This is what my project.json looks like:

{
  "version": "1.0.0-*",
  "description": "ClassLibrary1 Class Library",
  "authors": [ "Me" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "dnx451": { }
  },
  "dependencies": {
    "AutoFixture": "3.36.9",
    "AutoFixture.AutoMoq": "3.36.9",
    "Moq": "4.2.1510.2205"
  }
}

During compilation I get the following error:

Severity    Code    Description Project File    Line    Source
Error   NU1001  The dependency moq >= 4.1.1308.2120 could not be resolved.  ClassLibrary1   Path\To\My\Solution\ClassLibrary1\project.json  1   Build

This is what my project's references look like:

enter image description here

I guess the problem is that AutoFixture.AutoMoq requires Moq in version "4.1.1308.2120". See the project.lock.json:

  "AutoFixture.AutoMoq/3.36.9": {
    "type": "package",
    "dependencies": {
      "autofixture": "3.36.9",
      "moq": "4.1.1308.2120"
    },
    "compile": {
      "lib/net40/Ploeh.AutoFixture.AutoMoq.dll": {}
    },
    "runtime": {
      "lib/net40/Ploeh.AutoFixture.AutoMoq.dll": {}
    }
  },

However, the installed Moq version is higher "4.2.1510.2205", so according to the error message, it should be fine, but it's not.

It works fine though if I downgrade Moq to the required version, but I'd rather use the latest version. I've installed the latest nuget package manager, restarted VS and OS but neither helped.

What can I do about it?

EDIT

I also created a normal Class Library, installed the dependencies above with and gave it a try. Normal Class Library project built fine.

Carinthia answered 25/10, 2015 at 0:0 Comment(7)
What happens if you attempt to create a plain vanilla console application or class library with these dependencies? I tried right now, and it compiles fine, so my hypothesis is that it's related to ASP 5 MVC 6, which, after all, is still in beta. If so, it may be a bug that you ought to report.Elysha
@MarkSeemann I gave it a try, and it built fine. I'll report it to the ASP5 team and see what they say.Carinthia
I encountered the same problem. Did you create an issue on github? Is the issue resolved in rc1?Squarerigger
@Squarerigger yes, I have. No actions were taken thoug: github.com/aspnet/Home/issues/1033Carinthia
@Squarerigger I found a solution, see my answer.Carinthia
@Squarerigger see the answer by codegorkCarinthia
I created an issue for this in AutoFixture and will cross-reference it in the ASP.NET repo issue linked above. github.com/AutoFixture/AutoFixture/issues/541Ruffian
D
2

Update: This can now be fixed by upgrading to AutoFixture.AutoMoq 3.41.0 or later.

Original Answer:

In the targets section of project.lock.json capitalize "moq", so that the AutoMoq element looks like this:

"AutoFixture.AutoMoq/3.38.0": {
    "type": "package",
    "dependencies": {
      "autofixture": "3.38.0",
      "Moq": "4.1.1308.2120"
    },

Unfortunately, you will have to do this again every time the lock file is regenerated.

Dictum answered 3/1, 2016 at 18:21 Comment(0)
P
0

You can't have two different versions in the same project. You can use a * to allow up- or downgrade. See this artical Dependency-Resolution

Priebe answered 25/10, 2015 at 16:44 Comment(4)
It does not say that you cannot have two different versions. 'When deciding between multiple cousin dependencies, the resolver use the lowest version that satisfies all version requirements.'Epiclesis
You require an exact version. to allow an lower version you have to specify someyhing like "Moq": "4.2.*"Priebe
Bases on document you link to in answer it says nothing about not allowing two different versions.Epiclesis
See issue on https://github.com/aspnet/dnx/issues/2264Priebe

© 2022 - 2024 — McMap. All rights reserved.