From 8ec0bedee64f6a9d39fb606ea6bc462a7681b6d1 Mon Sep 17 00:00:00 2001
From: Joshua Larkin <70237359+j0shuams@users.noreply.github.com>
Date: Tue, 14 Sep 2021 22:13:16 -0700
Subject: [PATCH] Update authoring support for project references (#919)
* update targets
---
docs/authoring.md | 19 +++++--
...icrosoft.Windows.CsWinRT.Authoring.targets | 56 +++++++++++++++----
2 files changed, 59 insertions(+), 16 deletions(-)
diff --git a/docs/authoring.md b/docs/authoring.md
index 968d52d88..3ead45693 100644
--- a/docs/authoring.md
+++ b/docs/authoring.md
@@ -2,7 +2,8 @@
## Overview
-**Note: Authoring Support is still in preview**
+**Note**: Authoring support is still in preview.
+**Note**: C#/WinRT authoring and hosting project reference support is available with [.NET 6 RC1](https://dotnet.microsoft.com/download/dotnet/6.0) and later. This means the following scenario is **not supported in .NET 5**: C# app with a project reference to a C#/WinRT authored component.
C#/WinRT provides support for authoring Windows Runtime components. You can write a library in C#, and specify that it is a `CsWinRTComponent` for C#/WinRT to produce a WinMD that any WinRT compatible language can use. For example, a library written in C# can be used by a C++ program, via C#/WinRT and C++/WinRT.
Managed apps only need a project or package reference to the authored component, and native apps will need some extra steps that we cover in this documentation.
@@ -25,15 +26,19 @@ To author your component, first create a project using the C# **Class Library (.
- **net5.0-windows10.0.17763.0**
- **net5.0-windows10.0.18362.0**
- **net5.0-windows10.0.19041.0**
+ - **net5.0-windows10.0.20348.0**
+ - **net6.0-windows10.0.17763.0**
+ - **net6.0-windows10.0.18362.0**
+ - **net6.0-windows10.0.19041.0**
+ - **net6.0-windows10.0.20348.0**
2. Install the latest version of the [Microsoft.Windows.CsWinRT](https://www.nuget.org/packages/Microsoft.Windows.CsWinRT) NuGet package.
-3. Add the following C#/WinRT specific properties to the project file. The `CsWinRTComponent` property specifies that your project is a Windows Runtime component, so that a WinMD file is generated for the component. The `CsWinRTWindowsMetadata` property provides a source for Windows Metadata and is required as of the latest C#/WinRT version.
+3. Add the following C#/WinRT specific properties to the project file. The `CsWinRTComponent` property specifies that your project is a Windows Runtime component, so that a WinMD file is generated for the component.
```xml
true
- 10.0.19041.0
```
@@ -67,7 +72,7 @@ Similarly, any other dependencies, e.g. `Microsoft.WinUI`, will need to be inclu
-
@@ -107,7 +112,7 @@ Consuming a C#/WinRT component from a C++/WinRT desktop application is supported
- For package references, simply right-click on the native project node and click **Manage NuGet packages** to find and install the component package.
-- For project references, you also currently need a reference to the component's generated WinMD. The WinMD can be found in the output directory of the authored component's project. To add both the project and WinMD references, right-click on the native project node, and click **Add** -> **Reference**. Select the C#/WinRT component project under the **Projects** node and the generated WinMD file from the **Browse** node.
+- For project references, if your authored component is built with C#/WinRT version 1.3.3 or earlier, you also need a WinMD reference along with the typical project reference. The WinMD can be found in the output directory of the authored component's project. To add both the project and WinMD references, right-click on the native project node, and click **Add** -> **Reference**. Select the C#/WinRT component project under the **Projects** node and the generated WinMD file from the **Browse** node.
For native consumption of C#/WinRT components, you also need to create a manifest file named `YourNativeApp.exe.manifest`. If your app is packaged with MSIX, then you don't need to include the manifest file. In the case that you do make a manifest, you need to add activatable class registrations for the public types in your component. We provide an [authoring sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/AuthoringDemo/CppConsoleApp) with an example manifest file. To create the manifest file:
@@ -119,7 +124,9 @@ For native consumption of C#/WinRT components, you also need to create a manifes
### Consuming from C# applications
-Consuming a C#/WinRT component from C#/.NET 5 is supported by both package reference or project reference. This scenario is equivalent to consuming any ordinary C# class library and does not involve WinRT activation in most cases.
+**Note** Starting with C#/WinRT 1.3.5, project references require .NET 6.
+
+Consuming a C#/WinRT component from C#/.NET apps is supported by both package reference or project reference. This scenario is equivalent to consuming any ordinary C# class library and does not involve WinRT activation in most cases.
### Consuming an out of process component
diff --git a/nuget/Microsoft.Windows.CsWinRT.Authoring.targets b/nuget/Microsoft.Windows.CsWinRT.Authoring.targets
index 65456eab2..798a9374d 100644
--- a/nuget/Microsoft.Windows.CsWinRT.Authoring.targets
+++ b/nuget/Microsoft.Windows.CsWinRT.Authoring.targets
@@ -16,6 +16,11 @@ Copyright (C) Microsoft Corporation. All rights reserved.
true
+
+ x86
+ $(Platform)
+
+
@@ -67,13 +72,13 @@ Copyright (C) Microsoft Corporation. All rights reserved.
PreserveNewest
-
+
WinRT.Host.dll
PreserveNewest
-
-
+
+
-
+
+
+
+
+ %(Filename)%(Extension)
+ PreserveNewest
+
+
+
+ %(Filename)%(Extension)
+ PreserveNewest
+
+
+
+
+
+
+
-
+
+ %(FullPath)
+ PreserveNewest
+
+
+
+
+
+
+
- true
- true
+
WinRT.Host.dll
- false
+
+ true
+
+ %(CsWinRTComponent_ManagedImplementation.TargetPath)
winmd
+ true
+ true
true
@@ -138,7 +173,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
-
+
<_ThisProjectItemstoCopyToOutputDirectory Include="@(CsWinRTSDKRefDll)">