dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.14k stars 4.71k forks source link

Single-file running from "admin" location may load code from "non-admin" location #39177

Open vitek-karas opened 4 years ago

vitek-karas commented 4 years ago

I have an application which contains some native library dependencies - either the app itself, or for example WPF app (WPF has several native libraries it relies on).

If I publish the app as self-contained but non-single-file, I end up with folder with all of the code in it. If I deploy this folder into an "admin" location (that is location which is writable only to admins, and not normal users - for example C:\Program Files on Windows) and run the app from there, by default the app will not load code outside of its location - that is outside of the "admin" location.

If I publish the app as self-contained single-file and use /p:IncludeNativeLibrariesInSingleFile=true I will get one executable. If I then deploy that to "admin" location and run the app, it will extract the native libraries into a temp folder which is a non-admin location (writable by normal user) and load the native libraries from there. This effectively breaks the behavior which I get without single-file publish.

ghost commented 4 years ago

Tagging subscribers to this area: @swaroop-sridhar, @agocke Notify danmosemsft if you want to be subscribed.

vitek-karas commented 4 years ago

I don't think we should try to solve this in the code - it's really hard. For example, just trying to detect if the app is running from "admin" location is definitely non-trivial (let alone OS specific). That said we should probably document this, and possibly think about SDK experiences around this (warning?, but then most people who don't deploy to "admin" locations would not care).