dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.39k stars 10k forks source link

Blazor publish cannot access file because it's being compressed multiple times #38429

Closed GeertvanHorrik closed 2 years ago

GeertvanHorrik commented 2 years ago

Describe the bug

A project pack fails because the same file is being compressed twice.

Here are the logs that show the output:

[01]  Compressing 'C:\MyProject\output\net6.0\MyProject.Shared.dll' because compressed file 'obj\Release\net6.0\build-gz\isV2tDho.gz' does not exist.
[02]  Skipping 'C:\Users\username\.nuget\packages\microsoft.netcore.app.runtime.mono.browser-wasm\6.0.0\runtimes\browser-wasm\lib\net6.0\System.Xml.ReaderWriter.dll' because 'obj\Release\net6.0\build-gz\NOUkSdFO.gz' is newer than 'C:\Users\username\.nuget\packages\microsoft.netcore.app.runtime.mono.browser-wasm\6.0.0\runtimes\browser-wasm\lib\net6.0\System.Xml.ReaderWriter.dll'.
[03]  Skipping 'C:\Users\username\.nuget\packages\microsoft.codeanalysis.scripting.common\4.0.0\lib\netcoreapp3.1\ru\Microsoft.CodeAnalysis.Scripting.resources.dll' because 'obj\Release\net6.0\build-gz\e9meF4Mt.gz' is newer than 'C:\Users\username\.nuget\packages\microsoft.codeanalysis.scripting.common\4.0.0\lib\netcoreapp3.1\ru\Microsoft.CodeAnalysis.Scripting.resources.dll'.
[04]  Skipping 'C:\Users\username\.nuget\packages\microsoft.netcore.app.runtime.mono.browser-wasm\6.0.0\runtimes\browser-wasm\lib\net6.0\System.Private.Xml.dll' because 'obj\Release\net6.0\build-gz\aT7quPI1.gz' is newer than 'C:\Users\username\.nuget\packages\microsoft.netcore.app.runtime.mono.browser-wasm\6.0.0\runtimes\browser-wasm\lib\net6.0\System.Private.Xml.dll'.
[05]  Compressing 'C:\MyProject\output\net6.0\MyProject.Shared.dll' because compressed file 'obj\Release\net6.0\build-gz\isV2tDho.gz' does not exist.
[06]  Skipping 'C:\Users\username\.nuget\packages\serilog\2.10.0\lib\netstandard2.1\Serilog.dll' because 'obj\Release\net6.0\build-gz\0l2FEPm7.gz' is newer than 'C:\Users\username\.nuget\packages\serilog\2.10.0\lib\netstandard2.1\Serilog.dll'.
[07]  Skipping 'C:\Users\username\.nuget\packages\microsoft.codeanalysis.scripting.common\4.0.0\lib\netcoreapp3.1\tr\Microsoft.CodeAnalysis.Scripting.resources.dll' because 'obj\Release\net6.0\build-gz\Dj1datXZ.gz' is newer than 'C:\Users\username\.nuget\packages\microsoft.codeanalysis.scripting.common\4.0.0\lib\netcoreapp3.1\tr\Microsoft.CodeAnalysis.Scripting.resources.dll'.
[08]  Skipping 'C:\Users\username\.nuget\packages\serilog.formatting.compact.reader\1.0.5\lib\netstandard2.1\Serilog.Formatting.Compact.Reader.dll' because 'obj\Release\net6.0\build-gz\eb6Qll++.gz' is newer than 'C:\Users\username\.nuget\packages\serilog.formatting.compact.reader\1.0.5\lib\netstandard2.1\Serilog.Formatting.Compact.Reader.dll'.
[09]  Skipping 'C:\Users\username\.nuget\packages\microsoft.codeanalysis.scripting.common\4.0.0\lib\netcoreapp3.1\zh-Hans\Microsoft.CodeAnalysis.Scripting.resources.dll' because 'obj\Release\net6.0\build-gz\Yx2XHcXn.gz' is newer than 'C:\Users\username\.nuget\packages\microsoft.codeanalysis.scripting.common\4.0.0\lib\netcoreapp3.1\zh-Hans\Microsoft.CodeAnalysis.Scripting.resources.dll'.
[10] 27:6>C:\Program Files (x86)\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(238,5): error : The process cannot access the file 'C:\MyProject\obj\Release\net6.0\build-gz\isV2tDho.gz' because it is being used by another process. [C:\MyProject\MyProject.UI.csproj]

For simplification, I've added line numbers. As you can see, the same file (MyProject.Shared.dll) is being compressed twice (line 01 and 05), which could be the reason the error occurs (line 10).

To Reproduce

Still figuring it out, but I think:

MyProject.Shared MyProject.Client (references MyProject.Shared) MyProject.UI (Blazor project, references both MyProject.Client and MyProject.Shared)

Update 01:

Sorry I confused anyway, it's not "pack", it's "publish".

Here is the full command line:

