WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

MRTCore using MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY breaks launching one WinAppSDK app from another

Open DHowett opened this issue 2 months ago • 4 comments

Describe the bug

WinAppSDK applications which use C# registration free WinRT set the environment variable MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY.

https://github.com/microsoft/WindowsAppSDK/blob/bd8e2c16f1e15185ff31beb15cdadd550883f27e/dev/UndockedRegFreeWinRT/UndockedRegFreeWinRT-AutoInitializer.cs#L24-L27

This environment variable is used by MRTCore to locate resources.

https://github.com/microsoft/WindowsAppSDK/blob/bd8e2c16f1e15185ff31beb15cdadd550883f27e/dev/MRTCore/mrt/Core/src/MRM.cpp#L999

When that env var is present, MRTCore skips all local resource PRI locations including ModuleName.pri and just loads resources.pri out of the specified directory.

https://github.com/microsoft/WindowsAppSDK/blob/bd8e2c16f1e15185ff31beb15cdadd550883f27e/dev/MRTCore/mrt/Core/src/MRM.cpp#L1001

This explodes any application that relies on resources when it is spawned from another WinAppSDK application using CreateProcess.


A word of advice: don't use Environment Variables to communicate information across your own processes. They get inherited in places you would not expect.

DHowett avatar Nov 10 '25 22:11 DHowett

Oh, and it allows a user environment variable to control where an elevated process reads a data file from. I hope that MRTCore is fuzzed. :)

DHowett avatar Nov 10 '25 22:11 DHowett

@DHowett MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY is used in the implementation of PublishSingleFile, not reg-free WinRT activation. Is that your scenario? Do you see the same thing without PublishSingleFile?

(The env var was a requirement imposed upon the PublishSingleFile by fusion manifest redirection.)

Scottj1s avatar Nov 17 '25 20:11 Scottj1s

@scottj1s honestly, I looked at the filename and path ("WindowsAppSDK/dev/UndockedRegFreeWinRT/UndockedRegFreeWinRT-AutoInitializer.cs") which is all about "reg" "free" and "winrt" before concluding that it had something to do with undocked reg free winrt. Perhaps my confusion is understandable. 🙂

However, I am happy to confirm that there are 300 instances of PublishSingleFile in the project where we saw this and they are all set to FALSE...

DHowett avatar Nov 24 '25 21:11 DHowett