I have a simple console app which has a dependency on Libgit2Sharp, which contains native binaries. When published as a single EXE, it fails to run.
git clone https://github.com/ztl8702/dotnet-core-single-exe-repro.git
cd dotnet-core-single-exe-repro/ConsoleAppUsingLibgit
dotnet publish -r win-x86 -c Release -o $env:HOME\bin-x86\ ConsoleAppUsingLibgit.csproj /p:PublishSingleFile=true /p:PublishTrimmed=true;
$env:HOME\bin-x86\ConsoleAppUsingLibgit.exe
Console app runs, and should output something like:
Hello World! This app uses LibGit2Sharp
Latest commit: add tests to CI config
Fails to run, with error:
Error:
An assembly specified in the application dependencies manifest (ConsoleAppUsingLibgit.deps.json) was not found:
package: 'LibGit2Sharp.NativeBinaries', version: '2.0.289'
path: 'runtimes/win-x64/native/git2-7ce88e6.pdb'
I have set up CI on Github Actions to reproduce this.
See https://github.com/ztl8702/dotnet-core-single-exe-repro/runs/259587098 (and expand the logs for the "Test ..." steps)
Publishing without using single exe works fine.
.NET Core SDK: 3.0.100
Operating system (reproducible when running the single exe on):
Ok. So I tried creating another sample app that uses Grpc.Core (the C version); and it works fine.
https://github.com/ztl8702/dotnet-core-single-exe-repro/runs/260574843
So this might be an issue specific to Libgit2Sharp....
Still, I would appreciate any ideas on how to debug.
So it appears that the libgit2sharp.nativebinaries NuGet package contains .pdb files for the native dlls (e.g. git2-7ce88e6.pdb). dotnet publish copies it to output, but single exe strips it. However ConsoleAppUsingLibgit.deps.json still contains a reference to that pdb file.
The bundle task has an IncludeSymbols switch that it looks like you should be able to set via /p:IncludeSymbolsInSingleFile=true. I think your scenario is a little unusual because you have a NuGet package with a PDB in it, not sure whether the bundler is expecting that.
@swaroop-sridhar
Setting /p:IncludeSymbolsInSingleFile=true works!
So the logic here:
https://github.com/dotnet/core-setup/blob/119d6f9ad450a81c0b93491adebc8090ee10858a/src/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs#L95-L98
Should be changed to something like: if EmbedPDBs || if the pdb is referenced in deps.json?
That sounds reasonable to me, I'm not familiar with this code though. (That ToLower rather than ToLowerInvariant is also interesting there.)
This issue is a dup of https://github.com/dotnet/sdk/issues/3685
Please see the discussion in https://github.com/dotnet/sdk/issues/3685 for more details.
@dagood, I'll fix the ToLower() issue. Thanks for pointing it out.
The bundle task has an
IncludeSymbolsswitch that it looks like you should be able to set via/p:IncludeSymbolsInSingleFile=true. I think your scenario is a little unusual because you have a NuGet package with a PDB in it, not sure whether the bundler is expecting that.@swaroop-sridhar
This does not work when the project containing the nuget with native pdb files (ex Microsoft.ML.onnxruntime) is a .net core 3 project, and referenced in a Windows Application Packaging Project (to pack as UWP)... Then it seams impossible to either discard the pbd files, or to include them in the single file (which the packaging project is totally responsible for)...
I finally managed to find a workaround with a postbuildscript, see here: https://github.com/klalle/Microsoft.ML.onnxruntime_UWP_fix
Any other solutions is apreciated!
Most helpful comment
This issue is a dup of https://github.com/dotnet/sdk/issues/3685
Please see the discussion in https://github.com/dotnet/sdk/issues/3685 for more details.
@dagood, I'll fix the
ToLower()issue. Thanks for pointing it out.