How to add moq as a dependency in dotnet Core? - asp.net-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"
}
}
}
}
}

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.

Related

AspNetCore namespace doesnt exist

I'm following this course to learn ASP.NET Core.
I did exactly as they did, I can type dotnet new and dotnet restore.
I also installed the dotnetcore 1.0.1 SDK preview.
All seems fine, and I should be able to type
using Microsoft.AspNetCore.Http;
But the only things recognized after Microsoft are cSharp, visualbasic and win32?
Here is my project.json file:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.AspNet.WebApi": "5.2.3",
"Microsoft." **<< i cannt type AspNetCore here**
},
"imports": "dnxcore50"
}
}
There is no Microsoft."AspNetCore". The only things I do have starting with Asp are:
AspNet.Identity.Owin
AspNet.Mvc
AspNet.Providers.Core
AspNet.Razor
AspNet.SignalR
AspNet.Web.Optimization
AspNet.WebApi
AspNet.WebApi.Clients
AspNet.WebApi.Core
AspNet.WebApi.Cors
AspNet.WebPages
The code completion doesn't always work when editing the project.json file, especially if you're using a lighter editor like VS Code. (Sometimes it doesn't work even in full-blown Visual Studio).
If this happens, don't worry! You can still install any packages you need. Find packages by searching on NuGet and then edit the dependencies section like this:
"PackageName": "1.0.0" # Version from package details on NuGet
Then, use the dotnet restore command within the project directory to pull down all the packages in project.json.

Why can't my Core 1 library be seen in my ASP.NET Core 1.0 (MVC6) project?

I have a little class library (Core 1), separate so that other apps may also use it, and all those reasons. It has only POCO model classes and a DbContext derivative. Its project file looks as follows:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"NETStandard.Library": "1.5.0-rc2-24027",
"System.ComponentModel.Annotations": "4.1.0"
},
"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50"
}
}
}
Then I have an ASP.NET Core Web Application (.NET Core) that I wish to use the class library in. Nearly everywhere I look, and I've looked, says to just add the library to the main project's dependencies section of its project file. There it is, right at the top:
"dependencies": {
"WideWorld.Filing": "1.0.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
I can't even see the library namespace WideWorld.Filing in the main project, where I can, obviously, see its namespace, WideWorld.Office. I am very, very new to Core 1, and have only build monolith web applications before, so please excuse my ignorance if I'm missing something obvious.
If I do a package restore on the main project, I get three warnings in the log (and other stuff that looks harmless):
warn : Detected package downgrade: Microsoft.EntityFrameworkCore.SqlServer from 1.0.0 to 1.0.0-rc2-final
warn : WideWorld.Office (>= 1.0.0) -> WideWorld.Filing (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0)
warn : WideWorld.Office (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0-rc2-final)
The issue is that you're mixing packages versions. For example the RTM and RC2 packages are not compatible. You should either target everything as RC2 (which I'd advise against) or take the more preferred approach and upgrade all package references to RTM, targeting version 1.0.0.
More details here:
Note, I have omitted the "import": "dnxcore50"
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"NETStandard.Library": "1.6.0",
"System.ComponentModel.Annotations": "4.1.0"
},
"frameworks": {
"netstandard1.5": { }
}
}
Likewise, in the other project.json do this:
"dependencies": {
"WideWorld.Filing": "1.0.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0"
Additional details on packages.

Why can't EntityFramework.Core be added to a simple PCL?

Am I missing something obvious?
Open Visual Studio 2015 Update 2
Add a new Portable Class Library project, targeting .NET 4.6 and UWP 10
Attempt to install NuGet package Microsoft.EntityFrameworkCore v1.0.0-rc2-final
It fails with "EntityFramework.Core 7.0.0-rc1-final is not compatible with .NETPlatform,Version=v5.0."
Is this supposed to work?
EDIT
Just to clarify, here is my PCL properties:
Installation with nuget unfortunately does not working out of the box. You have to modify the project.json by your self to get it working!
https://docs.efproject.net/en/latest/miscellaneous/rc1-rc2-upgrade.html
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
}
For more info :
Trying to install EF Core with Portable Class Library targeting .Net 4.6.1

