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

Current executing assembly location is wrong for single file published project #13531

Closed
Arclight3 opened this issue Oct 2, 2019 · 6 comments

Comments

@Arclight3
Copy link

Current executing assembly location is wrong when the project is published as a single file

General

I upgraded a .net core 2.2 application to 3.0 and I enabled the PublishSingleFile feature.
Unfortunately the current executing assembly location is not the directory where the executable is located. It is something like this:

%AppData%\Local\Temp.net<project_name>\q1upmq4v.zgw

  • This is how the single file publish feature is configured:
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishTrimmed>true</PublishTrimmed>
    <OutputType>Exe</OutputType>

  • This is how I get the location of the current executing assembly:
    var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

@scalablecory
Copy link
Contributor

I'm not sure if this will work, but try using Assembly.CodeBase rather than Assembly.Location.

@jeffschwMSFT is this something you're familiar with?

@Arclight3
Copy link
Author

Ok. I`ll give it a try and share the results.

@Arclight3
Copy link
Author

It didn't work. It returns the same path as Location.

@MichalStrehovsky MichalStrehovsky transferred this issue from dotnet/core Oct 4, 2019
@MichalStrehovsky
Copy link
Member

Cc @vitek-karas @swaroop-sridhar

@swaroop-sridhar
Copy link
Contributor

The assermbly-location is the location of the main application DLL, which will be the temporary extraction directory. You can use something like:
Process.GetCurrentProcess().MainModule.FileName

Or pinvoke into GetModuleFileNameW(Null, , )

@swaroop-sridhar
Copy link
Contributor

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants