Search code examples
c#.netwpfcsproj

Config XamlRuntime and DefaultXamlRuntime in csproj file meaning


I try to figure out what the following csproj config means. I googled, but failed to find a result for <XamlRuntime> or $(DefaultXamlRuntime).

<ItemGroup>
  <Page Update="Views\SetupTests.xaml">
    <XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
  </Page>
</ItemGroup>

Solution

  • The XamlRuntime and DefaultXamlRuntime properties were introduced because there are different flavors (or frameworks or runtimes - they are still discussing the right term) of XAML that require different compilers and different build tools. The reason was distinguishing WPF and the upcoming WinUI, which both use XAML. Here is the issue on GitHub with the changes for WPF:

    For now, we'll keep the globbing in WPF targets, and add the appropriate Item metadata and project property, so that vs tooling can distinguish WPF from WinUI in .NET core projects.

    This issue originated from another issue for adding globbing support for WinUI projects, so that the project files are not modified for each XAML file that is added, like in the old .NET Framework projects.

    This issue is still open and there is also a more general proposals for both WinUI the .NET SDK.


    The value for DefaultXamlRuntime for WPF is defined in Microsoft.NET.Sdk.WindowsDesktop.targets:

    <DefaultXamlRuntime Condition="'$(DefaultXamlRuntime)'==''">Wpf</DefaultXamlRuntime>
    

    In the proposal for generic globbing, the default runtime for WinUI is also mentioned:

    <DefaultXamlFramework Condition="'$(DefaultXamlFramework)'=='' and $(UseWpf)'!='true'">WinUI</DefaultXamlFramework>
    

    As @Alp mentioned, there are or were issues related to copy-pasting XAML files that lead to the creation of superflous metadata in the project file and that might be what you are expieriencing.