xunit on dotnet cli project

I am trying to set up xunit tests on a dotnet cli project. I realize this is very early stages of support. Right now, I am not able to restore packages. Below is my project.json
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002392"
},
"xunit": "2.1.0-*",
"dotnet-test-xunit": "1.0.0-dev-*"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50"
]
}
},
"testRunner": "dotnet-test-xunit"
}
After running dotnet restore I get the following errors:
Package xunit.assert 2.1.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package xunit.assert 2.1.0 supports:
- dotnet (.NETPlatform,Version=v5.0)
- portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
Package xunit.runner.reporters 2.1.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package xunit.runner.reporters 2.1.0 supports:
- dnx451 (DNX,Version=v4.5.1)
- dotnet (.NETPlatform,Version=v5.0)
- net45 (.NETFramework,Version=v4.5)
Package Microsoft.Extensions.Logging.Abstractions 1.0.0-rc2-16040 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Microsoft.Extensions.Logging.Abstractions 1.0.0-rc2-16040 supports:
- dotnet5.4 (.NETPlatform,Version=v5.4)
- net451 (.NETFramework,Version=v4.5.1)
- netcore50 (.NETCore,Version=v5.0)
Package Microsoft.DiaSymReader 1.0.6 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Microsoft.DiaSymReader 1.0.6 supports:
- net20 (.NETFramework,Version=v2.0)
- portable-net45+win8 (.NETPortable,Version=v0.0,Profile=Profile7)
Package Microsoft.Extensions.FileSystemGlobbing 1.0.0-rc2-15996 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Microsoft.Extensions.FileSystemGlobbing 1.0.0-rc2-15996 supports:
- dotnet5.4 (.NETPlatform,Version=v5.4)
- net451 (.NETFramework,Version=v4.5.1)
One or more packages are incompatible with .NETCoreApp,Version=v1.0.
Feeds used:
https://www.myget.org/F/dotnet-core/api/v3/index.json
https://api.nuget.org/v3/index.json
https://www.myget.org/F/coreclr-xunit/api/v2
https://www.myget.org/F/dotnet-cli/
The imports that you specify cannot satisfy all the requirements. That's why you see the errors.
Try replacing them with:
"imports": [
"portable-net451+win8",
"dnxcore50"
]
Also, the xunit runner should be "xunit" not "dotnet-test-xunit".
See an example project here: https://github.com/aspnet/dotnet-watch/blob/46d4c6edcb374060b4e8ebf83e3ccd399f8f61ae/test/dotnet-watch.FunctionalTests/project.json

dnxcore50 framework support in ASP.Net 5 Class Library Package project?

I am trying to develop my first ASP.Net web application and in my solution I have two projects. A Web Application and Class Library (Package) and noticed that the Web App has this for it's framework inside the project.json
"frameworks": {
"dnxcore50": { }
}
My understanding is that code makes my Web App target Net 5.0 Core but if I look at the project.json for the Class Library I see this:
"frameworks": {
"net451": { },
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
I have never heard of dotnet5.4 and what I read from google just confuses me. I think the net451 is the equivalent to dnx451 but I am not 100% on that.
What do I need to change in my project.json to get it to target the new .Net 5.0 core?
This is the result of the upcoming .NET Standard Platform. You can see the changes regarding this specific to rc1 here, the main part being;
Only class libraries should change to target net4x and dotnet5.x. For
class libraries the recommended conversion steps are:
In project.json:
Change dnx4x to net4x (e.g. dnx451 to net451)
Change dnxcore50 to
dotnet5.4
And in your CS files:
Change #if DNX451 to #if NET451
Change #if DNXCORE50 to #if DOTNET5_4