dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.66k stars 3.15k forks source link

Migrations Bundles #19693

Closed bricelam closed 3 years ago

bricelam commented 4 years ago

We currently have dotnet ef migrations script and database update to apply migrations. Unfortunately, they each have their shortcomings.

migrations script is pretty good at producing SQL scripts (there are some known issues with the scripts), but figuring out what to do with those scripts may not be obvious. Publish from Visual Studio wraps these scripts up in a web deployment package and uses MSDeploy to run them on the server. This works well for SQL Server on Windows, but nothing else.

database update is a lot better at applying migrations. It doesn't have any of the issues the SQL script does. Unfortunately, it requires the .NET Core SDK, your app's source code, and a direct connection to the production database. Having all of these things available where you need them is't always possible.

I propose we introduce a new migrations bundle command. This would create a self-contained EXE that you could use to apply migrations. It would behave the same as database update and let you specify the connection string. This would make SSH/Docker/PowerShell deployment a lot easier. You wouldn't need to copy your source files to a server inside the firewall and you wouldn't need to install the .NET Core SDK. Here is an example of what it might look like to use SSH:

dotnet ef migrations bundle
scp bundle me@myhost.com:./
ssh me@myhost.com "./bundle --connectionString ${DEPLOYMENT_CONNECTION_STRING}"
ssh me@myhost.com "rm bundle"

Taking this further, Visual Studio could do all of this for you like they do today on MSDeploy but when you're deploying to Docker. They could even create a new SSH deployment experience.


TODO

tibitoth commented 4 years ago

@bricelam Why not use dacpac? I have not seen any better approach for MSSQL.

We try to embrace sqlproj (in this sense it's DB first) + reverse engineer code first on every change + dacpac migrations.

bricelam commented 4 years ago

dacpac is perfect for DB-first; keep using it there. However, it's fundamentally different from Migrations which are designed for a code-first workflow. Also, dacpac is SQL Server-only and a big part of these bundles is to improve the experience when using other databases like PostgreSQL, MySQL, and Oracle.

Fun fact, the first prototype of Migrations was based on dacpac.

ErikEJ commented 4 years ago

FWIW, "EF Core Power Tools" supports Reverse Engineering directly from a dacpac / SQL Database project (.sqlproj)

leealexander commented 4 years ago

migrations script is pretty good at producing SQL scripts (there are some known issues with the scripts)

Could you elaborate on the issues?

database update is a lot better at applying migrations.

In what way(s) is update better?

I take it the SQL isn't the same if I was to look at trace logs of the two different update methods?

bricelam commented 4 years ago

The SQL is the same, the differences (and issues) stem from things like when transactions begin and end, the if blocks (some statements aren’t allowed inside), and how the script is parsed (some objects are created at the beginning of the script but the parser/compiler errors because later statements reference them.

bricelam commented 4 years ago

Items to address issues with the script: #7681 #12911 #14746 #19740

ajcvickers commented 4 years ago

Team note: make sure to consider how bundles interact with continuous deployment systems. See #9841.

ajcvickers commented 4 years ago

Unfortunately, while we have made good progress in understanding the space here, we are deferring release of the migrations bundles feature until after the EF Core 5.0 release to provide more time for feedback. The current plan is to get something into preview near the beginning of the EF Core 6.0 milestone so that we have enough time for feedback, integration, and testing before committing.

ivanmonteiro commented 3 years ago

I'm not sure if it is the right place, but here are my considerations: It would be interesting if the migrations bundle could be built and run on both Windows/Linux platforms.

Currently I'm developing using a Windows machine and deploying to a Linux server. Also, my CI workflow uses Linux machines under the covers. So being able to choose the target platform would be great.

JohnnySixStrings commented 3 years ago

This is currently an issue I'm interested in we currently work with multiple databases including postgres, mysql, sql server. Using azure pipelines we have not found a suitable way to deploy migrations since migration script will not work with postgres.

roji commented 3 years ago

@JohnnySixStrings migration scripts generally work fine with PostgreSQL - I'm guessing you're running into issues with maintaining migrations with multiple providers (see this doc page).

If you're encountering specific issues with PostgreSQL migrations, that probably isn't related to this issue - can you please open an issue on https://github.com/npgsql/efcore.pg?

rhyswat commented 3 years ago

A common use case for me is that the production database is not accessible from my workstation - not directly, and not over a tunnel either - typically due to clients' on-prem requirements.

So the proposed bundle -> copy -> run -> cleanup workflow would work well in these cases.

One thing to consider is that the putative bundle executable needs to be runnable on a different platform to the one where it was built. For example, my use case might require building the bundle on an Ubuntu box then copying it and running it against an MS SQL database on a Windows Server box.

I realise that we can target runtimes when building our applications, so I wonder whether a) this is necessary and b) whether this is possible for bundle executables.

