dotnet / dotnet/efcore

EF Tools Migration Bundle Ignores --force option when specifying a output directory

Open
#33,589 0 comments 0 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-tools customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

When building a Bundle to apply migrations to another machine, the force option fails to overwrite an existing bundle if you are specifying a custom output directory for the bundle.

```C#
dotnet ef migrations bundle -f --output "C:\PublishTestDirecory"
```
The bundle fails to build if an existing bundle exists
```
Building bundle...
System.IO.IOException: Cannot create a file when that file already exists.
at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.b__0(String[] args)
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Cannot create a file when that file already exists.
```

Running the same option without an output directory works as expected with no errors

```C#
dotnet ef migrations bundle -f
```

```
Building bundle...
Done. Migrations Bundle: C:\PublishTestDirecory\efbundle.exe
Don't forget to copy appsettings.json alongside your bundle if you need it to apply migrations.
```

### Include provider and version information
Entity Framework Core .NET Command-line Tools 8.0.4
EF Core version: 8.0.4
Database provider: (e.g. Pomelo.EntityFrameworkCore.MySql)
Target framework: (e.g. .NET 8.0)
Operating system: Windows
IDE: (e.g. Visual Studio 2022 17.9.6)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.