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.
DustinJoosen commented 2 years ago

@bricelam Should the floating versions be removed? because i tried it again, with the packages set to static versions, but it still only works with --configuration Bundle

Aerodynamite 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?

@bricelam No, I don't use any of those features.

pantonis commented 2 years ago

Im still getting this when I run dotnet ef migrations bundle --verbose --force .

pgouv commented 2 years ago

I am getting this on Windows Server 2019 but I have no issues on ubuntu.

ctolkien commented 2 years ago

Im still getting this when I run dotnet ef migrations bundle --verbose --force .

It's not slated for a fix until v7.

rroyter commented 2 years ago

Still getting this error on Win 11, EF 6.0.5. The --configuration Bundle workaround seemed to work one time but doesn't seem reliable from the comments in this thread.

goldytech commented 2 years ago

This issue is a deal-breaker for me to use the EfCore migrations bundle as part of the CI/CD feature. It must be addressed in upcoming versions.

tgourley commented 2 years ago

I'm late to this party but wanted to provide my experience. We are using bundles for pipeline builds (using Azure DevOps) and so far we are not having issues. BUT... locally when testing and debugging I ALWAYS get the "cannot access file..." error. If I immediately re-run the bundle it almost always works the second time. The only thing different from the local run and our pipeline is the use of "--verbose". I have another powershell script that uses the command without "--verbose" and it has always worked. Maybe the bug is somewhere around this option. Thanks!

yugabe commented 2 years ago

I'm not actually sure what's happening, but I can't get it to work either (.NET 7 Preview 7).

The process cannot access the file '\src\Server.Data\bin\Debug\net7.0\Server.Data.dll' because it is being used by another process. The file is locked by: ".NET Host (10548)

Sometimes it complains on the Server project, sometimes the Server.Data project.

