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.73k stars 3.18k forks source link

Bundle-Migration errors with "cannot access file...being used by another process" #25555

Open bricelam opened 3 years ago

bricelam commented 3 years ago

Originally reported by @ryanrichard19 in https://github.com/dotnet/efcore/issues/19693#issuecomment-900396649

For some reason, dotnet publish is behaving differently between Bundle-Migration and dotnet ef migrations bundle.

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.<Configure>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.
ajcvickers commented 3 years ago

Note from triage: consider removing.

karl-sjogren commented 3 years ago

I'm seeing the same problem when running dotnet ef migrations bundle --verbose while the project is open in VSCode. If I close VSCode it works. I'm running on preview7 on Windows 10 and I've tried by removing my runtime targets and such but the error persists even with a minimal project file (see below).

$ dotnet ef migrations bundle --verbose
Using project 'X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj'.
Using startup project 'X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj'.
Writing 'X:\Github\songbird\src\Songbird.Web\obj\Songbird.Web.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Karl\AppData\Local\Temp\tmp5143.tmp /verbosity:quiet /nologo X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj
Writing 'X:\Github\songbird\src\Songbird.Web\obj\Songbird.Web.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Karl\AppData\Local\Temp\tmp5309.tmp /verbosity:quiet /nologo X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj
Build started...
dotnet build X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.33
Build succeeded.
dotnet exec --depsfile X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.deps.json --additionalprobingpath C:\Users\Karl\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.runtimeconfig.json C:\Users\Karl\.nuget\packages\dotnet-ef\6.0.0-preview.7.21378.4\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations bundle --assembly X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll --project X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj --startup-assembly X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll --startup-project X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj --project-dir X:\Github\songbird\src\Songbird.Web\ --root-namespace Songbird.Web --language C# --working-dir X:\Github\songbird\src\Songbird.Web --verbose
Using assembly 'Songbird.Web'.
Using startup assembly 'Songbird.Web'.
Using application base 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0'.
Using working directory 'X:\Github\songbird\src\Songbird.Web'.
Using root namespace 'Songbird.Web'.
Using project directory 'X:\Github\songbird\src\Songbird.Web\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'Songbird.Web'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'SongbirdContext'.
Finding DbContext classes in the project...
Using context 'SongbirdContext'.
Building bundle...
dotnet publish --output C:\Users\Karl\AppData\Local\Temp\pqtfcewu.r5o\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\Karl\AppData\Local\Temp\pqtfcewu.r5o\bundle.csproj (in 735 ms).
  1 of 2 projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 2 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 3 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 4 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 6 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 7 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 8 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 9 in 1000ms. The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): warning MSB3026: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Beginning retry 10 in 1000ms. The process cannot 
access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): error MSB3027: Could not copy "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". Exceeded retry count of 10. Failed.  [X:\Github\songbird\src\Songbird.Web\Songbird.Web.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4508,5): error MSB3021: Unable to copy file "obj\Debug\net6.0\Songbird.Web.dll" to "bin\Debug\net6.0\Songbird.Web.dll". The process cannot access the file 'X:\Github\songbird\src\Songbird.Web\bin\Debug\net6.0\Songbird.Web.dll' because it is being used by another process. [X:\Github\songbird\src\Songbird.Web\Songbird.Web.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.<Configure>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.

This is the project I'm trying to build a bundle for. Both building and publishing works fine.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AspNetCore.HealthChecks.UI" Version="5.0.1" />
    <PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
    <PackageReference Include="AutoMapper.Collection" Version="7.0.1" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
    <PackageReference Include="LetterAvatars.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.0-preview.7.21378.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-preview.7.21378.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.7.21378.4" />
    <PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="6.0.0-preview.7.21378.6" />
    <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.0-preview.7.21378.6" />
    <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.0-preview.7.21378.6" />
    <PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="6.0.0-preview.7.21378.6" />
    <PackageReference Include="Microsoft.Identity.Web" Version="1.16.0" />
    <PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.16.0" />
    <PackageReference Include="NEST" Version="7.14.1" />
    <PackageReference Include="NEST.JsonNetSerializer" Version="7.14.1" />
    <PackageReference Include="RobotsTxtCore" Version="1.1.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
  </ItemGroup>
</Project>
bricelam commented 3 years ago

This appears to be fixed on RC1 with latest version of Visual Studio. I wonder if OmniSharp just needs to catch up too...

keenjus commented 3 years ago

Seems like it is broken again with dotnet-ef 6.0.0-rc.2.21480.5 ? This error does not appear with 6.0.0-rc.1.21452.10

julielerman commented 3 years ago

gah ... I'm getting it now too (preparing for conference demo this week eek) VS Code on Windows using EF Core Version="6.0.0-rtm.21518.2 I have the same version of the tools. Dotnet version 6.0.100-rc.2.21505.57. "Punted for 6" as in not getting fixed??

sturlath commented 3 years ago

I´m getting this error both with 6.0.0-rc.1.21452.10 and 6.0.0-rc.2.21480.5 it doesn´t matter if restart the machine and just run the bundle script.

C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]

