Skip to content

Commit dd6a99c

Browse files
committed
Fix CsWinRT
Thanks to Manodasan, this fixes the CsWinRT support. :-)
1 parent b5bb471 commit dd6a99c

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

Samples/Islands/DrawingIsland/DrawingCppTestApp/WinMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace winrt
1515
using namespace DrawingIslandComponents;
1616
}
1717

18-
int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
18+
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
1919
{
2020
winrt::init_apartment(winrt::apartment_type::single_threaded);
2121

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0-windows</TargetFramework>
4+
<OutputType>WinExe</OutputType>
5+
6+
<!-- TODO: Why do we need to specify a specific Windows version? -->
7+
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
68
<ImplicitUsings>enable</ImplicitUsings>
79
<Nullable>enable</Nullable>
810
<Platforms>x64;ARM64;x86</Platforms>
11+
12+
<!-- TODO: Why do we need to specify the explicit RIDs? -->
13+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
914
</PropertyGroup>
1015

1116
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -21,18 +26,15 @@
2126
</PropertyGroup>
2227

2328
<ItemGroup>
29+
<!-- Added CsWinRT reference to avoid WinMD error as a result of WinMD leaking via project reference. -->
30+
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.7" />
31+
32+
<!-- Reference WASDK for types -->
2433
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
2534
</ItemGroup>
2635

2736
<ItemGroup>
2837
<ProjectReference Include="..\DrawingIslandCsProjection\DrawingIslandCsProjection.csproj" />
2938
</ItemGroup>
3039

31-
<!-- Workaround for "error NETSDK1082: There was no runtime pack for Microsoft.NETCore.App available for the specified RuntimeIdentifier 'win10-arm'." -->
32-
<ItemGroup>
33-
<KnownRuntimePack Update="@(KnownRuntimePack)">
34-
<LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == 'TARGETFRAMEWORK'">EXISTINGVERSION</LatestRuntimeFrameworkVersion>
35-
</KnownRuntimePack>
36-
</ItemGroup>
37-
3840
</Project>
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
11
using System;
2+

3+
using Microsoft.UI;
4+
using Microsoft.UI.Composition;
5+
using Microsoft.UI.Content;
6+
using Microsoft.UI.Dispatching;
7+
using Microsoft.UI.Input;
8+
using Microsoft.UI.Windowing;
29

3-
// See https://aka.ms/new-console-template for more information
4-
Console.WriteLine("Hello, World!");
10+
using DrawingIslandComponents;
11+
12+
var controller = DispatcherQueueController.CreateOnCurrentThread();
13+
var queue = controller.DispatcherQueue;
14+
15+
var window = AppWindow.Create();
16+
window.AssociateWithDispatcherQueue(queue);
17+
window.Closing +=(sender, args) =>
18+
{
19+
queue.EnqueueEventLoopExit();
20+
};
21+
22+
window.Title = "Drawing C# .NET TestApp";
23+
window.Show();
24+
25+
var compositor = new Compositor();
26+
var drawing = new DrawingIsland(compositor);
27+
28+
var siteBridge = DesktopChildSiteBridge.Create(compositor, window.Id);
29+
siteBridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
30+
siteBridge.Show();
31+
siteBridge.Connect(drawing.Island);
32+
33+
queue.RunEventLoop();
34+
35+
controller.ShutdownQueue();

Samples/Islands/DrawingIsland/DrawingIslandCsProjection/DrawingIslandCsProjection.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0-windows10.0.18362.0</TargetFramework>
4+
<!-- TODO: Why do we need to specify the latest Win11 SDK instead of RS5 SDK? -->
5+
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
56
<ImplicitUsings>enable</ImplicitUsings>
67
<Nullable>enable</Nullable>
78
<Platforms>x64;x86;ARM64</Platforms>
9+
10+
<!-- TODO: Why do we need to specify the explicit RIDs? -->
11+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
812
</PropertyGroup>
913

1014
<!-- See "Edit the project file to execute C#/WinRT" from https://learn.microsoft.com/en-us/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component. -->

0 commit comments

Comments
 (0)