PublishSingleExe MSB4018 GenerateBundle Error
I'm having an issue trying to publish as a single binary using .NET5. This used to work via Fody/Costura (old .NET 4.x framework) but I'm trying to migrate to the built-in PublishSingleFile option.
Error text from running this command are as follows:
Run:
"%ProgramFiles%\dotnet\dotnet.exe" publish <...>.csproj --configuration Release --runtime win7-x86 --framework net5.0-windows -p:Platform=x86 -p:PublishProfile="SingleExe" /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true --verbosity d
Output:
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [C:\work\<proj>.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: System.ArgumentException: Invalid input specification: Found multiple entries with the same BundleRelativePath [C:\work\<proj>.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [C:\work\<proj>.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() [C:\work\<proj>.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() [C:\work\<proj>.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\work\<proj>.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\work\<proj>.csproj]
Done executing task "GenerateBundle" -- FAILED.
1>Done building target "GenerateSingleFileBundle" in project "<proj>.csproj" -- FAILED.
1>Done Building Project "C:\work\<proj>.csproj" (Publish target(s)) -- FAILED.Build FAILED.
Note that the publish works fine when PublishSingleFile is omitted (false).
I suspect that my issue shares a root cause with https://github.com/dotnet/sdk/issues/3465 and https://github.com/dotnet/runtime/issues/3735 . From the text, it seems likely that one of my nuget deps is having a naming collision. It also seems like adding a <ExcludeAssets>all</ExcludeAssets>
tag into the offending nuget would solve my issue. The problem I have is that I have many many nuget deps, making it really tricky to find the colliding binary (I am not using NLog, which is the common failure point from those issues). Is there a way to output diagnostic detail on what is colliding, and if not, can you please add one? This seems to have been an issue since 3.1, with no apparent resolution for 5.0, making it somewhat brittle as a feature.
Thanks! In the meantime, I think I'll try adding <ExcludeAssets>true
to all of my nuget deps, see if I can at least get it to publish (even if runtime fails ..)