Workaround: I downloaded LockHunter and pointed it to the EFCoreMigrationWeb.dll and when the dotnet process was showing this warning I unlocked the process and it finished creating the bundle.

Below is the complete output log. I also uploaded the project to here if you would like to try it out.

C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore> dotnet ef migrations bundle --verbose
Using project 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj'.
Using startup project 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj'.
Writing 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\obj\EFCoreMigrationWeb.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\sturla.thorvaldsson\AppData\Local\Temp\tmp3D.tmp /verbosity:quiet /nologo C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj
Writing 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\obj\EFCoreMigrationWeb.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\sturla.thorvaldsson\AppData\Local\Temp\tmp222.tmp /verbosity:quiet /nologo C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj
Build started...
dotnet build C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj /verbosity:quiet /nologo
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Email.cs(5,23): warning CS8618: Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Email.cs(6,23): warning CS8618: Non-nullable property 'EmailAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(6,23): warning CS8618: Non-nullable property 'StreetAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(7,23): warning CS8618: Non-nullable property 'City' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(8,23): warning CS8618: Non-nullable property 'State' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(9,23): warning CS8618: Non-nullable property 'PostalCode' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Person.cs(8,23): warning CS8618: Non-nullable property 'FirstName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Person.cs(9,23): warning CS8618: Non-nullable property 'LastName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Program.cs(155,12): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]

Build succeeded.

C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Email.cs(5,23): warning CS8618: Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Email.cs(6,23): warning CS8618: Non-nullable property 'EmailAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(6,23): warning CS8618: Non-nullable property 'StreetAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(7,23): warning CS8618: Non-nullable property 'City' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(8,23): warning CS8618: Non-nullable property 'State' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(9,23): warning CS8618: Non-nullable property 'PostalCode' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Person.cs(8,23): warning CS8618: Non-nullable property 'FirstName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Person.cs(9,23): warning CS8618: Non-nullable property 'LastName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Program.cs(155,12): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
    9 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.05
