Closed bricelam closed 3 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.
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.
FWIW, "EF Core Power Tools" supports Reverse Engineering directly from a dacpac / SQL Database project (.sqlproj)
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?
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.
Items to address issues with the script: #7681 #12911 #14746 #19740
Team note: make sure to consider how bundles interact with continuous deployment systems. See #9841.
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.
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.
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.
@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?
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.
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.
I got an end-to-end working. There are still a lot of details to sort out before sending a PR...
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.
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.
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. :)
@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.?
@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 :) )
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?
Please share your .csproj
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>
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
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)
Is it possible to provide the connection string via the file system? Something like bundle --connection-file /vault/secrets/connection
@gunniwho Yes, like dotnet ef
, the bundle honors response files.
bundle --connection @/vault/secrets/connection
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
@bricelam Awesome addition to EF. Where can I find official documentation on migration bundles ?
@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.
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
Hope this helps
@ryanrichard19 can you run it with --verbose and share any errors that reveals?
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
+ CategoryInfo : InvalidArgument: (:) [Bundle-Migration], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Bundle-Migration
Please try running with -Verbose
Thanks @ErikEJ now I get this PM> Bundle-Migration -Verbose Using project 'MarketingIncentive.Data'. Using startup project 'MarketingIncentive.API'. Build started... Build failed.
And both these projects can build in VS?
Yes I can run migrations the other way and that works for me. Could it be due to me having the Data project separated?
Does your entire solution build without errors??
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.
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.
Should I be in the .Data project folder when I run the CLI command?
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 !
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.
Can you share your .csproj?
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.
@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.
So I added the ef design package to my project
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.
Just restarted my PC and retried and get the same error.
Hmm, it looks like something is breaking the incremental build causing a full rebuild of the startup project. Do you have any custom targets?
No I dont. Pretty much standard entity framework and dbcontext setup
I'm able to repro this on the latest bits. dotnet ef
works but VS fails. Filing a new issue to follow up: #25555
We currently have
dotnet ef migrations script
anddatabase 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 asdatabase 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: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
--output
to allow renaming the bundleRuntimeIdentifier, and SelfContainedof startup project by defaultAdd--no-self-contained
--self-contained
doesn't work--runtime
doesn't work between Windows and other OSes. We look for .exe based on the current runtime instead of the target* runtime.--force
to overwrite an existing bundle #25271--configuration
and--runtime
optoins are repeated in help