microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

Unpackaged, Framework-dependent WinUI 3 app not able to locate Microsoft.ui.xaml.dll #8141

Open s5bug opened 2 years ago

s5bug commented 2 years ago

Describe the bug

This is similar to other issues regarding Microsoft.ui.xaml.dll not being located, but with the key difference of I want this app to be able to be framework-dependent.

Steps to reproduce the bug

Using the default WinUI3 C# template,

  1. Update the SDK version to match the one installed
  2. Set WindowsPackageType to `None

    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>WinUI3_Test</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;arm64</Platforms>
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
    <WindowsPackageType>None</WindowsPackageType>
    </PropertyGroup>
    
    <ItemGroup>
    <Content Include="Assets\SplashScreen.scale-200.png" />
    <Content Include="Assets\LockScreenLogo.scale-200.png" />
    <Content Include="Assets\Square150x150Logo.scale-200.png" />
    <Content Include="Assets\Square44x44Logo.scale-200.png" />
    <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
    <Content Include="Assets\StoreLogo.png" />
    <Content Include="Assets\Wide310x150Logo.scale-200.png" />
    </ItemGroup>
    
    <ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.5" />
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
    <Manifest Include="$(ApplicationManifest)" />
    </ItemGroup>
    <!-- etc remains unchanged -->

Running the (Unpackaged) version of the project leads to Microsoft.ui.xaml.dll not being found.

Expected behavior

The project behaves equivalently to if

    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

was set, especially when run on the same machine it is being built.

Yes, setting the project to Self Contained does work, but again I would prefer if Framework Dependent was an option.

Screenshots

image

image

NuGet package version

No response

Packaging type

Unpackaged

Windows version

Windows 10 version 21H2 (19044, November 2021 Update)

IDE

Visual Studio 2022, Other

Additional context

I have uploaded a project demonstrating the issue: https://github.com/s5bug/WinUI3-Test

mattico commented 2 years ago

I spent a lot of time trying to fix this issue. See these related discussions:

Here's what I think I know:

What I'm currently doing is building unpackaged+self-contained during development (because many debuggers, profilers, etc. don't support packaged apps well) and building packaged+runtime-dependent for releases to save space. Those are the only two configurations I've found that work.

As an aside, I haven't been able to find a good way to build the same project separately for packaged+runtime-dependent and unpackaged+self-contained or to switch between them easily. Ideally the different options in launchsettings.json (Project vs MsixPackage) could be used to set WindowsAppSDKSelfContained appropriately and trigger a rebuild but I couldn't make it work.

rocksdanister commented 2 years ago

@mattico

As an aside, I haven't been able to find a good way to build the same project separately for packaged+runtime-dependent and unpackaged+self-contained or to switch between them easily. Ideally the different options in launchsettings.json (Project vs MsixPackage) could be used to set WindowsAppSDKSelfContained appropriately and trigger a rebuild but I couldn't make it work.

I have had success using Directory.Build.props to switch between them.

octaviordz commented 1 year ago

Hi @rocksdanister, could you elaborate on how you use Directory.Build.props to switch between packaged and unpackaged. Thank you.

rocksdanister commented 1 year ago

Create Directory.Build.props file in project folder:

<Project>
 <PropertyGroup>
    <IsMsixRelease>false</IsMsixRelease>
 </PropertyGroup>
</Project>

Then add the different flags in csproj file:

  <PropertyGroup Condition="'$(IsMsixRelease)' != 'true'">
    <WindowsPackageType>None</WindowsPackageType>
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>
  <PropertyGroup Condition="'$(IsMsixRelease)' == 'true'">
    <AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
    <AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
    <GenerateTestArtifacts>True</GenerateTestArtifacts>
    <AppxBundle>Always</AppxBundle>..
  </PropertyGroup>
JesseCol commented 11 months ago

Hi, thanks for filing this issue. Can you validate this still repros on WinAppSDK 1.4? If so, please provide a minimal sample app. Thanks!