Build succeeded.
dotnet exec --depsfile C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.deps.json --additionalprobingpath C:\Users\sturla.thorvaldsson\.nuget\packages --runtimeconfig C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.runtimeconfig.json C:\Users\sturla.thorvaldsson\.dotnet\tools\.store\dotnet-ef\6.0.0-rc.1.21452.10\dotnet-ef\6.0.0-rc.1.21452.10\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations bundle --assembly C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll --project C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj --startup-assembly C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll --startup-project C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj --project-dir C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\ --root-namespace EFCoreMigrationWeb --language C# --framework net6.0 --nullable --working-dir C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore --verbose
Using assembly 'EFCoreMigrationWeb'.
Using startup assembly 'EFCoreMigrationWeb'.
Using application base 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0'.
Using working directory 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore'.
Using root namespace 'EFCoreMigrationWeb'.
Using project directory 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'EFCoreMigrationWeb'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'TodoDbContext'.
Finding DbContext classes in the project...
Using context 'TodoDbContext'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 6.0.0-rc.2.21480.5 initialized 'TodoDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0-rc.2.21480.5' with options: None
Building bundle...
dotnet publish --runtime win10-x64 --output C:\Users\sturla.thorvaldsson\AppData\Local\Temp\i35uregs.wj3\publish --no-self-contained
Microsoft (R) Build Engine version 17.0.0-preview-21460-01+8f208e609 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored C:\Users\sturla.thorvaldsson\AppData\Local\Temp\i35uregs.wj3\efbundle.csproj (in 420 ms).
  Restored C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj (in 420 ms).
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(6,23): warning CS8618: Non-nullable property 'StreetAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(7,23): warning CS8618: Non-nullable property 'City' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(8,23): warning CS8618: Non-nullable property 'State' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Address.cs(9,23): warning CS8618: Non-nullable property 'PostalCode' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Email.cs(5,23): warning CS8618: Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Email.cs(6,23): warning CS8618: Non-nullable property 'EmailAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Person.cs(8,23): warning CS8618: Non-nullable property 'FirstName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Models\Person.cs(9,23): warning CS8618: Non-nullable property 'LastName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\Program.cs(155,12): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 2 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 3 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 4 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 6 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 7 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 8 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 9 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 10 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): error MSB3027: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Exceeded retry count of 10. Failed.  [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): error MSB3021: Unable to copy file "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]
Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors.
   at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Build failed. Use --verbose to see errors.
julielerman commented 3 years ago

Same ...I tried reverting to the earlier build with no luck. @bricelam mentioned that it's a problem with Omnisharp. (I can run the command from the visual studio command prompt ONLY IF VS CODE IS CLOSED...a little clunky for a conference demo but that's what I'll have to do). Is there an issue filed on the omnisharp end?

