Open bricelam opened 3 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 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.
Im still getting this when I run dotnet ef migrations bundle --verbose --force
.
I am getting this on Windows Server 2019 but I have no issues on ubuntu.
Im still getting this when I run
dotnet ef migrations bundle --verbose --force
.
It's not slated for a fix until v7.
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.
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.
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!
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.
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.
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
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
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)?
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, butdotnet 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?
--configuration Bundle
workaround does not work for me, i am using 7.0.9
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真是个天才
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
--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.
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.
Note for triage: we should consider the --disable-build-servers
approach.
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.
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.
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.
@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?
@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 Are you using the daily tool build?
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 Are you using the daily tool build?
Yes, I am.
what is the workaround for this until it is fixed in the very far feature?
@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
The workaround in the above didn't work for me, but what does work is removing the runtime (e.g. win-x64
) option from the bundle command, and also from any project files, along with the self-contained option. I.e. remove these:
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
The bundle does some extra file copying at the end where a Windows runtime is specified, and it's during this that the locked file cannot be moved.
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 anddotnet ef migrations bundle
.