See the question and my original answer on StackOverflow

Many articles pointed out here are old (aka few years, but few years are ages with .NET Core), and with recent Framework some things are easier than they were but it's hard to find the solution.

So, starting from this (official) tutorial Generate a C# projection from a C++/WinRT component, distribute as a NuGet for .NET apps wich is available as sample code here C#/WinRT Projection Sample. First thing to do is update all packages, especially CsWinRT which is completely outdated (current version as of today is 2.0.7).

And then, thanks to this newer CsWinRT, you don't even need the use an intermediary Nuget project like what's explained in the sample, because this new CsWinRT generates some .cs file on the fly for us from the component's .winmd file (metadata).

Just build the SimpleMathComponent C++/WinRT project, and now you can reference it in a console app with a .csproj like this, using .NET 8 and x64 (debug or release)

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <Nullable>enable</Nullable>
    <PlatformTarget>x64</PlatformTarget>
    <Platforms>x64</Platforms>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
</ItemGroup>

<ItemGroup>
    <ProjectReference Include="..\SimpleMathComponent\SimpleMathComponent.vcxproj" />
</ItemGroup>

<PropertyGroup>
    <CsWinRTIncludes>
        SimpleMathComponent;
    </CsWinRTIncludes>
</PropertyGroup>

We can see the .cs projection auto-generated file in the obj directory:

enter image description here

Now, with a WPF project, the same project layout doesn't work. For some reason, the SimpleMathComponent component is not picked up by CsWinRT for code generation (the only real difference I can see is OutputType, Exe vs WinExe) and the SimpleMathComponent.cs is not generated which causes a compilation error. Looks like a bug to me.

A possible workaround is to feed CsWinRT directly with the input it needs, something like this;

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
        <Nullable>enable</Nullable>
        <PlatformTarget>x64</PlatformTarget>
        <Platforms>x64</Platforms>
        <UseWPF>true</UseWPF>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\SimpleMathComponent\SimpleMathComponent.vcxproj" />
    </ItemGroup>

    <PropertyGroup>
        <CsWinRTParams>
            -target net6.0
            -input 10.0.19041.0
            -input "$(BuildOutDir)SimpleMathComponent\bin\SimpleMathComponent\SimpleMathComponent.winmd"
            -output "$(IntermediateOutputPath)\net8.0-windows10.0.19041.0\Generated Files\CsWinRT"
            -exclude Windows
            -exclude Microsoft
            -include SimpleMathComponent
        </CsWinRTParams>
    </PropertyGroup>
</Project>

Obviously it's less practical than the Console app version (and it needs to be adapted when varying .NET versions, SDK versions, etc.).