Further experiments: DIsabled Omnisharp (C# Extension) in VS COde and reloaded and was able to run the bundle command successfully. As for my demo, I can leave C# disabled and perform all of the tasks. (run efbundle, dotnet run, modify code, add a new migration, bundle again, dotnet run) to show idempotency . Just no intellisense. That will work. Just as long as I remember to enable it again for the next demos! 😆

julielerman commented 3 years ago

It is NOW working in VS Code. Not sure if the latest nightly build did the trick, @bricelam (now getting 21519.8) but guessing that's it. 🥇 I ran dotnet ef migrations bundle --force repeatedly and it worked each time. (With C# enabled 😁 )

15 minutes later. I closed and opened VS Code and tried again and ....SOB...it's back. sorry about that

anuraj commented 2 years ago

I am facing the same issue with 6.0.0-rtm.21519.8. Here is the log - error MSB3021: Unable to copy file "obj\Debug\net6.0\demo2.dll" to "bin\Debug\net6.0\demo2.dll". The process cannot access the file 'C:\demo2\bin\Debug\net6.0\demo2.dll' because it is being used by another process.

I don't have VS Code is running and C# extension is disabled in VS Code.

DanoThom commented 2 years ago

Same here. LockHunter says the file(s) aren't being locked at all however.

image

mcaden commented 2 years ago

I ran into this without VS Code or Visual Studio open at all - simply running from CLI (tried windows terminal - powershell/cmd, and cmd standalone).

However, I found an odd workaround that works but it seems to me that it works because of a bug.

If I execute dotnet ef migrations bundle --verbose --configuration Debug (or leave --configuration off, or change to Release) It executes and fails as described:

dotnet build C:\dev\...\MyProject.Web\MyProject.Web.csproj --configuration Debug /verbosity:quiet /nologo
...
dotnet publish --runtime win10-x64 --output C:\Users\me\AppData\Local\Temp\exndyuow.3es\publish --no-self-contained --configuration Debug

However, I noticed that if I run the same command with --configuration Bundle it did this:

dotnet build C:\dev\...\MyProject.Web\MyProject.Web.csproj --configuration Bundle /verbosity:quiet /nologo
...
dotnet publish --runtime win10-x64 --output C:\Users\me\AppData\Local\Temp\m15pxos2.mpo\publish --no-self-contained

Note that the publish call doesn't include the --configuration flag, but the dotnet build does.

It seems that if I set --configuration to Debug or Release it propagates to both the build and publish calls but if I set it to anything else it gets used for the build but not the publish. I believe this to be a bug (I'd assume config would be passed to both commands always), but because of it that means that the 'build' step and 'publish' step are using different working directories.

I'm on

Edit: I downloaded and installed LockHunter. It DOES say that my dll in the bin folder is locked by dotnet exec ... which happens as a part of the bundle process.

dotnet.exe Process ID: 24084 Command Line: "dotnet" exec --depsfile C:\dev\MyProject\bin\Debug\net6.0\MyProject.deps.json --additionalprobingpath C:\Users\me.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\dev\MyProject\bin\Debug\net6.0\MyProject.runtimeconfig.json C:\Users\me.dotnet\tools.store\dotnet-ef\6.0.0\dotnet-ef\6.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations bundle --force --assembly C:\dev\MyProject\bin\Debug\net6.0\MyProject.dll --project C:\dev\MyProject\MyProject.csproj --startup-assembly C:\dev\MyProject\bin\Debug\net6.0\MyProject.dll --startup-project C:\dev\MyProject\MyProject.csproj --project-dir C:\dev\MyProject\ --root-namespace MyProject --language C# --framework net6.0 --working-dir C:\dev\MyProject --verbose

ZeusAFK commented 2 years ago

Same with Azure build pipeline and net core 6.0.100 ef tools 6.0.0:

dotnet ef migrations bundle --configuration Release --project MyProject/MyProject.csproj --verbose "C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a_temp\d1b341b4-301f-4550-a431-bc4a38837ef9.cmd"" Using project 'D:\a\1\s\MyProject\MyProject.csproj'. Using startup project 'D:\a\1\s\MyProject\MyProject.csproj'. Writing 'D:\a\1\s\MyProject\obj\MyProject.csproj.EntityFrameworkCore.targets'... dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpA5E3.tmp /verbosity:quiet /nologo D:\a\1\s\MyProject\MyProject.csproj Writing 'D:\a\1\s\MyProject\obj\MyProject.csproj.EntityFrameworkCore.targets'... dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpA8A3.tmp;Configuration=Release /verbosity:quiet /nologo D:\a\1\s\MyProject\MyProject.csproj Build started... dotnet build D:\a\1\s\MyProject\MyProject.csproj --configuration Release /verbosity:quiet /nologo D:\a\1\s\MyProject\Startup.cs(36,17): warning SYSLIB0020: 'JsonSerializerOptions.IgnoreNullValues' is obsolete: 'JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull.' [D:\a\1\s\MyProject\MyProject.csproj]

Build succeeded.

D:\a\1\s\MyProject\Startup.cs(36,17): warning SYSLIB0020: 'JsonSerializerOptions.IgnoreNullValues' is obsolete: 'JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull.' [D:\a\1\s\MyProject\MyProject.csproj] 1 Warning(s) 0 Error(s)

Time Elapsed 00:00:01.92 Build succeeded. dotnet exec --depsfile D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.deps.json --additionalprobingpath C:\Users\VssAdministrator.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --runtimeconfig D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.runtimeconfig.json C:\Users\VssAdministrator.dotnet\tools.store\dotnet-ef\6.0.0\dotnet-ef\6.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations bundle --assembly D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll --project D:\a\1\s\MyProject\MyProject.csproj --startup-assembly D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll --startup-project D:\a\1\s\MyProject\MyProject.csproj --project-dir D:\a\1\s\MyProject\ --root-namespace MyProject --language C# --framework net6.0 --configuration Release --nullable --working-dir D:\a\1\s --verbose Using assembly 'MyProject'. Using startup assembly 'MyProject'. Using application base 'D:\a\1\s\MyProject\bin\Release\net6.0'. Using working directory 'D:\a\1\s\MyProject'. Using root namespace 'MyProject'. Using project directory 'D:\a\1\s\MyProject\'. Remaining arguments: .

Finding DbContext classes... Finding IDesignTimeDbContextFactory implementations... Finding application service provider in assembly 'MyProject'... Finding Microsoft.Extensions.Hosting service provider... Using environment 'Development'. Using application service provider from Microsoft.Extensions.Hosting. Found DbContext 'MyProjectContext'. Finding DbContext classes in the project... Using context 'MyProjectContext'. Building bundle... dotnet publish --runtime win10-x64 --output C:\Users\VssAdministrator\AppData\Local\Temp\hadixnkm.d3f\publish --no-self-contained --configuration Release Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... Restored D:\a\1\s\MyProject\MyProject.csproj (in 481 ms). Restored C:\Users\VssAdministrator\AppData\Local\Temp\hadixnkm.d3f\efbundle.csproj (in 484 ms). D:\a\1\s\MyProject\Startup.cs(36,17): warning SYSLIB0020: 'JsonSerializerOptions.IgnoreNullValues' is obsolete: 'JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull.' [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 2 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 3 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 4 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 6 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 7 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 8 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 9 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): warning MSB3026: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Beginning retry 10 in 1000ms. The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): error MSB3027: Could not copy "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". Exceeded retry count of 10. Failed. [D:\a\1\s\MyProject\MyProject.csproj] C:\hostedtoolcache\windows\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(4635,5): error MSB3021: Unable to copy file "obj\Release\net6.0\MyProject.dll" to "bin\Release\net6.0\MyProject.dll". The process cannot access the file 'D:\a\1\s\MyProject\bin\Release\net6.0\MyProject.dll' because it is being used by another process. [D:\a\1\s\MyProject\MyProject.csproj] Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors. 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) Build failed. Use --verbose to see errors.

