dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.95k stars 4.9k forks source link

Assembly location when "PublishSingleFile" #4041

Closed heartacker closed 4 years ago

heartacker commented 4 years ago

Issue Title

my wpf application has multi dlls. and when i publish my wpf app as one WinExe singlefile, the code

System.Reflection.Assembly.GetEntryAssembly().Location;
System.Reflection.Assembly.GetExecutingAssembly().Location;
System.Reflection.Assembly.GetCallingAssembly().Location;

return the temp directory, c:\Users\xxx\AppData\Local\Temp\.net\xxxx.xxxx.dll

not the app directory It's confusing

heartacker commented 4 years ago

Some of the functionality of using relative paths breaks down 😖

swaroop-sridhar commented 4 years ago

In the current version, we simply extract the contents of the bundle to a directory on the disk, and declare that directory as the base-directory. This choice aims to preserve compatibility for apps that assume that apcontext.basedirectory contains the app.dll. In the current version, we'll need to use Process.GetCurrentProcess().MainModule.FileName or native APIs such as GetModuleFileName to get the path of the native AppHost.

In subsequent versions, once the app.dll is processed directly from the bundle, the design doc discusses options to set AppContext.BaseDirectory. The current proposal is to set it to the location of the AppHost.

This is a dup of https://github.com/dotnet/core-setup/issues/7491