We have been focusing on the new JavaScript capabilities of Visual Studio 2015 CTP 6 for the past few weeks. We were sorta expecting other basic .NET aspects to just work.
Today, we just tried to add some Unit Tests using NUnit to a WebAPI project and we are 0 for 20 (since it's opening day!) No matter what we try, we can't seem to even be able to add a NuGet package reference to NUnit (including 2.6.4 and 3.0.0-beta1).
Anybody have any suggestions on how to get NUnit tests to work with against ASP.NET 5 WebAPI projects?
Here is what we are doing:
Adding the new 4.6 ASP.NET 5 project
We are interested in the WebAPI stuff:
We read about issues with NuGet Package manager from NuGet Beta2, so we installed that version. And updated our configuration:
We can find the NUnit package (3.0 beta)
But in the end, this is all we get in the output window:
And the references are missing:
Here is our Project.json for this project:
{
/* Click to learn more about project.json http://go.microsoft.com/fwlink/?LinkID=517074 */
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
"Microsoft.AspNet.Mvc": "6.0.0-beta3",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
"NUnit": "3.0.0-beta-1"
},
"frameworks": {
"aspnet50": {},
"aspnetcore50": {}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"bundleExclude": [
"node_modules",
"bower_components",
"**.kproj",
"**.user",
"**.vspscc"
]
}
Alright, it turns out that my PostSharp NuGet source was messing with NuGet. I disabled it and things started working.
I now have NUnit 3.0 Beta 1 available:
I suspect this is or will be fixed in a recent release of PostSharp or the Package Source.
Related
After updating an existing project to ASP.NET Core 1.1 and Entity Framework Core 1.1 using this tutorial
I tried to execute "Add-Migration MigrationName" in Package Management Console but got an error:
Startup project 'src\ProjectName' is an ASP.NET Core or .NET Core
project for Visual Studio 2015. This version of the Entity Framework
Core Package Manager Console Tools doesn't support these types of
projects.
I am using VS 2015 Update 3.
Project.json
{
"dependencies": {
"CoursesManagement.DAL": "1.0.0-*",
"Microsoft.AspNetCore.Diagnostics": "1.1.1",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.1",
"Microsoft.AspNetCore.Mvc": "1.1.2",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.1",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.1",
"Microsoft.AspNetCore.StaticFiles": "1.1.1",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.1",
"Microsoft.Extensions.Configuration.Json": "1.1.1",
"Microsoft.Extensions.Logging.Console": "1.1.1",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
"Microsoft.NETCore.App": "1.1.1",
"Microsoft.EntityFrameworkCore": "1.1.1",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Design": "1.1.1"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
},
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"runtimes": {
"win10-x64": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
global.json
{
"projects": [ "src" ],
"sdk": {
"version": "1.0.0-preview2-003131"
}
}
As mentioned in this blog,
We’re now encouraging everyone to migrate to MSBuild and csproj from project.json. As I stated above, we will not be supporting any of the new .NET Core tools in Visual Studio 2015. We also won’t be updating the Visual Studio 2015 project.json-based tools.
You are using EFCore.Tools package version 1.1.0 which doesn't support project.json. The tooling for project.json never reached RTM. The suitable preview version to use for EF Core 1.1 packages is EFCore.Tools 1.1.0-preview4-final.
Also as mentioned in other answers, if you want to use powershell commands then you need to install EFCore.Tools package but if you want dotnet ef then you need to install EFCore.Tools.DotNet (version 1.1.0-preview3-final since preview4-final had minor issue).
As noted above, there will not be any updates to project.json-based tools. You can still use above preview package though best option would be to migrate to VS2017 csproj when you can.
As per official ASP.NET Core team announcement (see GitHub) the Microsoft.EntityFrameworkCore.Tools package was split into Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.Tools.DotNet.
You need to reference the later one, if you want to continue to use the dotnet ef commands. If you only want to use the old powershell styled commands (Database-Update, Add-Migration, etc.) the old package should be sufficient.
When referencing Microsoft.EntityFrameworkCore.Tools.DotNet``there is no need to also reference ``Microsoft.EntityFrameworkCore.Tools.
Quote by Rowan Miller
If you are using ASP.NET Core, then you need to update the tools
section of project.json to use the new
Microsoft.EntityFrameworkCore.Tools.DotNet package (rather than the
Microsoft.EntityFrameworkCore.Tools package).
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final"
},
As the design of .NET CLI Tools has
progressed, it has become necessary for us to separate the dotnet ef
tools into this separate package. Microsoft.EntityFrameworkCore.Tools
is still used for Package Manager Console commands.
Now that EF Core is released it should be of course
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0"
},
Also please note, that the tools do not share the version with the EF itself. The latest version of the tools is still 1.0.0 for Tools.DotNet(see Nuget) and 1.1.0 for Tools (see Nuget again).
I believe the commads are different in .NET Core and EF Core.
Try
dotnet ef migrations add MigrationName
and
dotnet ef database update
Here are the dotnet cli commands
I am trying to learn the basics of ASP.NET Core using this tutorial:
I have created a ASP.NET Core web application
I have upgraded it using instruction from here
Now, I am trying to setup the database migration using dotnet ef migrations add Initial from command prompt within project's folder (where project.json is located):
No executable found matching command "dotnet-ef"
I have changed project.json, so that dotnet-ef works:
"tools": {
...
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
Now, the generation fails with the following error:
The specified framework 'Microsoft.NETCore.App', version
'1.0.0-rc2-3002702' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App
- The following versions are installed:
1.0.0
1.0.1
1.1.0
- Alternatively, install the framework version '1.0.0-rc2-3002702'
Ok, it makes sense, because Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final relies on the old version mentioned in the error, as found in the project.lock.json file.
I don't want to downgrade, so I put the latest version of Microsoft.EntityFrameworkCore.Tools I could find:
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
Doing this will lead to the same error:
No executable found matching command "dotnet-ef"
How can I make it work in version 1.1?
Other context information that might be useful:
OS: Windows 7 x64
VS: 2015 Community Edition
Other parts from project.json:
"frameworks": {
"netcoreapp1.1": {
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"runtimes": {
"win7-x64": {}
},
UPDATE [30/3/2017]
The new package is
Install-Package Microsoft.EntityFrameworkCore.Tools
ORIGINAL
Try adding
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
Additionally here is a tutorial on setting up .Net Core 1.1.0 with EF Core 1.1.0
https://learn.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
Grierson's answer is ok, but for future reference I will include the whole process until I made it work:
1) Tools.DotNet already suggested in the accepted answer
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}
Ran the same command and received:
Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.
2) Added
//EF Core
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
}
3) Now, the error is:
No parameterless constructor was found on 'ApplicationDbContext'.
Either add a parameterless constructor to 'Application DbContext' or
add an implementation of 'IDbContextFactory' in
the same assembly as 'ApplicationDbC ontext'.
I have chosen to implement the interface. One possible way:
public ApplicationDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true");
return new ApplicationDbContext(builder.Options);
}
The same error occurs when running dotnet ef migrations add Initial
4) I have added a default constructor for ApplicationDbContext class
Now I can add the migration.
EntityFrameworkCore 1.1.0-preview4-final will work only asp.net core 1.1,if you want to move from core 1.0 to core 1.1,look into https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/.
I had the same issue.
that's resolved it for me
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
},
You might miss CliToolReference
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
check this
I am trying to update my net core project to 1.1-preview as well as EF core to the same version. Restoring the project.json works fine, but once I try to use commands like Add-Migration it fails with this error:
Commands could not invoke on target framework 'netcoreapp1.1'.
Commands on ASP.NET Core and .NET Core projects currently only support .NET Core ('netcoreapp1.0') or .NET Framework (e.g. 'net451') target frameworks.
project.json of small console App to test
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0-preview1-*"
},
"Microsoft.EntityFrameworkCore": "1.1.0-preview1-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0-preview1-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview3-final"
},
"frameworks": {
"netcoreapp1.1": {
"imports": "dnxcore50"
}
}
}
I am using Visual Studio 2015. Am I missing something or is EF/.net Core 1.1 not supported by the Visual Studio tools right now?
On EF/.net 1.0 it already does not recognize the Add-Migration or dotnet-ef commands, so to get them to work I have to initialize the EF tools manually as decribed here: https://stackoverflow.com/a/37876143/3506081
I also tried using the Microsoft.EntityFrameworkCore.Tools.DotNet as suggested in the release post but that has same issue that it does not recognize dotnet-ef.
Anyone got similar issues?
I found out that you can do that using the command line, so not within Visual Studio Package Manager Console (strange not sure why).
Keep in mind that the commands are not exactly the same, so for creating a migration for instance this is how you would do it:
dotnet ef migrations add InitialMigration
I'm also using:
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final"
and removed the old tools.
I believe that the tooling has not been updated yet to work with Entity Framework Core 1.1 Preview 1. So, what I did as a work around is to change framework version to netcoreapp1.0, do whatever commands I want to run on database, then revert to latest targeted framework.
This thread shreads some light over this situation.
The tooling is dependent on a certain MSBuild version so make sure that the tools version have the same version. I've got it running on Mac OSX Sierra
.csproj
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
<Version>1.0.0-msbuild1-final</Version>
</DotNetCliToolReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
<Version>1.0.0-msbuild1-final</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
<Version>1.0.0-msbuild1-final</Version>
</PackageReference>
After changing the .csproj make sure to run dotnet clean && dotnet restore. In case it fails try rm -rf obj/
Also
I am trying to get an MVC 6 web application up and running using the .NET 4.6 CLR, but I get the following kind of errors:
The dependency Microsoft.AspNet.Loader.IIS 1.0.0-beta5 in project TestDeployProject does not support framework .NETFramework,Version=v4.6.
project.json:
{
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.Framework.DependencyInjection.Abstractions": "1.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5"
},
"frameworks": {
"net46": { }
},
}
According to this blog post, the .NET 4.6 target framework does work with ASP.NET 5.
What am I doing wrong?
Unlike most Microsoft.Framework.* projects (like Caching for instance: https://github.com/aspnet/Caching/blob/dev/src/Microsoft.Framework.Caching.Abstractions/project.json#L7), Microsoft.AspNet.* packages only work with the "dnx-flavored" .NET Framework: if you want to use these packages in your own project, remove net46 and add a new dnx46 TFM and it should work.
Note that you'll need a recent DNX runtime version to use dnx46: don't hesitate to migrate to the latest nightly versions.
I am developing an asp.net 5 application targeting dnx451.
The asp.net 5 project relies some libraries with unit-tests written for nunit 2.x. So the reasonable choice for me is to use nunit for testing the asp.net 5 project.
When I running the unit test in ReSharper, the ReSharper says "Test not run" with additional message "System.IO.FileNotFoundException: Could not load file or assembly xxx ".
Both nunit 2.6.4 and 3.0.0-beta-2 results the same error.
Any one has successfully running nunit tests against an dnx project?
DNX tests aren't currently supported by ReSharper. It's a whole new execution model, and hasn't yet been implemented for ReSharper. I'd expect to see support as DNX and asp.net stabilise and near release. Also, I don't believe nunit itself supports running as a DNX test runner - the xunit team have a separate project to plug into DNX: https://github.com/xunit/dnx.xunit
NUnit does not support the DNX core.
Follow this issue to see when nunit adds dnx support. https://github.com/nunit/nunit/issues/575
Looks like NUnit has (partial) support as of v3.0.0-RC
http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/
Hopefully, by saying "Especially with ReSharper", you mean that you want to know how to run NUnit tests, and if possible, with ReSharper. That being said, here's how to run NUnit tests against ASP.NET Core (Formerly known as ASP.NET 5) in Visual Studio without needing ReSharper:
Add a new project and choose Console Application (.NET Core). Trying to use class libraries will currently report an error.
Add the latest version of the dotnet-test-nunit NuGet package (Make sure that Include prerelease is checked, or you won't find it in the NuGet feed)
Add the latest version of the NUnit NuGet package.
Edit project.json and add this line: "testRunner": "nunit",
Now you can run your tests by choosing Test - Run - All Tests from the Visual Studio menu.
Your project.json file should look like this:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"dotnet-test-nunit": "3.4.0-beta-1",
"ProjectUnderTest": "1.0.0-*",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"NUnit": "3.4.1"
},
"testRunner": "nunit",
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}