I have created a MVC 6 project in Visual Studio 2015.
I am trying to create a Code First Entity framework class library
{
"version": "1.0.0-*",
"description": "DB Class Library",
"authors": [ "Michael" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"System.Collections": "4.0.10-beta-23019",
"System.Linq": "4.0.0-beta-23019",
"System.Threading": "4.0.10-beta-23019",
"System.Runtime": "4.0.10-beta-23019",
"Microsoft.CSharp": "4.0.0-beta-23019",
"System.ComponentModel.Annotations": "4.0.10",
"System.Data.Entity.Repository": "2.0.0.1",
"EntityFramework.SqlServer": "7.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5",
"Microsoft.Data.Edm": "5.6.5-beta"
},
"frameworks": {
"dotnet": { }
}
}
This is my project.json file.
The tutorial now says I should add "Microsoft.Data.Entity" However I am missing this reference so I'm not able to add this library. I need this library so I can create my DBContext class.
Had the same problem, the project did not load all the libraries in the beginning. Added the hot fix and all is well now.
Problem :
Opening Package Manager Console produces the message:
"Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Unrestricted. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy"."
But no PowerShell prompt ever appears. Similarly, attempting to install a package produces the same message on attempting to execute the script file from the package, followed by:
Install failed. Rolling back...
Attempting to upgrade an existing package instead produces:
Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
Solution
Explained and hot fix links available in https://github.com/NuGet/Home/issues/974#issuecomment-124774650
A hotfix is now available to install and we are confident it will unblock you. Please grab the install from one of these locations appropriately:
3.1.1 for VS 2015:
https://github.com/NuGet/Home/releases/download/3.1.1/NuGet.Tools.vsix
We will publish these to the Visual Studio gallery next week.
Change dotnet to dnx451
"frameworks": {
"dnx451": { }
}
Related
I was playing around with allure.Specflow until i noticed that there is no support for specflow 3.6+, so i decided to remove it from my project.
I have removed Allure.Specflow and all dependencies, Cleaned Debug and Release folders, Restarted VS checked that there are no mentions of Allure* anywhere in the project.
The project it self builds fine, but when i try to run any test I am getting the error below.
OneTimeSetUp: System.IO.FileNotFoundException : Could not load file or assembly 'Allure.SpecFlowPlugin' or one of its dependencies. The system cannot find the file specified.
The error states that the package could not be found, but Why is it trying to look for it in the first place?
For Anyone that is interested I have found the solution, I was referencing the package in specflow.json file
changing to the below fixed it
{
"bindingCulture": {
"name": "en-us"
},
"language": {
"feature": "en-us"
},
"NRetrySettings": {
"maxRetries": 3,
"applyGlobally": true
}
//"stepAssemblies": [
// { "assembly": "Allure.SpecFlowPlugin" }
//]
}
I am getting this error when I use the -LockMode switch with the nuget restore command.
NU1004: The packages lock file is inconsistent with the project
dependencies so restore can't be run in locked mode. Disable the
RestoreLockedMode MSBuild property or pass an explicit
--force-evaluate option to run restore to update the lock file.
What I am trying to achieve is to automatically upgrade my nuget references by using wildcards but use specific versions when I want to re-build my project from known sources. this blog posts describes how this can be achieved Enable repeatable package restores using a lock file.
When I use -UseLockFile & -LockMode on a simple solution with just one project it works as expected, the issue arises when I start adding another project to the solution.
Here're the steps:
I have published my package to an Azure DevOps feed and I have the following versions listed:
1.0.1-ci.1
1.0.1-ci.2
I have created a .Net 3.1 console app that references my package using wild cards, i.e. <PackageReference Include="My.Package" Version="1.0.*-ci.*" />
Running the command nuget restore -UseLockFile -ForceEvaluate creates the packages.lock.json with the right reference (I am using -ForceEvaluate in order to ensure it always resolves to the latest version available on the feed), the contents of the lock file of my console project are:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"My.Package": {
"type": "Direct",
"requested": "[1.0.*-ci.*, )",
"resolved": "1.0.0-ci.2",
"contentHash": "4HQuN7LNoZT9Z+MOL/Yig79FehhXBZmi26j3VtWR9Cgz8k5irWspSQ8aasVbNkYp7AgA2XaDQdr/cnwJnPilpQ=="
}
}
}
}
I then publish a new version of My.Package (1.0.1-ci.3) and run the command nuget restore -LockedMode, and the version resolved is still 1.0.1-ci.2, and if I then run nuget restore -ForceEvaluate it will resolve as expected to 1.0.1-ci.3, so far so good!
The issue arises when I add a class library to my solution which uses the same package reference, i.e. <PackageReference Include="My.Package" Version="1.0.*-ci.*" />, when I run restore -UseLockFile -ForceEvaluate my packages.lock.json file is updated to include the project dependency:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"My.Package": {
"type": "Direct",
"requested": "[1.0.*-ci.*, )",
"resolved": "1.0.0-ci.3",
"contentHash": "4HQuN7LNoZT9Z+MOL/Yig79FehhXBZmi26j3VtWR9Cgz8k5irWspSQ8aasVbNkYp7AgA2XaDQdr/cnwJnPilpQ=="
},
"classlibrary1": {
"type": "Project",
"dependencies": {
"My.Package": "1.0.0-ci.0"
}
}
}
}
}
While the contents of the lock file of the Class Library project are:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"My.Package": {
"type": "Direct",
"requested": "[1.0.*-ci.*, )",
"resolved": "1.0.0-ci.3",
"contentHash": "4HQuN7LNoZT9Z+MOL/Yig79FehhXBZmi26j3VtWR9Cgz8k5irWspSQ8aasVbNkYp7AgA2XaDQdr/cnwJnPilpQ=="
}
}
}
}
After this when I try running restore -LockMode I get the NU1004 error mentioned earlier.
Doing what the error message suggests and use -ForceEvaluate would clearly break what I wanted to achieve, yet I can't imagine that this relatively simple scenario is not covered by NuGet, so I would guess I am doing something wrong, does anyone have any ideas of what I could try to make this work?
It sounds like you're adding a new dependency then running nuget restore -LockedMode without first running nuget restore -ForceEvaluate.
It's not obvious what NuGet should do in that case - you're telling it you only want to use the dependencies in your lock file but you've also added new dependencies too.
It sounds like this would typically fail the restore:
If locked mode is set, restore will either get the exact packages as listed in the lock file or fail if it cannot. For example, if you updated the defined package dependencies for the project after lock file was created
https://devblogs.microsoft.com/nuget/enable-repeatable-package-restores-using-a-lock-file/#why-use-a-lock-file
You might have hit a corner case if the only transitive dependency of your new dependency is one that's already in the lock file but at a different version.
In general though, whenever you add new dependencies you're going to need to update your lock file, then after that you should be set to carry on running nuget restore -LockedMode.
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
Every time I try either install or restore any package for my VS 15 / .net 5 / EF7 project I receive this error regardless of the package. I have been looking and cannot seem to find anything for this error with nuget specifically. If anyone could help me understand what is going on here would be appercaited.
Restore failed
A circular reference to 'EntityFramework.MicrosoftSqlServer.Design' was detected.
NuGet Config files used:
C:\Users\User\AppData\Roaming\NuGet\nuget.config
Feeds used:
https://api.nuget.org/v3-flatcontainer/
C:\Program Files (x86)\Microsoft Web Tools\DNU
In case anyone else has this problem when updating your project the problem was in the global.json file.
{
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-final"
}
}
my problem was the sdk version never updated when I switched from beta-8 to rc1-final. So just change that and you should be ok.