[error]Cmd.exe exited with code '1'.

Finishing: Create migrations bundle

jerryk414 commented 2 years ago

Also getting this error.

I found that using Lockhunter, i can kill a specific instance of dotnet.exe, and it appears to create the bundle. When the bundle is created, I do end up with an error, but the .exe is still there... I have not tried it yet, so i cannot say if the bundle actually works.

I tried adding the --no-build flag to the ef migrations command, but it still seems to build when creating a bundle.

The process that i can kill to lead to the bundle creation finishing is as follows:

dotnet.exe
  Process ID: 11176
  Command Line: "dotnet" exec --depsfile C:\Users\Jerry\Documents\Github\<project_name_goeshere>.deps.json --additionalprobingpath C:\Users\Jerry\.nuget\packages --runtimeconfig C:\Users\Jerry\Documents\Github\<project_name_goeshere>.runtimeconfig.json C:\Users\Jerry\.dotnet\tools\.store\dotnet-ef\6.0.0\dotnet-ef\6.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations bundle --assembly C:\Users\Jerry\Documents\Github\<project_name_goeshere>.dll --project C:\Users\Jerry\Documents\Github\<project_name_goeshere>.csproj --startup-assembly C:\Users\Jerry\Documents\Github\<project_name_goeshere>.dll --startup-project C:\Users\Jerry\Documents\Github\<project_name_goeshere>.csproj --project-dir C:\Users\Jerry\Documents\Github\<project_name_goeshere>\ --root-namespace <project_name_goeshere> --language C# --framework net6.0 --configuration Release --working-dir C:\Users\Jerry\Documents\Github\<project_name_goeshere> --verbose
ivanmonteiro commented 2 years ago

This appears to be fixed on RC1 with latest version of Visual Studio. I wonder if OmniSharp just needs to catch up too...

