dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.62k stars 1.96k forks source link

Document how to execute migrations without the .NET Core SDK installed #807

Open jholovacs opened 6 years ago

jholovacs commented 6 years ago

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.

jsancho commented 6 years ago

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/

ajcvickers commented 6 years ago

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

Specifically, it would be useful to:

bricelam commented 5 years ago

benday's tool: Build & Release Tools

jholovacs commented 5 years ago

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.

zordark commented 3 years ago

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