dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.63k stars 408 forks source link

Dotnet publish broken in preview 5 #3766

Closed ElanHasson closed 4 days ago

ElanHasson commented 4 months ago

I noticed my CI stopped building images after I upgraded to preview 5.

See https://asciinema.org/a/XBd5yCk1SHPISVNrJKgb3Bfgb

Repro steps:

  1. dotnet new aspire
  2. dotnet publish mynewaspire.csproj
  3. Try to find the output of the publish operation 🕵🏼‍♂️
davidfowl commented 4 months ago

Publishing the apphost project doesn’t work and has never worked AFAIK.

ElanHasson commented 4 months ago

Perhaps a poor example, I can't get an "aspire" web API project to publish either.

I'll put together more repro steps shortly.

ElanHasson commented 4 months ago

@davidfowl i can't repro with a dotnet new aspire-starter when i try to publish the API project that is in the template.

However, myself and another eng on the team can't publish, neither can our GHA which works on main (preview4), but in our preview5 upgrade branch, fails to publish any output.

It's a private repo, so i can't link here, but I will try to clone + remove all non-relevant stuff to get a repro sample i can share.

I am also happy to zip up and share with you privately.

edit: We're both in the Orleans discord, can send via there.

davidfowl commented 4 months ago

I guess I still don't understand what worked before and what doesn't work now. A minimal repro showing the problem would be great.

ElanHasson commented 4 months ago

I'll get on that minimal.

Let me try to explain a bit better.

I used to be able to do:

dotnet restore System.sln
dotnet build System.sln --no-resource -c Release
dotnet publish "src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj" -c Release --no-build --no-restore -o /app/publish

Which would, as expected output the publish output to /app/publish.

Now, dotnet publish does not output anything at all, nor does it result in any error output or a non-zero exit code.

I also can't get right click =>publish to output anything for the same project.

I'll update here with the repro app.

ElanHasson commented 4 months ago

@davidfowl here you go.

repro.zip

There are really two issues, after preview 5 update, not clear if they are related or not.

A sudden requirement to transform the web.config on publish. If i suppress this via IsWebConfigTransformDisabled, when suppressed now leads to the second, where no published output is written and no errors occur.

/usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: The "TransformWebConfig" task failed unexpectedly. [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]

#15 [publish 1/1] RUN dotnet publish "src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj" -c Release --no-build --no-restore -o /app/publish
#15 0.244 MSBuild version 17.9.8+b34f75857 for .NET
#15 0.802 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: The "TransformWebConfig" task failed unexpectedly. [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path '/app/publish/web.config'. [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError) [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException) [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException) [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode) [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute() [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 0.803 /usr/share/dotnet/sdk/8.0.204/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj]
#15 ERROR: process "/bin/sh -c dotnet publish \"src/InfinityFlow.Hosting.WebAPI/InfinityFlow.Hosting.WebAPI.csproj\" -c Release --no-build --no-restore -o /app/publish" did not complete successfully: exit code: 1

These are from my local windows env, where same happens from CLI w/o docker.

> dotnet --list-sdks
8.0.204 [C:\Program Files\dotnet\sdk]
8.0.300-preview.24203.14 [C:\Program Files\dotnet\sdk]

> dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

>dotnet workload list

Installed Workload Id      Manifest Version                      Installation Source
--------------------------------------------------------------------------------------------------------------------------------
android                    34.0.95/8.0.100                       SDK 8.0.300-preview.24203, VS 17.9.34728.123, VS 17.10.34804.81
aspire                     8.0.0-preview.5.24201.12/8.0.100      SDK 8.0.300-preview.24203, VS 17.10.34804.81
ios                        17.2.8053/8.0.100                     SDK 8.0.300-preview.24203, VS 17.9.34728.123, VS 17.10.34804.81
maccatalyst                17.2.8053/8.0.100                     SDK 8.0.300-preview.24203, VS 17.9.34728.123, VS 17.10.34804.81
maui-windows               8.0.7/8.0.100                         SDK 8.0.300-preview.24203, VS 17.9.34728.123, VS 17.10.34804.81
wasm-tools-net7            8.0.4/8.0.100                         SDK 8.0.300-preview.24203, VS 17.10.34804.81

