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
Related
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.
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.
I'm trying to upgrade my ASP.NET 5 RC1 projects to ASP.NET Core RC2 projects. I'm having some issues because I'm using libraries that do not yet support .NET Core so I have to run on the full framework. This has worked fine in RC1, but I'm not able to figure out the right way to achieve this in RC2.
I have one class library which can restore packages and build properly. And I have a test project referencing the class library. When I try to build the test project, I'm getting the following errors:
> dotnet build
Project TenantService (.NETFramework,Version=v4.5.1) was previously compiled. Skipping compilation.
Project TenantServiceTests (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling TenantServiceTests for .NETCoreApp,Version=v1.0
C:\projects\TenantService\test\TenantServiceTests\project.json(25,23): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(25,23): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(26,21): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(26,21): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(27,26): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(27,26): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency Microsoft.CSharp could not be resolved.
The project.json files for these two projects look like this:
src\TenantService\project.json
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"Microsoft.Extensions.Options": "1.0.0-rc2-final",
"Newtonsoft.Json": "8.0.4-beta1",
"MongoDB.Driver": "2.2.4",
"StackExchange.Redis": "1.1.603"
},
"frameworks": {
"net451": {}
}
}
test\TenantServiceTests\project.json
{
"version": "1.0.0-*",
"testrunner": "xunit",
"description": "TenantServiceTests Class Library",
"authors": [ "Henning" ],
"dependencies": {
"xunit": "2.1.0",
"TenantService": "1.0.0-*",
"dotnet-test-xunit": "1.0.0-rc2-build10015"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"imports": [
"net451"
]
}
}
}
How should I properly set this up in order to use net451 libraries in my app?
The dependency mscorlib could not be resolved
I ran into this same problem yesterday. The issue is that the project.json for the test project is targeting the netcoreapp1.0. Instead you can target the net451 framework like the service you're testing against and that should "just work".
{
"version": "1.0.0-*",
"testrunner": "xunit",
"description": "TenantServiceTests Class Library",
"authors": [ "Henning" ],
"dependencies": {
"xunit": "2.1.0",
"TenantService": "1.0.0-*",
"dotnet-test-xunit": "1.0.0-rc2-build10015"
},
"frameworks": {
"net451": { }
}
}
For more details on this checkout the Migrating from ASP.NET 5 RC1 to ASP.NET Core. Another great resource is the markdown file out on the corefx repo that details .NET Platform Standard.
This is a follow-up to this question. I started with an Empty ASP.NET project in VS2015 community, tried to add a couple packages based on a tutorial, and haven't gotten it to actually work yet. The initial problem in the linked question was due to some project dependencies using beta5 and some using beta7. Matching those up solved that, but now I get this error when I try to run the project in IIS Express:
Could not load file or assembly 'Microsoft.Dnx.Host.Clr' or one of its dependencies.
I think the problem is still version related--like the previous web.config assembly reference issues--but I don't know how to deal with it yet. I tried modifying global.json based on a similar issue I found on GitHub, but now it doesn't build. It looks like it can't find the newer version of the CLR I guess. From the Error List in VS2015:
The dependency Microsoft.AspNet.Mvc >= 6.0.0-beta7 could not be resolved.
The dependency Microsoft.AspNet.Server.IIS >= 1.0.0-beta7 could not be resolved.
The dependency Microsoft.AspNet.Server.WebListener >= 1.0.0-beta7 could not be resolved.
global.json:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta7",
"runtime": "clr",
"architecture": "x86"
}
}
My project's References tree has yellow error indicators but looking in the NuGet package manager for my project doesn't show any upgrades (or anything installed at all, as far as I can tell).
dnvm list:
1.0.0-beta5 clr x64
1.0.0-beta5 clr x86
1.0.0-beta5 coreclr x64
1.0.0-beta5 coreclr x86
* 1.0.0-beta7 clr x86 default
1.0.0-beta8-15585 clr x86
dnu list:
Microsoft .NET Development Utility CLR-x86-1.0.0-beta7-15532
I've restart VS but that didn't help. Changing back to beta5 in my global.json makes it compule successfully but then I get the IIS error.
project.json:
{
"webroot": "public",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"public",
"node_modules",
"bower_components"
]
}
package.json:
{
"version": "1.0.0",
"name": "ASP.NET",
"private": true,
"devDependencies": {
"angular2": "2.0.0-alpha.36",
"gulp": "3.9.0"
}
}
"To use ASP.NET 5 beta7 with Visual Studio 2015, you will need to download and install the beta7 version (14.0.60831.0) of ASP.NET and Web Tools 2015."
http://go.microsoft.com/fwlink/?LinkId=623894
https://github.com/aspnet/Home/releases
I'm using ASP.NET 5.0 and I wanted to run just on the new Core CLR, so I removed "dnx451": { } from dependencies in my project.json file. I now get the following error when I launch in IIS:
Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
Microsoft.AspNet.Mvc 6.0.0-beta4
Microsoft.AspNet.Server.IIS 1.0.0-beta4
Microsoft.AspNet.Server.WebListener 1.0.0-beta4
Microsoft.AspNet.StaticFiles 1.0.0-beta4
My understanding was that AspNet.Mvc 6 would run on Core CLR? Why then do I have to include dnx451 as a dependency?
My project.json file:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"frameworks": {
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
Specifying dnxcore50 as a dependency in project.json is not the same as telling the Solution to target that dnx. To fix this I had to modify the solution global.json file to use a specific version of the dnx (i.e. a specific .Net executable). I also had to change a few using statements to use new Core CLR libraries instead of .Net 4.5 libraries. You will get intellisense and error warnings about these.
The global.json file can be found under the Solution node. I had to add the sdk version part:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta4"
}
}
Note that you can also edit this in a GUI:
Strongly recommend the recently uploaded ASP.NET Introduction and ASP.NET Deep Dive videos from Build 2015 available on Channel 9.
I had this error when publishing my DNX web app. It turned out it was because I had upgraded from Beta5 to Beta6 but neglected to update my publish powershell script which looks like:
$thisFolder = (Get-Item -Path ".\" -Verbose).FullName
$webFolder = "$thisFolder\..\src\Web.UI"
dnu publish $webFolder `
--out \\uatserver\uatshare `
--configuration DEBUG `
--no-source `
--runtime dnx-clr-win-x64.1.0.0-beta5
So in the last parameter my publish was still telling it to target beta5 instead of beta6.