C
C#2w ago
peppy

Self-contained, trimmed .NET 9 executable "can't find framework" when run

I'm attempting to publish a project with two NuGet dependencies (one with native libraries) as a single-file, trimmed executable.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
I am using the following profile with the command-line dotnet.exe publish $FOLDER_CONTAINING_PROJECT --no-build -c "Release" /p:PublishProfileFullPath=PATH_TO_PROFILE --self-contained:
<PropertyGroup>
<PublishDir>SOME_DIR</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
<PropertyGroup>
<PublishDir>SOME_DIR</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
but running the finished artifact produces:
PS D:\fh\artifacts\localdeploy\rel\bin> .\fhmodmgr.exe
You must install or update .NET to run this application.

App: D:\fh\artifacts\localdeploy\rel\bin\fhmodmgr.exe
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '9.0.0' (x64)
.NET location: D:\fh\artifacts\localdeploy\rel\bin\

No frameworks were found.

PS D:\fh\artifacts\localdeploy\rel\bin> dotnet --list-runtimes
Microsoft.AspNetCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
PS D:\fh\artifacts\localdeploy\rel\bin> .\fhmodmgr.exe
You must install or update .NET to run this application.

App: D:\fh\artifacts\localdeploy\rel\bin\fhmodmgr.exe
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '9.0.0' (x64)
.NET location: D:\fh\artifacts\localdeploy\rel\bin\

No frameworks were found.

PS D:\fh\artifacts\localdeploy\rel\bin> dotnet --list-runtimes
Microsoft.AspNetCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To clarify: 1) Aren't self-contained executables supposed to not require .NET to be installed in the first place? 2) Given Microsoft.NETCore.App >= 9.0.0 x64 evidently is installed, how can it not be found? 3) Is there something incorrect with either the project or publish settings that would prohibit this from working?
1 Reply
peppy
peppyOP2w ago
sfextract over the resulting image does show some runtime assemblies in:
PS D:\fh\artifacts\localdeploy\rel\bin> sfextract.exe .\fhmodmgr.exe
Bundle version: 6.0
Contains 22 files:
- fhmodmgr.runtimeconfig.json (1 KB, 1610 bytes)
- Hexa.NET.ImGui.dll (190 KB, 194560 bytes)
- Hexa.NET.ImGui.Backends.dll (14 KB, 14848 bytes)
- HexaGen.Runtime.dll (12 KB, 12800 bytes)
- TerraFX.Interop.Windows.dll (38 KB, 39424 bytes)
- fhmodmgr.dll (224 KB, 229888 bytes)
- Microsoft.Win32.Registry.dll (19 KB, 19456 bytes)
- System.Collections.Concurrent.dll (27 KB, 27648 bytes)
- System.Collections.Immutable.dll (21 KB, 21504 bytes)
- System.Collections.NonGeneric.dll (8 KB, 8192 bytes)
- System.ComponentModel.Primitives.dll (11 KB, 11264 bytes)
- System.ComponentModel.TypeConverter.dll (13 KB, 13824 bytes)
- System.Diagnostics.DiagnosticSource.dll (92 KB, 94720 bytes)
- System.Diagnostics.Process.dll (51 KB, 52736 bytes)
- System.Diagnostics.StackTrace.dll (9 KB, 9216 bytes)
- System.IO.Compression.dll (32 KB, 32768 bytes)
- System.IO.MemoryMappedFiles.dll (25 KB, 25600 bytes)
- System.ObjectModel.dll (8 KB, 8192 bytes)
- System.Private.CoreLib.dll (2 MB, 2436096 bytes)
- System.Reflection.Metadata.dll (108 KB, 110592 bytes)
- System.dll (5 KB, 5120 bytes)
- fhmodmgr.deps.json (6 KB, 6396 bytes)
PS D:\fh\artifacts\localdeploy\rel\bin> sfextract.exe .\fhmodmgr.exe
Bundle version: 6.0
Contains 22 files:
- fhmodmgr.runtimeconfig.json (1 KB, 1610 bytes)
- Hexa.NET.ImGui.dll (190 KB, 194560 bytes)
- Hexa.NET.ImGui.Backends.dll (14 KB, 14848 bytes)
- HexaGen.Runtime.dll (12 KB, 12800 bytes)
- TerraFX.Interop.Windows.dll (38 KB, 39424 bytes)
- fhmodmgr.dll (224 KB, 229888 bytes)
- Microsoft.Win32.Registry.dll (19 KB, 19456 bytes)
- System.Collections.Concurrent.dll (27 KB, 27648 bytes)
- System.Collections.Immutable.dll (21 KB, 21504 bytes)
- System.Collections.NonGeneric.dll (8 KB, 8192 bytes)
- System.ComponentModel.Primitives.dll (11 KB, 11264 bytes)
- System.ComponentModel.TypeConverter.dll (13 KB, 13824 bytes)
- System.Diagnostics.DiagnosticSource.dll (92 KB, 94720 bytes)
- System.Diagnostics.Process.dll (51 KB, 52736 bytes)
- System.Diagnostics.StackTrace.dll (9 KB, 9216 bytes)
- System.IO.Compression.dll (32 KB, 32768 bytes)
- System.IO.MemoryMappedFiles.dll (25 KB, 25600 bytes)
- System.ObjectModel.dll (8 KB, 8192 bytes)
- System.Private.CoreLib.dll (2 MB, 2436096 bytes)
- System.Reflection.Metadata.dll (108 KB, 110592 bytes)
- System.dll (5 KB, 5120 bytes)
- fhmodmgr.deps.json (6 KB, 6396 bytes)
Not using a publish profile (moving any needed directives into the project file) doesn't seem to change a thing. This is the output running with COREHOST_TRACE on. https://gist.github.com/fkelava/b28ca32ffadd1779a1af81d2360fd78d Why exactly does it think the .NET location is the folder I'm running it in? How does that work?

Did you find this page helpful?