@bricelam I recently updated to the latest release of .Net 6 SDK (6.0.100) on Windows 10 Pro. I was NOT getting this error with the 6.0.100-rc.1.21458.32 release.

Note: I have no IDE open, no VS Code or Visual Studio. I'm use only the console and it still gives the error above. Even after a fresh reboot and only the terminal open. So I think it it might be a problem on the dotnet-ef migrations bundle.

guillaume86 commented 2 years ago

Same issue on 6.0.100 with nothing running except the dotnet cli command (using the LockHunter trick I did manage to workaround it but it's not ideal).

julielerman commented 2 years ago

odd, I have been running bundle from CLI in the VS Code powershell terminal, the command terminal and the gitbash terminal (all in VS Code) without issues.

.NET 6.0.100 EF Core 6.0.0-* Pulling from standard nuget (e.g. no nuget.config) project.assests.Json confirms it's EF Core 6.0.0

My VSCode is 1.62.2 C# extension is v1.23.16

mcaden commented 2 years ago

I've been trying to narrow down if it's related to post-build/publish events or things like what is running in Program.cs or Startup.cs (web api project). So far nothing makes a difference. So far the only working around I've found is setting --configuration to something that is not debug or release. Heck, even asdf works.

MaxCrank commented 2 years ago

+1 that the bug exists and +1 that only the workaround seems to help. Closed IDEs, fresh restart - doesn't help.

julielerman commented 2 years ago

Any thoughts, @bricelam ??

anuraj commented 2 years ago

It is working property if we close VSCode and again running the command. And working properly in GitHub actions.

guillaume86 commented 2 years ago

+1 that the bug exists and +1 that only the workaround seems to help. Closed IDEs, fresh restart - doesn't help.

Yes fresh restart and not starting an IDE didn't help either here, trying to think about what's special in my setup...

DanoThom commented 2 years ago

I'm still having these issues too.

This is a big deal at this point as it's preventing me from taking any of this forward. No point if I can't get the migration bundles to reliably build on my own machine, let alone a build agent on Azure Devops.

vonzshik commented 2 years ago

While I hasn't been able to reproduce the problem via vs package manager (due to other issues with vs), I was able to reproduce it via dotnet ef migrations bundle.

The main problem is Microsoft.EntityFrameworkCore.Design.OperationExecutor, which is called from Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand. It loads the main assembly via Assembly.Load into dotnet process, so the main file gets locked on windows (most likely this doesn't happen on linux). Due to that, the child dotnet publish process fails, as the lock is taken by the parent process.

One way this could have been fixed is by using AssemblyLoadContext to load and unload the assemblies (after the executor is disposed) at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor, but since AssemblyLoadContext has been added with net core 3 (and ef tools is compiled against netcoreapp 2.0)...

roji commented 2 years ago

@bricelam maybe the modernization of the EF tools we mentioned at some point would allow us to use the "new" AssemblyLoadcontext to unload...

ivanmonteiro commented 2 years ago

... It loads the main assembly via Assembly.Load into dotnet process, so the main file gets locked on windows (most likely this doesn't happen on linux).

Well, to me at least using Github Actions (Windows) I have this problem, but using ubuntu-20-04 as the runner of the Github Action I see no errors and the migration bundle is correctly generated

matt-goldman commented 2 years ago

Same issue with 6.0.100 on Windows, not running VS or VS Code, no other terminal windows open. On macOS I don't get this problem, it works as expected.

ivanmonteiro commented 2 years ago

However, I noticed that if I run the same command with --configuration Bundle it did this:

This is the only workaround that worked for me on Windows (both on Windows 10 and Github Actions with Windows Server 2019 runner):

jobs:
  publish-bundle-windows:
    runs-on: windows-2019
   ...
    steps:
   ...
    - name: Create migrations bundle - windows
      run: dotnet ef migrations bundle --configuration Bundle --project ./src/Myproject/Myproject.csproj --verbose

On linux (ubuntu-20-04) and Docker (linux - alpine) I see no problems and the bundle is correctly generated:

jobs:
  publish-bundle-linux:
    runs-on: ubuntu-latest
   ...
    steps:
   ...
    - name: Create migrations bundle - linux
      run: dotnet ef migrations bundle --project ./src/Myproject/Myproject.csproj --verbose
jammyzt commented 2 years ago

I'm receiving the same issue on my Azure DevOps pipeline as well as locally.

Updating the command to: dotnet ef migrations bundle -p MyCoolProject.Infrastructure -s MyCoolProject.Api --verbose --configuration github.com.dotnet.efcore.issues.25555 --force

has done the trick nicely! : )

with "--configuration github.com.dotnet.efcore.issues.25555" being the workaround and "--force" being in case any local bundles have been created and need to be overwritten.

dennis-yemelyanov commented 2 years ago

Same here. Adding dummy --configuration worked like a charm. So glad I found this thread...

Since this issue seems to be affecting everyone (?), should it be mentioned as a known issue in the doc?

moalamri commented 2 years ago

Upgrading to 6.0.1 didn't solve the problem,

This is the only workaround (tested on win 10 & 11): dotnet ef migrations bundle --configuration Bundle --project ./src/Myproject/Myproject.csproj --verbose

Important: The above workaround doesn’t work when option —no-build is set

mbuonaccorsi commented 2 years ago

Upgrading to 6.0.1 didn't solve the problem,

This is the only workaround (Windows 11): dotnet ef migrations bundle --configuration Bundle --project ./src/Myproject/Myproject.csproj --verbose

How are people getting past this? I cannot get it to work by creating a dummy configuration name on the command line. When I do that I don't get any bundle at all because it can't find the build configuration with the name I made up.

EDIT: I realized that because I am using the --no-build option that this does not work with the workaround mentioned above. (I am using that option because I am testing this in a DevOps pipeline and didn't need it to re-build the project a second time)

So it should be noted that this workaround of making up a fake configuration does not work with the --no-build option

leodip commented 2 years ago

I'm having this problem with EF Core .NET CLI Tools 6.0.2, on Windows, no editor or IDE opened, just trying in Powershell.

Adding --configuration Bundle works. (but feels wrong)

moalamri commented 2 years ago

I'm having this problem with EF Core .NET CLI Tools 6.0.2, on Windows, no editor or IDE opened, just trying in Powershell.

Adding --configuration Bundle works. (but feels wrong)

It’s a workaround so ofcourse it would look ugly.

I thought they would address this in 6.0.2 but it seemed no. Perhaps 6.0.2 was just a security update where other fixes are pushed to the later update

JayVDZ commented 2 years ago

Also getting this :( Cannot create bundle.

axylophon commented 2 years ago

Same Problem

AivaloCap commented 2 years ago

Hi there, You can check a solution in this video using the PowerShell: https://www.youtube.com/watch?v=mBxSONeKbPk&t=3s You need to update the EF version in the PowerShell to at least version 6 using the command

dotnet tool update dotnet-ef

I hope that can help you.

mbuonaccorsi commented 2 years ago

Hi there, You can check a solution in this video using the PowerShell: https://www.youtube.com/watch?v=mBxSONeKbPk&t=3s You need to update the EF version in the PowerShell to at least version 6 using the command

dotnet tool update dotnet-ef

I hope that can help you.

That's the same solution shared above many times but does not always work. It did not for me and just created more errors because making up a fake "configuration" on the CLI can cause its own errors.

I ended up abandoning the bundle option because of this and just went with idempotent script generation, which is much simpler and produces a smaller script file than the large bundle EXE.

ivanmonteiro commented 2 years ago

I feel that this issue is a show-stopper and not given the proper attention. This makes developers unable to create the bundle, and many will give will up using it completely. Is there any deadline to fix this?

JayVDZ commented 2 years ago

I gave up, so for me, this is a dead feature. A shame.

ivanmonteiro commented 2 years ago

I gave up, so for me, this is a dead feature. A shame.

I manged to get it working after a couple of hours using the workaroud dotnet ef migrations bundle --configuration Bundle but it is not documented and it seems to not work for everybody.

My sistem configuration is: Windows 10, Dotnet sdk 6.0.2. and git bash as terminal.

BTW, have you tried using --configuration Bundle option?

mbuonaccorsi commented 2 years ago

BTW, have you tried using --configuration Bundle option?

Yes, that is what everyone suggests as a workaround... but it does not always work.

bricelam commented 2 years ago

not given the proper attention

This is going to require some architectural changes to the way our tools work to fix properly. We hope to address this in 7.0 as part of #26798

matewoj commented 2 years ago

BTW, have you tried using --configuration Bundle option?

Yes, that is what everyone suggests as a workaround... but it does not always work.

You can update dotnet tool and then try again with --configuration Bundle

to update dotnet tool dotnet tool update --global dotnet-ef

getputpost commented 2 years ago

I was able to use --configuration Bundle in JetBrains Rider terminal as a workaround.

It also worked on Azure Pipelines using power shell. I'm pasting YAML here for in hopes it can help others..

  - task: PowerShell@2
    displayName: 'Install Tools'
    inputs:
      targetType: 'inline'
      script: 'dotnet tool install --global dotnet-ef'
      workingDirectory: '$(System.DefaultWorkingDirectory)/PathToMyDataLayerProject'
      pwsh: true

  - task: PowerShell@2
    displayName: 'Bundle Migrations'
    inputs:
      targetType: 'inline'
      script: 'dotnet ef migrations bundle --configuration Bundle -c MyContext -s ../API -v'
      workingDirectory: '$(System.DefaultWorkingDirectory)/PathToMyDataLayerProject'
      pwsh: true
muiscatron commented 2 years ago

I have a problem running a generated bundle executable. I can't get it to accept a connection on the command line. It continues to insist on appsettings.json being present. The documentation(!) is unclear about how to specify a connection using an environment variable. If my env variable is called ABC Should it be:

--connection ${ABC}
--connection ABC

The command line help says --connection <CONNECTION> with no mention of environment variables. So should I be specifying the full connection string? No matter what I do, the exception I get is:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\temp\appsettings.json'.
ajcvickers commented 2 years ago

@muiscatron This message means that your "appsettings.json" file is needed to process the configuration in your application. (It's not actually a message from EF, but rather from the ASP.NET config code.) You can either change the configuration to not need appsettings (possibly only in a particular environment), or make sure that appsettings is available to the bundle.

muiscatron commented 2 years ago

@ajcvickers Thanks. I solved this by adding appsettings.json. What was confusing is that I had been supplying the connection string incorrectly on the command line, so the one in appsettings.json was being utilised. Now I fixed the command line, but the appsettings.json still seems to require at minimum a connection string with the required name. The content can be anything.

gnzgo commented 2 years ago

To anyone reading this: for us, the problem was Visual Studio. As soon as we ran the "dotnet ef bundle" command from a PowerShell or CLI, outside Visual Studio, and exited Visual Studio completely, the *.dll is being used by another process error was gone.

It's rather strange because Visual Studio was not in the middle of any process or compilation or anything, it was completely idle. But exiting Visual Studio fixed the issue, and we checked several times: having Visual Studio running was definitely the issue.

Aerodynamite commented 2 years ago

@gnzgo I just rebooted my (Windows 11) pc, only started Powershell, executed the dotnet ef migrations bundle -s "MyStartupProject" -p "MyDataProject" -c "MyContext" --verbose command, and it still failed due to "MyStartupProject.dll" being used by another process. No Visual Studio or Visual Studio Code running at all.

Adding the --configuration Bundle flag is the only thing that worked for me to get it to produce a bundle.

bricelam commented 2 years ago

@Aerodynamite There may be an issue with your csproj preventing a incremental builds. Do you use floating versions (stars) or ranges in your package references?