Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dev/UndockedRegFreeWinRT/UndockedRegFreeWinRT-AutoInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ class AutoInitialize
// Called by WindowsAppRuntimeAutoInitializer.cs
internal static void AccessWindowsAppSDK()
{
// Set base directory env var for PublishSingleFile support (referenced by SxS redirection)
Environment.SetEnvironmentVariable("MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY", AppContext.BaseDirectory);
try
{
// Set base directory env var for PublishSingleFile support (referenced by SxS redirection)
Environment.SetEnvironmentVariable("MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY", AppContext.BaseDirectory);
}
catch (MissingMethodException)
{
// When the application is trimmed, Environment.SetEnvironmentVariable might be removed
// In this case, we'll fall back to using AppContext.SetData which is less likely to be trimmed
AppContext.SetData("MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY", AppContext.BaseDirectory);
}

// No error handling needed as the target function does nothing (just {return S_OK}).
// It's the act of calling the function causing the DllImport to load the DLL that
Expand Down
16 changes: 16 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ In-box components will be supported forever in the usual way. We have no plans t
(remove their usability) at this time. We will likely slow down or pause investment in
the in-box components while we focus on making the Windows App SDK surface complete.

## How do I create a trimmed MSIX bundle that works with Windows App SDK?

When publishing a .NET application as an MSIX bundle with trimming enabled (PublishTrimmed=true), you might encounter issues with the Windows App SDK initialization. This is because the trimming process might remove methods that Windows App SDK relies on, such as `Environment.SetEnvironmentVariable`.

Starting with Windows App SDK 1.5.5 (version 1.5.240627000) and newer, the Windows App SDK has been updated to handle trimmed applications gracefully. If you're using an older version, you might need to add the following settings to your project file:

```xml
<PropertyGroup>
<PublishTrimmed>false</PublishTrimmed>
<PublishReadyToRun>True</PublishReadyToRun>
<WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained>
</PropertyGroup>
```

If you need to use trimming for size optimization, ensure you're using the latest version of Windows App SDK, which includes compatibility improvements for trimmed applications.

## I don't see my question here!

[Create an issue to ask a question or start a discussion](https://github.com/microsoft/WindowsAppSDK/issues/new/choose).
Expand Down