Not able to execute "add-migration" with function app and entity framework core 2.0.1.
I'm using entity framework with function app when I target ef project and try to execute "add-migration" it shows error in PMC
Error :-
Startup project 'LegacyGayaFuncApp' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core Package Manager Console Tools with this project, add an executable project targeting .NET Framework or .NET Core that references this project, and set it as the startup project; or, update this project to cross-target .NET Framework or .NET Core.
Code for API
namespace LegacyGayaFuncApp.ItemsHandler
{
public static class AddItems
{
[FunctionName("AddItems")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req, TraceWriter log)
{
log.Info("C# HTTP trigger AddItems function processed a request.");
IActionResult response = new OkObjectResult(new { sucess = true, message = "Ok" });
try
{
var items = new[] {
new Item{Title= "Title jeans", Tags = "new",Images = new Image[]{
new Image{ImageUrl="https://anf.scene7.com/is/image/anf/hol_211897_04_model1?$product-ofp-hol-v1$&$product-zoom-hol-v1$" }
} },
new Item{Title= "Jeans", Tags = "new", Images = new Image[]{
new Image{ImageUrl="https://anf.scene7.com/is/image/anf/hol_211897_04_model4?$product-ofp-hol-v1$&$product-zoom-hol-v1$" }
} },
new Item{Title= "Title", Tags = "new", Images = new Image[]{
new Image{ImageUrl="https://anf.scene7.com/is/image/anf/hol_211897_04_model3?$product-ofp-hol-v1$&$product-zoom-hol-v1$" }
} },
};
using (var context = new LegacyGayaDbContext())
{
context.Database.Migrate();
context.Database.EnsureCreated();
context.Item.AddRange(items);
context.SaveChanges();
}
string name = req.Query["code"];
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
}
catch (Exception ex)
{
response = new OkObjectResult(new { sucess = true, message = ex.Message + " InnerMessage : " + ex.InnerException?.Message});
}
return (ActionResult)response;
}
}
}
Code for DBContext
public class LegacyGayaDbContext : DbContext
{
public virtual DbSet<Item> Item { get; set; }
public virtual DbSet<Image> Image { get; set; }
public LegacyGayaDbContext() :
base(new DbContextOptions<LegacyGayaDbContext>{ })
{
//Database.Migrate();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=LegacyGaya;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Item>().ToTable("Items");
}
}
I want the solution for this error or else database should update automatically while running the code
.Net standard 2.0 (function app)
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows
IDE: Visual Studio 2017
@Risanshita Can you be specific about what part of the exception message is not clear?
@ajcvickers In package manager console, when I target ef project and try to execute "add-migration" it shows error is :
_Startup project 'LegacyGaya.Data' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core Package Manager Console Tools with this project, add an executable project targeting .NET Framework or .NET Core that references this project, and set it as the startup project; or, update this project to cross-target .NET Framework or .NET Core._
@ajcvickers
I'm able to create the database when executing this code first time :
using (var context = new LegacyGayaDbContext())
{
context.Database.Migrate();
context.Database.EnsureCreated();
context.Item.AddRange(items);
context.SaveChanges();
}
Because the first time I have not added migration so, I was able to do but when i make any changes in models then I need to do add-migration.
NOTE:- I'm using Azure Function app as startup project
There is a same issue with someone else
@Risanshita The Azure Functions project creates a .NET Standard class library. EF tooling cannot work with this directly, therefore you must take one of the actions suggested in the message and in the linked documentation.
It is actually possible, I wrote a Blogpost about it. You should add a netcoreapp target framework.
For more information check the entire blogpost.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0.7;netstandard2.0</TargetFrameworks>
</PropertyGroup>
...
</Project>
https://dibranmulder.github.io/2018/08/23/Azure-functions-V2-with-EF-Core/
@DibranMulder as you mention in your blog I have done same.
But I'm getting this error:-
PM> add-migration initialmigration
Error:
An assembly specified in the application dependencies manifest (FunctionApp3.deps.json) was not found:
package: 'FunctionApp3', version: '1.0.0'
path: 'FunctionApp3.dll'
Someone suggest on github to add this line in project file, i did event error shows
<PropertyGroup>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
This is my project files

Please help,
Thanks for the helpful blog
I've also been working from @DibranMulder's excellent blogpost (Thank you for that.)
@Risanshita I was able to work around your problem by creating a separate console app that includes my dll library as a dependency. Then using:
dotnet ef --startup-project ../ConsoleApp1 migrations add init
This idea came from a comment by @ivanruski here: #https://github.com/aspnet/EntityFrameworkCore/issues/10298
BTW my dll app is:
<TargetFrameworks>netcoreapp2.0.7;netstandard2.0</TargetFrameworks>
ConsoleApp is:
<TargetFramework>netcoreapp2.0.7</TargetFramework>