Webdeploy + EFCore migration : how to set target project

asp.net-core entity-framework-core webdeploy


In our ASP.NET Core 2.1 solution, we have placed EF and migrations into a separate project.

It is fine for us manage migrations from default project thanks to CLI e.g :

dotnet ef migrations add NewMigration --project MyApp.MyBdd

In this example, we set MyApp.MyBdd as target project.

But the WebDeploy wizard doesn't shows any settings about Bdd migration.

I can manually set EF migration into pubxml file like this :

Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
       <TimeStampOfAssociatedLegacyPublishXmlFile />
       <EncryptedPassword />
      <EFMigrations Include="MyApp.MyBdd.MyDbContext">
         <Value>Server=MyServer%3bDatabase=MyBdd%3bIntegrated Security=True%3b</Value>

Entity Framework SQL Script generation fails (nothing into logs)

Question: how to set target project to webdeploy settings file?

10/31/2018 9:36:14 PM

Accepted Answer

EDIT Thanks to @IvanStoev for pointing out that there is a way shown in the source code. Add this to your <PropertyGroup>:

     --project MyApp.MyBdd

ORIGINAL ANSWER Unfortunately that's not possible. EFMigrations is used by a build task called GenerateEFSQLScripts (see source) which always uses the project being deployed for migrations, as identified by the MSBuildProjectDirectory variable. You can see here that it's that project being run here, without any options to override it.

I see two options: You could refactor your code so that your DbContext lives in the project you are deploying, or you could run the migrations not during deploy but on application startup, i.e. add


to your Startup.Configure() implementation.

11/7/2018 7:43:11 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow