working on c++ WinUI3 application
'Cannot locate resource from 'ms-appx:///Sample.xaml'.'. Actually, by default xaml files are placed under TestWRC folder during build process under CoreApp x64 directory but when xaml cpp code is generated, file is referring root location ('ms-appx:///Sample.xaml'.') instead of ('ms-appx:///SampleWRC/Sample.xaml'.').
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="TestWRC.Sample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestWRC"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</Page>
Steps to reproduce the bug
I felt it has to do with configuration/property settings of xaml file but nothing found on project settings. Am I missing anything small here?
source code sample - https://github.com/GMudide/Bugs/tree/main/WinUI%203/CPP
After looking into multiple Microsoft pages found it as a known issue.
To resolve, add the below target to the end of the Windows Runtime Component's .vcxproj:
<Target Name="GetPriIndexName">
<PropertyGroup>
<!-- Winmd library targets use the default root namespace of the project for the App package name -->
<PriIndexName Condition="'$(RootNamespace)' != ''">$(RootNamespace)</PriIndexName>
<!-- If RootNamespace is empty fall back to TargetName -->
<PriIndexName Condition="$(PriIndexName) == ''">$(TargetName)</PriIndexName>
</PropertyGroup>
</Target>