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

Fix computation of app path when published as a "single file" #298

Merged
merged 1 commit into from
Feb 26, 2021

Conversation

mjcheetham
Copy link
Collaborator

@mjcheetham mjcheetham commented Feb 25, 2021

When publishing GCM as a 'single file' application, the computed path to the entry executable is no longer correct.

On .NET Core 3.1, using Assembly.Location resolves to the temporary extracted DLL file path. On .NET 5 Assembly.Location always returns the empty string.

Since .NET 5, published single-file apps no longer use the self-extraction model, and are real single file with all assemblies and native libraries statically linked/bundled.

We now use the Environment.GetCommandLineArgs() method to get the raw underlying "argv" arguments, which argv[0] is the absolute file path to the entry executable.

We also change how we get the application version number to look for the assembly attribute, rather than extract if from the file on disk.

At app startup, also change the way we trace system information to be more readable.

Fixes #229
Fixes #252

@mjcheetham mjcheetham force-pushed the fix-singlefile-path branch 2 times, most recently from ba9792a to a5ccf17 Compare February 25, 2021 14:29
When publishing GCM as a 'single file' application, the computed path to
the entry executable is no longer correct.

On .NET Core 3.1, using `Assembly.Location` resolves to the temporary
extracted DLL file path. On .NET 5 `Assembly.Location` always returns the
empty string.

Since .NET 5, published single-file apps no longer use the self-
extraction model, and are real single file with all assemblies and
native libraries statically linked/bundled.

We now use the `Environment.GetCommandLineArgs()` method to get the raw
underlying "argv" arguments, which argv[0] is the absolute file path to
the entry executable.

We also change how we get the application version number to look for the
assembly attribute, rather than extract if from the file on disk.

At app startup, also change the way we trace system information to be
more readable.
Copy link
Contributor

@kyle-rader kyle-rader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


string candidatePath = entryAssembly.Location;
// Use "argv[0]" to get the full path to the entry executable - this is consistent across
// .NET Framework and .NET >= 5 when published as a single file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@mjcheetham mjcheetham merged commit 10d9d66 into git-ecosystem:master Feb 26, 2021
@mjcheetham mjcheetham deleted the fix-singlefile-path branch February 26, 2021 13:23
@mjcheetham mjcheetham mentioned this pull request Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git-credential-manager-core: not found WSL2 Ubuntu 18.04 - Unable to Perform Any Type of Setup
3 participants