"C:\Program Files\dotnet\sdk\6.0.100\dotnet.dll" publish .\src\MyProject.Server\MyProject.Server.csproj --output C:/Source/MyProject/output/Release/MyProject.Server/output/output --configuration Release /property:ContinuousIntegrationBuild=true /property:ResolveNuGetPackages=false /property:OverridableOutputRootPath=C:\Source\MyProject\output\Release /property:OverridableOutputPath=C:\Source\MyProject\output\Release\MyProject.Server\output\output /property:PackageOutputPath=C:\Source\MyProject\output\Release\MyProject.Server\output\output /property:ConfigurationName=Release /property:PackageVersion=1.0.0-alpha3263 /property:RunCodeAnalysis=false /maxcpucount /fileLogger /fileloggerparameters:LogFile=C:/Source/MyProject/output/Release/MsBuild_MyProject.Server_pack_log.log /binarylogger:C:\Source\MyProject\output\Release\MsBuild_MyProject.Server_pack.binlog;ProjectImports=Embed /nologo"

Project structure:

MyProject.Server => references both MyProject.Shared and MyProject.UI, the project being packed MyProject.UI (Blazor webassembly) => references MyProject.Shared

Further technical details

dotnet --info Output ``` .NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x86 Base Path: C:\Program Files (x86)\dotnet\sdk\6.0.100\ Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa .NET SDKs installed: 2.1.526 [C:\Program Files (x86)\dotnet\sdk] 2.2.104 [C:\Program Files (x86)\dotnet\sdk] 3.0.101 [C:\Program Files (x86)\dotnet\sdk] 5.0.403 [C:\Program Files (x86)\dotnet\sdk] 6.0.100 [C:\Program Files (x86)\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.2 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.2 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.1 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.12 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.21 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.2 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.1 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.12 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.0.1 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App] ```
javiercn commented 2 years ago

@GeertvanHorrik thanks for contacting us.

Are you trying to pack a Blazor webassembly app?

ghost commented 2 years ago

Hi @GeertvanHorrik. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

GeertvanHorrik commented 2 years ago

@GeertvanHorrik thanks for contacting us.

Are you trying to pack a Blazor webassembly app?

Correct.

It's a server project with a reference to a Blazor we assembly app being packed into a docker image.

So running pack on the server which references we assembly app project.

javiercn commented 2 years ago

Blazor Webassembly apps are not packable.

GeertvanHorrik commented 2 years ago

Blazor Webassembly apps are not packable.

It used to work fine in in net 5.0? So I am packing the server project, can give you the exact command line of you would like to see it.

mkArtakMSFT commented 2 years ago

@GeertvanHorrik what is your motivation for trying to use dotnet pack? What are you trying to achieve here?

ghost commented 2 years ago

Hi @GeertvanHorrik. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

GeertvanHorrik commented 2 years ago

Sorry I confused anyone, it's not "pack", it's "publish".

Here is the full command line:

"C:\Program Files\dotnet\sdk\6.0.100\dotnet.dll" publish .\src\MyProject.Server\MyProject.Server.csproj --output C:/Source/MyProject/output/Release/MyProject.Server/output/output --configuration Release /property:ContinuousIntegrationBuild=true /property:ResolveNuGetPackages=false /property:OverridableOutputRootPath=C:\Source\MyProject\output\Release /property:OverridableOutputPath=C:\Source\MyProject\output\Release\MyProject.Server\output\output /property:PackageOutputPath=C:\Source\MyProject\output\Release\MyProject.Server\output\output /property:ConfigurationName=Release /property:PackageVersion=1.0.0-alpha3263 /property:RunCodeAnalysis=false /maxcpucount /fileLogger /fileloggerparameters:LogFile=C:/Source/MyProject/output/Release/MsBuild_MyProject.Server_pack_log.log /binarylogger:C:\Source\MyProject\output\Release\MsBuild_MyProject.Server_pack.binlog;ProjectImports=Embed /nologo"

Project structure:

MyProject.Server => references both MyProject.Shared and MyProject.UI MyProject.UI (Blazor webassembly) => references MyProject.Shared

GeertvanHorrik commented 2 years ago

I think the issue is caused by this:

https://github.com/dotnet/sdk/blob/843f0f90c815722f53c5857919469e859b7f625a/src/BlazorWasmSdk/Tasks/GZipCompress.cs#L28

I think it should either:

  1. Call Distinct on the files (preferred)
  2. Not process parallel (not preferred)
GeertvanHorrik commented 2 years ago

@javiercn do you think my analyses is correct or is this a different issue?

javiercn commented 2 years ago

@GeertvanHorrik I believe the issue is in a different place, there should not be duplicates when you get to that point.

Based on the fact that you are mentioning publish, I suspect that the issue is a bit before we call that task. Do you have a .config file or similar in any of your assemblies?

We recently fixed an issue where some items on the build were being incorrectly duplicated, and that might be causing this issue.

GeertvanHorrik commented 2 years ago

If you mean MyProject.Shared.dll.config, then yes, but it seems to be getting generated by the build, it's not inside any source directory.

Is there a way I can test the potential fix you mentioned?

GeertvanHorrik commented 2 years ago

@javiercn Any updates on this? Is there a way I can either provide more information or test a potential fix?

GeertvanHorrik commented 2 years ago

Feels similar to https://github.com/dotnet/aspnetcore/issues/37610

GeertvanHorrik commented 2 years ago

Tried 6.0.200-preview.21579.1, but does not seem to work yet.

GeertvanHorrik commented 2 years ago

Looks like the issue has been solved with the latest SDK. Thanks!