Use `dotnet workload search` to find additional workloads to install.
davidfowl commented 4 months ago

Doesn't look related to aspire. Looks like a .NET SDK issue.

ElanHasson commented 4 months ago

Thanks @davidfowl.

I dug a bit deeper. I'm attaching some binlogs. publish-with-webconfigtransform-error.zip

I tried producing a binlog when IsWebConfigTransformDisabled is set to true to bypass the webconfig transform error, and it seems msbuild isn't even called as no binlog is produced.

image

Running dotnet with -d didn't seem to do much.

image

I figured out what is "causing it": Add a reference to a package I make: InfinityFlow.Aspire.Temporal. I guess I missed the memo where I should produce a NuGet for Aspire model configuration in AppHost and a NuGet package for consumption from App Projects.

Also reproducible when you reference Aspire.Hosting.AppHost.

For my InfinityFlow.Aspire.Temporal i think it's because of the transitive dependency on Aspire.Hosting.AppHost.

:)

timheuer commented 4 months ago

@ElanHasson why are you referencing Aspire.Hosting in the API project?

ElanHasson commented 4 months ago

@ElanHasson why are you referencing Aspire.Hosting in the API project?

Heh, I'm not-- it came in via a package I make indirectly.

A better experience might be to detect that it's referenced in a non app host project and display an error vs the current behavior of a Web.config transform error + fail silently.

I admit, it's my fault for probably missing it in the docs.

timheuer commented 4 months ago

Ok, looking at the repo I see a direct pacakge ref not a transitive one...but might result in the same thing. It's definitely odd either would affect publish of the project. I see the error and was looking at the binlog, but after opening your solution in VS, I then could no longer repro the error?!?!

timheuer commented 4 months ago

But it's definitely InfinityFlow.Aspire.Temporal causing the issue.

ElanHasson commented 4 months ago

@timheuer yeah thanks for taking a look. I tried many, many things so it might have actually snuck in there the direct reference.

Tried everything the last thing I did was 1x1 remove every package and try.

timheuer commented 4 months ago

Okay to close this one @ElanHasson ?

ElanHasson commented 4 months ago

Go ahead @timheuer

Should the output of this report be to add a publish time error or warning when Aspire.Hosting is referenced in a non-apphost project and is attempted to be published?

Not sure if that is something to do with the sdk preview or if aspire's msbuild stuff is interfering (for example, the web.config transform stuff).

I'll defer to you on that stuff-- but yes you may close this one.

timheuer commented 4 months ago

I might take another stab at trying to repro this with a simpler solution, but couldn't detect easily what the specific issue was.

ElanHasson commented 4 months ago

Yeah i just don't want anyone else to lose time to something like this.

Thanks

timheuer commented 4 months ago

I tried to recreate the scenario (apphost referencing a library that has a reference to Aspire.Hosting.AppHost) and cannot trigger that error. I do want to know if there is an issue here with targets as triggering that web.config one is absolutely odd here. But I can't get a smaller repro...

ElanHasson commented 4 months ago

hm. Did you try with the package i used? btw it's oss, https://github.com/InfinityFlowApp/aspire-temporal/

so maybe i'm doing something wrong in that package which is "spilling over" into the repro?

were you able to repro with what i sent though? It's not environmental, as in limited to just me, right?

timheuer commented 4 months ago

I tried with a starter app and adding your package to the web api project...but i also can repro with your zip file. I'm a bit confused on what the specific trigger is but the simple recursion of references doesn't seem to be it.

rsalus commented 1 month ago

I ran into this trying to publish my web API.. I also tried to suppress the transform by adding <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled> to my csproj, but like @ElanHasson found this breaks the publish step. Turns out I had the Aspire.Hosting and Aspire.Hosting.AppHost packages referenced in that csproj, and removing them solved the issue.

davidfowl commented 5 days ago

Is this still an issue? Are we tracking anything here to be fixed?

ElanHasson commented 5 days ago

Don't think so. Go ahead and close @davidfowl, I'm not expecting anything from here as the answer is in the comments.