ivanmonteiro commented 3 years ago

With migrations bundle ideally It would be possible to also run the migrations using the dotnet runtime image instead of the dotnet sdk image which is bigger and not ideal for final stages of docker containers.

I see no problem using the dotnet sdk image for the build stage of the bundle but actually running the migrations bundle should be using the more lightweight runtime image instead.

Also migration bundles ideally shoud run on both docker for linux OR on Windows containers, as the client's existing infrastructure might require that.

bricelam commented 3 years ago

📢 Status update

I got an end-to-end working. There are still a lot of details to sort out before sending a PR...

Bundles

bricelam commented 3 years ago

An initial implementation was just merged. It'll be in Preivew 7 (August).

You can try it out using the daily builds:

dotnet tool update -g dotnet-ef --version 6.0.0-* --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json
dotnet ef migrations bundle
./bundle

Or from Visual Studio:

Bundle-Migration
.\bundle.exe

See TODO list in issue description for what's still missing.

julielerman commented 3 years ago

Hey @bricelam ...should this work with SQLite yet? I'm targeting 6.0.0-rc.1.21409.2 for packages and the tools. Getting

Method 'AppendIdentityWhereCondition' in type 'Microsoft.EntityFrameworkCore.Sqlite.Update.Internal.SqliteUpdateSqlGenerator' from assembly 'Microsoft.EntityFrameworkCore.Sqlite, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

If that's new to you then maybe it's related to my model and I can dig further. But here is what's in the UP of my one and only migration file

migrationBuilder.CreateTable(
                name: "People",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "TEXT", nullable: false),
                    FirstName = table.Column<string>(type: "TEXT", nullable: true),
                    LastName = table.Column<string>(type: "TEXT", nullable: true),
                    Name_FirstName = table.Column<string>(type: "TEXT", nullable: true),
                    Name_LastName = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_People", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Address",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "TEXT", nullable: false),
                    Street = table.Column<string>(type: "TEXT", nullable: true),
                    PostalCode = table.Column<string>(type: "TEXT", nullable: true),
                    AddressType = table.Column<int>(type: "INTEGER", nullable: false),
                    PersonId = table.Column<Guid>(type: "TEXT", nullable: false),
                    StreetLine2 = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Address", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Address_People_PersonId",
                        column: x => x.PersonId,
                        principalTable: "People",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Address_PersonId",
                table: "Address",
                column: "PersonId");

Also note: database-update works from this migration.

julielerman commented 3 years ago

Note: I removed the owned entity from the model, trashed original migrations and created a new migration from scratch. Same error when trying to execute the new bundle so it wasn't the owned entity. :)

roji commented 3 years ago

@julielerman this is most likely as a result of mixing EF Core versions - can you check in your csproj that all versions are exactly the same etc.?

julielerman commented 3 years ago

@roji Hi there. Only package refs are 6.0.0-*

I am targetting daily builds with nuget.config

<packageSources>
        <add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    </packageSources>

In projects.assets.json all efcore packages are the same version:

"Microsoft.EntityFrameworkCore.Sqlite/6.0.0-rc.1.21409.2": {

Microsoft.EntityFrameworkCore.Relational/6.0.0-rc.1.21409.2": { "Microsoft.EntityFrameworkCore.Design/6.0.0-rc.1.21409.2": {

And I installed the same version of the efcore tools as per Brice's note above.

I'm going to test against sql server now (just had to get my container running :) )

julielerman commented 3 years ago

same with sql server. Ok...so it's me. I just don't know what... :) Shall I drop my little sample (or just project.assets.json) on github? Wait for preview 7?

