Entityframework.docs: Document how to execute migrations without the .NET Core SDK installed

Created on 5 Jul 2018  Â·  5Comments  Â·  Source: dotnet/EntityFramework.Docs

I keep getting told the project can't be found. Why is the project necessary? The code is contained in the dlls. How do I take my published code as an artifact and run the database update?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

area-migrations area-tools propose-punt punted-for-5.0

Most helpful comment

I'm doing a workaround now by creating an idempotent migration script in my build:

dotnet ef migrations script --idempotent --output "$(Build.ArtifactStagingDirectory)/migrations.sql" --context MySolution.MyDataAccessProject.Services.AnalysisDbContext

...then I run this like any other sql script in a powershell window. It seems a little kludgy, but... eh, it works.

All 5 comments

Not that straightforward to do manually.
We have ended up using the VSTS task from Ben Day, he's also published scripts for win/linux to execute the migrations.
https://www.benday.com/2018/07/05/deploy-entity-framework-core-2-1-migrations-from-a-dll/

See also the discussion here: https://github.com/aspnet/EntityFrameworkCore/issues/13339

Specifically, it would be useful to:

  • Make sure that people understand that the dotnet tools can be used if the SDK is installed
  • For people who can't install the SDK, link to these blog posts
  • Add benday's tool to the EF core extensions document.

benday's tool: Build & Release Tools

I'm doing a workaround now by creating an idempotent migration script in my build:

dotnet ef migrations script --idempotent --output "$(Build.ArtifactStagingDirectory)/migrations.sql" --context MySolution.MyDataAccessProject.Services.AnalysisDbContext

...then I run this like any other sql script in a powershell window. It seems a little kludgy, but... eh, it works.

We are working in .net 4.8 environment and using next workaround.
In csproj file with migrations we are coping all dependencies to output folder:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
      <IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
      <Publish>true</Publish>
    </PackageReference>
     ...
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9" GeneratePathProperty="true">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    ...
   <ItemGroup>
      <None Include="$(PkgMicrosoft_EntityFrameworkCore_Tools)\tools\net461\any\ef.exe" CopyToOutputDirectory="PreserveNewest" />
   </ItemGroup>

So we don't need to know where is Microsoft.EntityFrameworkCore.Tools installed and we can run migrations much easily.
With powershell something like that:

.\ef.exe database update --assembly <assembly name>.dll

with dotnet core you can do the same, all you need is replace ef.exe path with ef.dll path, something like that: \tools\netcoreapp2.0\any\ef.dll

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CubeSpark picture CubeSpark  Â·  3Comments

ajcvickers picture ajcvickers  Â·  4Comments

jpeckham picture jpeckham  Â·  3Comments

ctaggart picture ctaggart  Â·  3Comments

SychevIgor picture SychevIgor  Â·  4Comments