I tried to use EFCore with SQLite in a Xamarin.Android project. I also added the package Microsoft.EntityFrameworkCore.Tools. When I try to create database migrations I get various errors.
When running dotnet ef migrations add migrationname on the command line I get the error
No executable found matching command "dotnet-ef"
When running Add-Migration migrationname in Package Manager Console I get error
Startup project 'MyProject' targets framework 'MonoAndroid'. The Entity Framework Core Package Manager Console Tools don't support this framework.
Is there some way around this? Do I have to use EF6 instead of
The guidance for unsupported frameworks is to move your DbContext code into a .NET Standard class library and use a dummy .NET Core console app with the tools.
cd MyDbContextProject
dotnet ef migrations add MyMigration --startup-project ..\MyDummyProject
Related
I have a Asp.Net Core 3 project in Visual Studio using the standard MVC template. After updating VS to 16.4.6, I could not run the project anymore. I can build without issues, but attempting to run will give:
How do I fix this error? I did not make any explicit changes to my .NET environment (other than updating VS).
I am starting a new CORE application that uses a SQLServer database, and was using the following command to reverse engineer the current database for a model.
Scaffold-DbContext "Data Source=XXX;Initial Catalog=XXX;User ID=XXX;Password=XXX;MultipleActiveResultSets=True;App=EntityFramework" Microsoft.EntityFrameworkCore.SqlServer -Verbose
This leads to the following error that I have not found any resolution for.
Startup project 'src\XXXtest' 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 have installed packages for NetCoreApp.1.1.1 and Newtonsoft.json. I am using the 4.6.1 framework and using VS2015Community.
I am using VS 2013 for application development , I am not sure what version of Entity framework its being used in my project. Is there any way to find out current version of EF using package manager console ?
You could run the Get-Package command targeting the EntityFramework package in the Package Manager Console:
Get-Package EntityFramework
After running the command, you'll see any instances within your solution (or selected scope) where Entity Framework is installed as seen below :
The nuguet package for EntityFramework (6.1.3) installs some tools that you can execute from the nuget package manager console (like AddMigration, Update-Database, etc.). Those are available if you use nuget and the appropiate .ps files are loaded.
I'am resolving my project & solution dependencies with paket instead of nuget, so those commands are not available to me.
Are there any alternative to execute those scripts without having to go back to nuget?
As #ErikEJ mentioned, you can use migrate.exe from the command line. Unfortunately (from the docs):
All the utility is designed to do is execute migrations. It cannot generate migrations or create a SQL script.
So you can run any existing migrations, but you can't create any new ones with this tool. That makes migrate.exe a pretty poor replacement for the tools EF provides in the Package Manager Explorer.
I tried manually importing the EntityFramework.psd1 file in the Package Manager Console:
PM> Import-Module ".\packages\EntityFramework\tools\EntityFramework.psd1"
While this made the Enable-Migrations command available, running it produced the following error:
No packages installed.
The EntityFramework package is not installed on project 'Foo'.
I'm guessing that this is all going to work better with EF7. But for now, it looks like I'll either have to ditch paket altogether, or have a frankenstein of both Paket and Nuget to get this working.
Yes, you an run migrate.exe from the command line, it is included in the NuGet package in the Tools folder.
https://msdn.microsoft.com/en-us/data/jj618307.aspx
From the Paket issue Entity Framework code-first migrations:
The EF commands wouldn't appear in the VS console until I've added version_in_path: true in paket.dependencies:
nuget EntityFramework ~> 6.2 version_in_path: true
I have recently run into an issue where (for some reason this behaviour has appeared out of nowhere) during web deployment of a project to Azure Websites - some reference assemblies of the dependent projects are not automatically included into the deployment package.
SO this is a rough structure of my project:
1) ASP.NET MVC project that references class library project
2) Class library project that references some NuGet packages
Now, when I web deploy the ASP.NET MVC project to Azure Website - not all of the NuGet packaged assemblies from the reference class library are deployed (it seems that some are included automatically and others are not). Everything works fine when run locally. All of the required assemblies are copied over to the bin folder of the ASP.NET MVC project.
Now, the only way that I have found to work around this issue is to add the NuGet package of the missing reference directly to ASP.NET MVC project. I really don't like this workaround - since it breaks the modular structure of my project.
Surely there must be a way to specify which assemblies are to be included with Web Deploy? I have tried some pretty extensive google searches on the topic - but that didn't yield an working solution.
Try the following for each of the offending Nuget packages:
Open the Package Manager Console. Make sure the Default Project dropdown is set to your MVC project.
Run Uninstall-Package [Package Name] -Force
Run Install-Package [Package Name]
If you need to keep a particular version of a package instead of just pulling the latest in, you can add -Version [Version Number] to the end of the last command.
That will essentially refresh all the references and other bootstrapping for the package, then try to web deploy again.