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.

Andrzej Gis
  • 13,706
  • 14
  • 86
  • 130
  • 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. – Mark Seemann Oct 25 '15 at 09:02
  • @MarkSeemann I gave it a try, and it built fine. I'll report it to the ASP5 team and see what they say. – Andrzej Gis Oct 25 '15 at 10:32
  • I encountered the same problem. Did you create an issue on github? Is the issue resolved in rc1? – Asik Dec 11 '15 at 21:54
  • 1
    @Asik yes, I have. No actions were taken thoug: https://github.com/aspnet/Home/issues/1033 – Andrzej Gis Dec 13 '15 at 13:29
  • @Asik I found a solution, see my answer. – Andrzej Gis Dec 28 '15 at 16:38
  • @Asik see the answer by codegork – Andrzej Gis Jan 09 '16 at 21:49
  • 1
    I created an issue for this in AutoFixture and will cross-reference it in the ASP.NET repo issue linked above. https://github.com/AutoFixture/AutoFixture/issues/541 – David Peden Mar 07 '16 at 18:39

2 Answers2

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.

codegork
  • 36
  • 3
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

Thom Kiesewetter
  • 6,703
  • 3
  • 28
  • 41