There are about 8 ".NET Host" processes being spawned when running dotnet ef migrations bundle (VS is closed, everything is cleared, nothing is using the file, the path isn't too long etc.). I tried all the suggested workarounds here, none work. The bundling process creates the file that is being locked by itself.

I suspect it has something to do with how my database project is separate from my entry project, and the dependency is the other way around (obviously), but when the tool tries to publish the app, it tries to implicitly publish my entry project as well (I can see it's calling my publishing hooks for webpack builds from the web app). Obviously, if the data project tries to "publish" the web project, while the web project tries to compile the whole solution, it won't work. Also, it's not in any way straightforward of efficient, I don't want to recompile my whole solution once more (during CI builds especially), and it doesn't seem to care for the --no-build flag either.

I feel there is a different kind of issue here. Generating migrations should not depend on the whole infrastructure of the app, not even on a connection string, only on the provider.

yugabe commented 2 years ago

Managed to resolve.

The problem was related to my previous suspicion. Implementing an IDesignTimeDbContextFactory essentially severed the link between my full solution build and cyclic dependency, thus allowing me to build the project -- and the bundle -- correctly.

For reference:

using Microsoft.EntityFrameworkCore.Design;

namespace MyProject.Server.Data.Design;
internal class DesignTimeMyDbContextFactory : IDesignTimeDbContextFactory<MyDbContext>
{
    public MyDbContext CreateDbContext(string[] args) => new(new DbContextOptionsBuilder<MyDbContext>().UseSqlServer().Options);
}

There was no need to configure a connection string either, fortunately.

It's a bit weird that dotnet ef migrations script works correctly, but dotnet ef migrations bundle seems to break altogether.

npbenjohnson commented 2 years ago

Workaround for api startup project using tools 6.0.9: Pass --configuration Bundle and add this conditional to the api project so that it ignores appsettings publishing:

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

  <PropertyGroup>
    <NoDefaultLaunchSettingsFile Condition=" '$(Configuration)' == 'Bundle' ">true</NoDefaultLaunchSettingsFile>
  </PropertyGroup>
//...

IMPORTANT: This does not copy appsettings and the bundle.exe fails if the expected connection string is null or empty, even if it is ignored due to a --connection command line switch. So define appsettings.json alongside bundle.exe like:

{
  "ConnectionStrings": {
    "YourAppDbConnectionString": "Cannot be empty or null, but may be nonsense string if --connection command line option is used"
  }
}

Note: "Bundle" is not a magic configuration, it can be any name not actually in use, it just needs to be matched in the csproj Condition

filmico commented 1 year ago

I was able to overcome this issue by using the flag --configuration and stating the name of the appsetting.[EnvironMentName].json

In my case, I have an appsettings.Production.json file where I place my connection string for production

The Bundle command looks like:

dotnet ef migrations bundle --no-build --force --configuration Production

if for example you have the project split in tiers, you can point to the place where your migrations lives using the flag --project

dotnet ef migrations bundle --no-build --force --project ..\Data\ --configuration Production

For more flags, take a look at: dotnet ef migrations bundle -h

Side Note, always run this command at the solution tier were you have the appsetting

gzinger commented 1 year 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

Given severity of the issue (i.e. the feature does NOT work for most of the people) can it be addressed sooner (in v6.0.x)?

gzinger commented 1 year ago

Managed to resolve.

The problem was related to my previous suspicion. Implementing an IDesignTimeDbContextFactory essentially severed the link between my full solution build and cyclic dependency, thus allowing me to build the project -- and the bundle -- correctly.

For reference:

using Microsoft.EntityFrameworkCore.Design;

namespace MyProject.Server.Data.Design;
internal class DesignTimeMyDbContextFactory : IDesignTimeDbContextFactory<MyDbContext>
{
    public MyDbContext CreateDbContext(string[] args) => new(new DbContextOptionsBuilder<MyDbContext>().UseSqlServer().Options);
}

There was no need to configure a connection string either, fortunately.

It's a bit weird that dotnet ef migrations script works correctly, but dotnet ef migrations bundle seems to break altogether.

Dear yugabe, could you elaborate a bit? Are you saying that you were able to resolve the issue in this ticket by adding the above code? Where did you add it? How do you build a bundle afterwards? How do you run the resulting executable?

MoishyS commented 1 year ago

--configuration Bundle workaround does not work for me, i am using 7.0.9

Chadwuo commented 1 year ago

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

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 and when the dotnet process was showing this warning I unlocked the process and it finished creating the bundle.EFCoreMigrationWeb.dll

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.

阿甘,你TM真是个天才

alraseensaad commented 1 year ago

for me the errors appear when I add and configure Nerdbank.GitVersioning to the solution I remove the PackageReference of Nerdbank.GitVersioning in Directory.Build.props file and it's work fine

dmi-harlow commented 1 year ago

--configuration Bundle

I was having this issue for an Azure Pipelines build using a self-hosted agent. Adding '--configuration Bundle' made the problem go away.

rafalkwol commented 11 months ago

I have encountered this issue and described it in #1261. I was investigating it a bit and I think it can be pretty quickly fixed (if there is no time for a "real" fix) by allowing us to pass the new dotnet build & publish property "--disable-build-servers". It is not the perfect fix, but it would cause the build step to close all the dotnet.exe processes it's starting when building the projects before the publish step happens. It would be a way to make it work for those who don't mind invalidating the build cache.

ajcvickers commented 11 months ago

Note for triage: we should consider the --disable-build-servers approach.

plillevold commented 10 months 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

Given severity of the issue (i.e. the feature does NOT work for most of the people) can it be addressed sooner (in v6.0.x)?

This was saddening news. I came here experiencing this issue in our CI build in Azure DevOps Pipelines, using v6.0.25. No time soon are we able to upgrade to 7 in order to work around this issue.

Adding my vote for getting a fix backported to v6.0.x.

ctolkien commented 10 months ago

This was saddening news. I came here experiencing this issue in our CI build in Azure DevOps Pipelines, using v6.0.25. No time soon are we able to upgrade to 7 in order to work around this issue.

It's not fixed in 7 (or 8) anyway.

plillevold commented 10 months ago

This was saddening news. I came here experiencing this issue in our CI build in Azure DevOps Pipelines, using v6.0.25. No time soon are we able to upgrade to 7 in order to work around this issue.

It's not fixed in 7 (or 8) anyway.

Yeah, I tested with the 7.0 version of dotnet-ef tools and the issue persist. I presume the 7 and 8 versions are mere version bumps of the existing 6.0 tools.

That said, I did actually manage to get the 6.0.25 version to work in Azure DevOps Pipelines, which is great! I'm not 100% sure how, which is not so great :|

This is my build command, and the main difference is that I use an absolute path to the project file, while previously it was relative to the current working folder.

migrations bundle --output $(Build.ArtifactStagingDirectory)\Migrations\migrate-seed.exe --project $(Build.SourcesDirectory)\src\Data.Migrations --verbose --force

Note also that I did not use the "--configuration Bundle" trick, as this did not help for me at all.

jasekiw commented 8 months ago

@ajcvickers What is the status of this fix considering https://github.com/dotnet/efcore/pull/32737 has been merged? Has that been released to the public yet?

ajcvickers commented 8 months ago

@jasekiw I'd be extremely surprised, but very happy, if #32737 fully fixed this. It will be included in 9.0 preview 1, but you should be able to try it now with the daily builds.

ChrisPeacock1 commented 7 months ago

32737 Doesn't fix the issue for me. This is going to prevent us from upgrading our projects, which build fine in .Net 6, to .Net 8.

ErikEJ commented 7 months ago

@ChrisPeacock1 Are you using the daily tool build?

baronfel commented 7 months ago

Hey folks - we (SDK and Roslyn teams) very very very strongly recommend against using the --disable-build-servers argument. Any use of that flag will result in much longer (like 10x) build times due to Roslyn not being able to reuse its internal caches. Our teams have a kind of side-mission of finding and removing any usage of this flag because it's such an anti-pattern.

We'd love to work with the EF team to help diagnose why these errors are seen during the bundle generation, as well as work towards a solution that doesn't use --disable-build-servers. The first step in any resolution would be to gather binlogs for the publish that is happening under the covers. From there we can actually see what's going wrong in the build and fix the underlying issue that led to the addition of --disable-build-servers.

cc @jaredpar

ChrisPeacock1 commented 7 months ago

@ChrisPeacock1 Are you using the daily tool build?

Yes, I am.

pantonis commented 6 months ago

what is the workaround for this until it is fixed in the very far feature?

jasekiw commented 5 months ago

@pantonis

We followed the workaround here by adding <NoDefaultLaunchSettingsFile Condition=" '$(Configuration)' == 'Bundle' ">true</NoDefaultLaunchSettingsFile> to the migrations .csproj file and used --configuration Bundle when running the bundle command.

dotnet ef migrations bundle --configuration Bundle