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

Self-contained single-file program, published with --no-build option, needs .NET to be installed #45230

Closed
andygjp opened this issue Dec 1, 2024 · 3 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@andygjp
Copy link

andygjp commented Dec 1, 2024

I've created a repo and a README.md detailing some investigation here: https://github.com/andygjp/MustInstalDotNetSelfContainedNoBuild

In short, I can build a self-contained project and then package it up, with the --no-build option, like so:

$configuration = "Release"
$runtime = "win-x64"
$framework = "net9.0"

# project built in a previous step
dotnet publish MyProject.csproj `
--configuration $configuration `
--runtime $runtime `
--framework $framework `
--no-restore `
--no-build

That works fine.

If I repeat that, but publish a single file, like so:

dotnet publish MyProject.csproj `
--configuration $configuration `
--runtime $runtime `
--framework $framework `
--no-restore `
--no-build `
--property:PublishSingleFile=$true `
--property:IncludeNativeLibrariesForSelfExtract=$true

It fails with: "You must install .NET to run this application."

If I repeat the last command, but remove the --no-build option, it works again.

Why must I have to build it again or remove --property:PublishSingleFile option to make it work?

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

bording commented Dec 3, 2024

Looks like #45159 is the fix for this.

@andygjp
Copy link
Author

andygjp commented Dec 3, 2024

@bording I think you're right.

I just added:

<Target Name="_WorkaroundIncorrectAppHost" BeforeTargets="_GetComHostPaths">
  <CallTarget Targets="_GetAppHostCreationConfiguration" />
</Target>

To the csproj in the repo, as suggested here: #45159 (comment), and the --no-build exe is the same size as the exe built without the --no-build option.

@marcpopMSFT
Copy link
Member

This should release in 9.0.103 in February as it missed the cutoff for Jan.

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