ErikEJ commented 3 years ago

Please share your .csproj

julielerman commented 3 years ago

not much in there:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0-*" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-*" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlserver" Version="6.0.0-*" />

  </ItemGroup>

</Project>
julielerman commented 3 years ago

GOT IT! Even though 6.0.0.-* was giving me the correct versions (as per assets file), specifically targeting brought me success

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-rc.1.21409.2" />

(for sqlserver...new problem with sqlite ...will investigate . Database update works but bundle doesn't)

This is a very long conversation about the problem I'm seeing (Unable to load shared library 'e_sqlite3' or one of its dependencies.) https://github.com/dotnet/efcore/issues/19396

julielerman commented 3 years ago

update on my SQLite bundle problem (Unable to load shared library e_sqlite3 or one of its dependencies)

Failing on TWO MacBooks. I spent a bunch of hours trying to find a solution. (Reminder: that worked when I targeted SQL Server). (note: updating one of these machines from catalina to big sur did not change the problem.

Same project ...success on Windows (using VS Code and CLI). Gah! // @bricelam (sorry)

gunniwho commented 3 years ago

Is it possible to provide the connection string via the file system? Something like bundle --connection-file /vault/secrets/connection

bricelam commented 3 years ago

@gunniwho Yes, like dotnet ef, the bundle honors response files.

bundle --connection @/vault/secrets/connection
EricStG commented 3 years ago

Would it be possible to add an option to the bundle to preview the scripts (--script or --dryrun or something)? Ideally, we'd want a manual approval step in our pipeline after human eyeballs review the output. I know this can be generated from the ef core tools, but ideally we'd want to use the bundle's artifact on its own

lohithgn commented 3 years ago

@bricelam Awesome addition to EF. Where can I find official documentation on migration bundles ?

roji commented 3 years ago

@lohithgn docs aren't yet available as this feature is just now being finished. They should appear by the time EF Core 6.0 ships, and will be available under the migration section of the docs.

ryanrichard19 commented 3 years ago

Attempting to run Bundle-Migration on the Packege-Manager Console with latest VS Preview and getting the following error Bundle-Migration Build started... Build succeeded. Building bundle... Build failed. Use --verbose to see errors.

The way to create the migration and build it works fine for me.

Here is my project metadata

net6.0

Hope this helps

julielerman commented 3 years ago

@ryanrichard19 can you run it with --verbose and share any errors that reveals?

ryanrichard19 commented 3 years ago

When I try that I get this @julielerman Bundle-Migration --verbose Bundle-Migration : A positional parameter cannot be found that accepts argument '--verbose'. At line:1 char:1

ErikEJ commented 3 years ago

Please try running with -Verbose

ryanrichard19 commented 3 years ago

Thanks @ErikEJ now I get this PM> Bundle-Migration -Verbose Using project 'MarketingIncentive.Data'. Using startup project 'MarketingIncentive.API'. Build started... Build failed.

ErikEJ commented 3 years ago

And both these projects can build in VS?

ryanrichard19 commented 3 years ago

Yes I can run migrations the other way and that works for me. Could it be due to me having the Data project separated?

ErikEJ commented 3 years ago

Does your entire solution build without errors??

ryanrichard19 commented 3 years ago

Yes it does. If I Run Add-Migrations test I get this PM> Add-Migration test Build started... Build succeeded. To undo this action, use Remove-Migration.

julielerman commented 3 years ago

Since I'm working on my macbook, I'm curious if you get the same problem if you go to the command line and run the CLI version (dotnet ef migrations bundle). My small demo isn't in separate projects but I can try that.

ryanrichard19 commented 3 years ago

Should I be in the .Data project folder when I run the CLI command?

ryanrichard19 commented 3 years ago

from the .data folder ❯ dotnet ef migrations bundle Build started... Build succeeded. Specify --help for a list of available options and commands. Unrecognized command or argument 'bundle' ⨯ mrrar@DESKTOP-0VK5K1M  ~\Development\MarketingIncentive\MarketingIncentive.Data   main ≣ +2 ~26 -1 ! 

ryanrichard19 commented 3 years ago

Just ran the following dotnet tool update --global dotnet-ef --version 6.0.0-preview.7.21378.4 Tool 'dotnet-ef' was successfully updated from version '3.1.5' to version '6.0.0-preview.7.21378.4'. mrrar@DESKTOP-0VK5K1M  ~\Development\MarketingIncentive\MarketingIncentive.Data   main ≣ +2 ~26 -1 !  [17:10] ❯ dotnet ef migrations bundle Build started... Build succeeded. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. File name: 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark, IntPtr pPrivHostBinder) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark) at System.Reflection.Assembly.Load(String assemblyString) at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.get_EFCoreVersion() at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args) at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)

Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

ErikEJ commented 3 years ago

Can you share your .csproj?

julielerman commented 3 years ago

sorry I don' t mean to lead you down a completely different set of problems. Follow Erik's lead in VS /Windows. Also, (on mac) I just separated my demo into three folders: domain (library), data (library) and app (console). I'm using SQLite and nightly builds and bundle worked as expected.

ryanrichard19 commented 3 years ago

@julielerman no worries. Amazing trying to figure this out with you and @ErikEJ.

@ErikEJ I cant share this proj as it is in a private repo for a client. Will set up a new public repo to see if I get this error. Thanks all for your help.

ryanrichard19 commented 3 years ago

So I added the ef design package to my project

net6.0 all runtime; build; native; contentfiles; analyzers; buildtransitive

and rerun the command in Package Console manger and i get this now

PM> Bundle-Migration -Verbose Using project 'MarketingIncentive.Data'. Using startup project 'MarketingIncentive.API'. Build started... Build succeeded. C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.API.deps.json --additionalprobingpath C:\Users\mrrar.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.API.runtimeconfig.json C:\Users\mrrar.nuget\packages\microsoft.entityframeworkcore.tools\6.0.0-preview.7.21378.4\tools\netcoreapp2.0\any\ef.dll migrations bundle --verbose --no-color --prefix-output --assembly C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll --project C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\MarketingIncentive.Data.csproj --startup-assembly C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.API.dll --startup-project C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj --project-dir C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\ --language C# --working-dir C:\Users\mrrar\Development\MarketingIncentive --root-namespace MarketingIncentive.Data Using assembly 'MarketingIncentive.Data'. Using startup assembly 'MarketingIncentive.API'. Using application base 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0'. Using working directory 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API'. Using root namespace 'MarketingIncentive.Data'. Using project directory 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\'. Remaining arguments: . Finding DbContext classes... Finding IDesignTimeDbContextFactory implementations... Finding application service provider in assembly 'MarketingIncentive.API'... Finding Microsoft.Extensions.Hosting service provider... Using environment 'Development'. Using application service provider from Microsoft.Extensions.Hosting. Found DbContext 'MarketingIncentiveDBContext'. Finding DbContext classes in the project... Using context 'MarketingIncentiveDBContext'. Building bundle... dotnet publish --output C:\Users\mrrar\AppData\Local\Temp\etc5av4u.vrh\publish Microsoft (R) Build Engine version 17.0.0-preview-21378-03+d592862ed for .NET Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... Restored C:\Users\mrrar\AppData\Local\Temp\etc5av4u.vrh\bundle.csproj (in 319 ms). 2 of 3 projects are up-to-date for restore. You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview MarketingIncentive.Data -> C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 2 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 3 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 4 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 6 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 7 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 8 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 9 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 10 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): error MSB3027: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Exceeded retry count of 10. Failed. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): error MSB3021: Unable to copy file "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj] Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors. at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args) in ef.dll:token 0x60001a9+0x23b at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.b__0(String[] args) in ef.dll:token 0x6000205+0x3b at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) in ef.dll:token 0x6000053+0x100 at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) in ef.dll:token 0x60000cf+0x2e Build failed. Use --verbose to see errors.

ryanrichard19 commented 3 years ago

Just restarted my PC and retried and get the same error.

bricelam commented 3 years ago

Hmm, it looks like something is breaking the incremental build causing a full rebuild of the startup project. Do you have any custom targets?

ryanrichard19 commented 3 years ago

No I dont. Pretty much standard entity framework and dbcontext setup

bricelam commented 3 years ago

I'm able to repro this on the latest bits. dotnet ef works but VS fails. Filing a new issue to follow up: #25555