Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add moq as a dependency in dotnet Core?

I have the following dependencies in my dotnet core application:

 "dependencies": {
        "xunit": "2.2.0-beta2-build3300",
        "dotnet-test-xunit": "2.2.0-preview2-build1029",
        "Moq": "4.0.10827"
    },

And no matter what version i download of Moq its simply just not supported, it says:

Package Moq 4.0.10827 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Moq 4.0.10827 supports:
      - net35 (.NETFramework,Version=v3.5)
      - net40 (.NETFramework,Version=v4.0)
      - sl4 (Silverlight,Version=v4.0)
    One or more packages are incompatible with .NETCoreApp,Version=v1.0.

But i read on this blogpost: Moq on .NET Core that it was possible, i have the nuget plugin in studio code, so it autocompletes packages, i just cannot find any package when i write moq.netcore Maybe i am asking more of an approach to finding out if such a plugin actually exists, more than an answer, because right now i can't see on nuget if packages are supported in dotnet Core, how do you guys check if it has support? and do you only look for packages on Nuget.org ?

Thanks

EDIT: Solution project.json:

{
    "version": "1.0.0-*",
    "testRunner": "xunit",
    "dependencies": {
        "xunit": "2.2.0-beta2-build3300",
        "dotnet-test-xunit": "2.2.0-preview2-build1029",
        "moq": "4.6.38-alpha"
    },
    "frameworks": {
        "netcoreapp1.0": {
            "dependencies": {
                "Microsoft.NETCore.App": {
                    "type": "platform",
                    "version": "1.0.0"
                }
            }
        }
    }
}
like image 668
DenLilleMand Avatar asked Oct 19 '16 09:10

DenLilleMand


1 Answers

I guess current stable version in Nuget is 4.5.23 and in your code you have mentioned it should be 4.0.10827, may be that is causing problem.

As shown in your error, Moq 4.0.10827 is not compatible with netcoreapp1.0 and it only supports till 4.0, Look here for more details on versions of Moq

I have also wrote blog on Moq in .Net core, which is here. But I make changes in this everyday due to new changes.

Edit: As per DenLilleMand:

4.6.38-alpha works - but e.g. 4.5.3 doesn't work, that complains that Moq 4.5.3 supports net45 and one or more packages are incompatible with .NETCoreApp V1.0.

like image 87
Neel Avatar answered Oct 10 '22 17:10

Neel