Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publishsinglefile causes runtime failure of hostpolicy.dll not found for dotnet 9.0.100 #44992

Open
jsahaj opened this issue Nov 20, 2024 · 2 comments
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@jsahaj
Copy link

jsahaj commented Nov 20, 2024

HelloWorldExample1.zip
When doing publishsinglefile=true and running resulting exe we get a runtime failure of hostpolicy.dll not found for dotnet 9.0.100. This is a regression from net8, where it builds and runs fine.

With C# project file is defined as:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <PlatformTarget>x64</PlatformTarget> <PublishSingleFile>true</PublishSingleFile> <SelfContained>true</SelfContained> <PublishTrimmed>true</PublishTrimmed> <RuntimeIdentifier>win-x64</RuntimeIdentifier> </PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet publish --configuration $(Configuration) --runtime win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=true --no-build --output=$(EXEOUT) HelloWorldExample1.csproj" />
</Target>
</Project>

Set EXEOUT to some directory and build the project. Go to exeout directory at command prompt and run the executable and to get error:

c:\Temp\exeout>HelloWorldExample1.exe
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
Failed to run as a self-contained app.

  • The application was run as a self-contained app because 'c:\Temp\exeout\HelloWorldExample1.runtimeconfig.json' was not found.
  • If this should be a framework-dependent app, add the 'c:\Temp\exeout\HelloWorldExample1.runtimeconfig.json' file and specify the appropriate framework.

Removing the publishsinglefile allows program to run without error.

Versions:
dotnet 9.0.100
VS 17.12.1
csc 4.12.0-3.24558.5

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Nov 20, 2024
@bording
Copy link

bording commented Nov 22, 2024

I was just about to file an issue for this problem but saw that it was reported already.

The thing I'll add is that it seems to be related to the use of --no-build with the publish command.

If you let dotnet publish also build then it seems to work properly.

@Hoaas
Copy link

Hoaas commented Nov 25, 2024

Also experienced this with a buid pipeline like this:
dotnet restore --runtime win-x64
dotnet build --configuration release --runtime win-x64 --self-contained -p:PublishSingleFile True --no-restore
dotnet publish --configuration release --runtime win-x64 --self-contained --no-build

Worked when removing --no-build on publish, but would rather now have to do that :/

Only had the issues on programs running as windows services. APIs hosted in IIS work fine either way (though singlefile was not enabled for APIs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants