From 52bf3c33005c5edd46e5713cd79fb9c414cc28e8 Mon Sep 17 00:00:00 2001 From: Angela Zhang Date: Thu, 18 Nov 2021 14:58:10 -0800 Subject: [PATCH 1/5] Update embedded samples to 1.4.1 Some minor doc updates as well --- docs/embedded.md | 46 ++++---- docs/usage.md | 4 + .../SimpleMathProjection.csproj | 4 +- .../Net5App.Bootstrap.csproj | 7 +- .../TestEmbedded/Net5App/Net5App.csproj | 6 +- .../NetCore3App/NetCore3App.csproj | 4 +- .../NetFrameworkApp/NetFrameworkApp.csproj | 7 +- src/Samples/TestEmbedded/README.md | 27 +++-- src/Samples/TestEmbedded/TestEmbedded.sln | 102 +++--------------- .../TestEmbeddedLibrary.csproj | 5 +- .../UnitTestEmbedded/UnitTestEmbedded.csproj | 2 +- 11 files changed, 75 insertions(+), 139 deletions(-) diff --git a/docs/embedded.md b/docs/embedded.md index 770abcf23..c4efd7344 100644 --- a/docs/embedded.md +++ b/docs/embedded.md @@ -2,37 +2,35 @@ ## Overview -**Note**: Embedded support is currently **in preview**. +**Note**: Embedded support is currently **in preview**. -Embedded support is a C#/WinRT feature that allows you to compile the c# projection for the component, within the library/app itself. - -This is done by setting the build property `CsWinRTEmbedded` to `true` in the app or library's project file. +Embedded support is a C#/WinRT feature that allows you to compile C# runtime and projection sources into your library or app's output. This is done by setting the build property `CsWinRTEmbedded` to `true` in the app or library's project file. Enabling embedded support compiles the sources for WinRT.Runtime with the project. -For any types from the component which you want to embed in your project, they must be specified using `CsWinRTIncludes`. +You must specify the types in your component or app which you want to embed using the `CsWinRTIncludes` property. The specified types will be projected and embedded into the project's *.dll*. -This means projects using embedded support no longer have a dependency on a projection for the component, `WinRT.Runtime.dll` or `Microsoft.Windows.SDK.NET.dll` in the case of the Windows SDK projection. +This means that projects using embedded support no longer have a dependency on the projection assembly for the component, `WinRT.Runtime.dll`, or `Microsoft.Windows.SDK.NET.dll` in the case of dependencies on the Windows SDK projection. For an example, you can look at the [sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/TestEmbedded). -Embedded support introduces new features to the C#/WinRT toolchain: +Embedded support introduces new features and benefits to the C#/WinRT toolchain: * Decreased component/app size: The developer only needs to include the minimum necessary parts of the Windows SDK required by their component or app, reducing the size of the output .dll significantly. * Downlevel support: App developers on .NET 5+ can target Windows 7 (`net5.0-windows`) and light-up on Windows 10 (and Windows 11) when consuming an embedded .NET 5+ library. * Removes the need for multi-targeting: Library authors can support all .NET Standard 2.0 app consumers, including .NET 5+, without the need for multi-targeting. App consumers are able to target any .NET Standard 2.0 compatible TFM (e.g. `netcoreapp3.1`, `net48`, and `net5.0-windows`). -It is important to remember that embedded support constrains the scope of Windows Runtime types to your binary. +It is important to remember that embedded support constrains the scope of Windows Runtime types to your binary (e.g., usage of WinRT types must be self-contained). ## Scenarios -This feature allows C# apps and libraries to target `net5.0` (and above), .NET Framework 4.6.1+, `netcoreapp3.1`, and `netstandard2.0` while also using the Windows SDK. -Moreover, a library can target `netstandard2.0` and be able to run on NetFX, Net Core and Net 5. +This feature allows C# apps and libraries to target `net5.0` (and above), .NET Framework 4.6.1+, `netcoreapp3.1`, and `netstandard2.0` while also using Windows SDK types. +Moreover, a library can target `netstandard2.0` and be able to run on .NET Framework, .NET Core, and .NET 5 or later. -Note: the `netstandard2.0` generated projection is not optimized for .NET 5 and won't be as performant. +Note: the `netstandard2.0` generated projection is not optimized for .NET 5 and will not be as performant. ## Usage -Using embedded support allows you to target non-Windows specific TFMs and older versions of .NET. +Using embedded support allows you to target TFMs that are not tied to a specific Windows SDK version, as well as older versions of .NET. You will need to set a few properties: * `CsWinRTEmbedded` - must be set to `true` to include the sources * `CsWinRTIncludes` - Specify the types to be projected; error `CS0246` will highlight any missing namespaces @@ -48,7 +46,7 @@ Targeting `netstandard2.0` requires adding the following two package references: Here is an example project file for a library cross-targeting and embedding a C#/WinRT generated projection. -```csproj +```xml @@ -86,18 +84,20 @@ Here is an example project file for a library cross-targeting and embedding a C# ``` -You will need to enable Windows Desktop Compatible for all your referenced C++/WinRT components -- either via the properties or in the `.vcxproj` file. +**Note**: You will need to enable Windows Desktop Compatible for all your referenced C++/WinRT components, either via the project properties dialog or manually in the `.vcxproj` file. + +## Common issues and troubleshooting -If you try to use an embedded projection of a native (C++/WinRT) component, via ProjectReference, then you may encounter a runtime error `CLASS_NOT_REGISTERED`. +- If you try to use an embedded projection of a native (C++/WinRT) component via ProjectReference, you may encounter a runtime error `CLASS_NOT_REGISTERED`. You can fix this by unloading the native component project in Visual Studio, and adding the following: -```vcxproj - - true - -``` + ```vcxproj + + true + + ``` -Alternatively, you can right-click the C++ project in Visual Studio, select Properties > General > Project Defaults, - and set Windows Desktop Compatible to Yes for all configurations/platforms. + Alternatively, you can right-click the C++ project in Visual Studio, select **Properties** > **General** > **Project Defaults**, + and set Windows Desktop Compatible to Yes for all configurations/platforms. -If you find any other issues using embedded support, please [file an issue]()! +If you find any other issues using embedded support, please [file an issue](https://github.com/microsoft/CsWinRT/issues/new/choose)! diff --git a/docs/usage.md b/docs/usage.md index 4871ee03d..541dce796 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -3,6 +3,7 @@ The [C#/WinRT NuGet package](https://www.nuget.org/packages/Microsoft.Windows.CsWinRT/) provides tooling for the following scenarios: - [Generate and distribute an interop assembly](#generate-and-distribute-an-interop-assembly) +- [Embedded support for WinRT types](#embedded-support-for-winrt-types) - [Author and consume a C#/WinRT component](#author-and-consume-a-cwinrt-component) (in preview) For more information on using the NuGet package, refer to the [NuGet documentation](../nuget/readme.md). Command line options can be displayed by running `cswinrt -?`. @@ -47,6 +48,9 @@ Application developers on .NET 5+ can reference C#/WinRT interop assemblies by a src="images/Diagram_AddProjection.jpg" width="70%" height="50%"> +## Embedded support for WinRT types + +Starting with C#/WinRT version 1.4.1, support is included for embedding Windows SDK projection and runtime sources for both .NET 5+ and .NET Standard 2.0 into your library or app's output. This is useful in scenarios where usage of Windows SDK types is self-contained. Embedded support removes dependencies on WinRT.Runtime.dll and Microsoft.Windows.SDK.NET.dll which reduces the library or app output size. It also allows library developers to provide downlevel support and removes the need for multi-targeting. See the [embedded docs](https://github.com/microsoft/CsWinRT/blob/master/docs/embedded.md) for more details. ## Author and consume a C#/WinRT component diff --git a/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj b/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj index e92488e03..f18f52853 100644 --- a/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj +++ b/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj @@ -1,14 +1,14 @@  - net5.0-windows10.0.19041.0 + net6.0-windows10.0.22000.0 10.0.17763.0 x64 - + diff --git a/src/Samples/TestEmbedded/Net5App.Bootstrap/Net5App.Bootstrap.csproj b/src/Samples/TestEmbedded/Net5App.Bootstrap/Net5App.Bootstrap.csproj index 1401cb73d..4d4adf70b 100644 --- a/src/Samples/TestEmbedded/Net5App.Bootstrap/Net5App.Bootstrap.csproj +++ b/src/Samples/TestEmbedded/Net5App.Bootstrap/Net5App.Bootstrap.csproj @@ -1,11 +1,10 @@  - Exe net5.0-windows + x64;x86;ARM64 - 9 true @@ -13,7 +12,7 @@ - + @@ -49,6 +48,4 @@ Windows.Foundation.AsyncOperationWithProgressCompletedHandler; - - diff --git a/src/Samples/TestEmbedded/Net5App/Net5App.csproj b/src/Samples/TestEmbedded/Net5App/Net5App.csproj index e9c872180..c9661482a 100644 --- a/src/Samples/TestEmbedded/Net5App/Net5App.csproj +++ b/src/Samples/TestEmbedded/Net5App/Net5App.csproj @@ -1,8 +1,7 @@  - Exe - x64;x86 + x64;x86;ARM64 net5.0-windows sdk @@ -10,11 +9,10 @@ - + - diff --git a/src/Samples/TestEmbedded/NetCore3App/NetCore3App.csproj b/src/Samples/TestEmbedded/NetCore3App/NetCore3App.csproj index a75f547ba..6f2be948d 100644 --- a/src/Samples/TestEmbedded/NetCore3App/NetCore3App.csproj +++ b/src/Samples/TestEmbedded/NetCore3App/NetCore3App.csproj @@ -1,14 +1,12 @@  - Exe netcoreapp3.1 - x64;x86 + x64;x86;ARM64 9 - diff --git a/src/Samples/TestEmbedded/NetFrameworkApp/NetFrameworkApp.csproj b/src/Samples/TestEmbedded/NetFrameworkApp/NetFrameworkApp.csproj index febb4c2c1..2bfb46fe6 100644 --- a/src/Samples/TestEmbedded/NetFrameworkApp/NetFrameworkApp.csproj +++ b/src/Samples/TestEmbedded/NetFrameworkApp/NetFrameworkApp.csproj @@ -1,8 +1,8 @@  - Exe net47 + x64;x86;ARM64 @@ -12,12 +12,11 @@ - + - @@ -46,6 +45,4 @@ Windows.Foundation.AsyncOperationWithProgressCompletedHandler; - - diff --git a/src/Samples/TestEmbedded/README.md b/src/Samples/TestEmbedded/README.md index 8449e1455..8d6b63f38 100644 --- a/src/Samples/TestEmbedded/README.md +++ b/src/Samples/TestEmbedded/README.md @@ -1,16 +1,29 @@ -# Structure +# C#/WinRT Embedded Sample -This sample is composed of C++/WinRT components, a C#/WinRT projection that uses embedded support -(WinRT and Windows SDK), and apps of various flavors that use the embedded projection. +These samples demonstrate how to use [C#/WinRT Embedded Support](../../../docs/embedded.md). -Looking at the C#/WinRT projection, `TestEmbeddedLibrary`, we see it targets several different frameworks, +## Structure + +This sample is composed of a few projects to demonstrate C#/WinRT embedded support: + +- C++/WinRT component projects: *Alpha*, *Beta*, *Gamma* +- *TestEmbeddedLibrary*: a C# library project using C#/WinRT embedded support to embed the WinRT.Runtime and Windows SDK sources into the projection/library output. +- C#/.NET apps of various flavors that use the embedded projection (either by referencing *TestEmbeddedLibrary*, or by referencing the C++/WinRT components and generating the projection directly in the app project): + - *Net5App*: References *TestEmbeddedLibrary* to consume the embedded projection. + - *Net5App.Bootstrap*: References *Alpha*, *Beta*, and *Gamma* and creates an embeddded projection in the app itself. + - *NetCore3App*: References *TestEmbeddedLibrary* to consume the embedded projection. + - *NetFrameworkApp*: References *Alpha*, *Beta*, and *Gamma* and creates an embeddded projection in the app itself. + +Looking at the C#/WinRT embedded projection, `TestEmbeddedLibrary`, we see it targets several different frameworks, demonstrating support for the latest Windows SDK on all platforms. ```xml net6.0-windows;net5.0-windows;netstandard2.0;net48 ``` -Of the apps, `Net5App` and `NetCore3App` use the same C#/WinRT projection to make use of Windows 10 APIs -like `Windows.Devices.Geolocation` via the embedded WinRT support provided by C#/WinRT. +Of the apps, `Net5App` and `NetCore3App` reference the same C#/WinRT embedded projection (*TestEmbeddedLibrary*) to make use of WinRT APIs +like `Windows.Devices.Geolocation`. The other two apps, `Net5App.Bootstrap` and `NetFrameworkApp`, demonstrate how an app can generate and embed the projection itself using a package reference to C#/WinRT. + +## Build and run the sample -The other two, `Net5App.Bootstrap` and `NetFrameworkApp` demonstrate how an app can generate and embed the projection itself. +Open `TestEmbedded.sln` in Visual Studio. Select one of the application projects described above as the startup project in Visual Studio. Then build and run the application. diff --git a/src/Samples/TestEmbedded/TestEmbedded.sln b/src/Samples/TestEmbedded/TestEmbedded.sln index a15c88d63..fdf9d16be 100644 --- a/src/Samples/TestEmbedded/TestEmbedded.sln +++ b/src/Samples/TestEmbedded/TestEmbedded.sln @@ -32,186 +32,116 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Net5App.Bootstrap", "Net5Ap EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|ARM = Debug|ARM Debug|ARM64 = Debug|ARM64 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|ARM = Release|ARM Release|ARM64 = Release|ARM64 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|ARM.ActiveCfg = Debug|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|ARM.Build.0 = Debug|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|ARM64.Build.0 = Debug|Any CPU + {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|ARM64.ActiveCfg = Debug|x64 + {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|ARM64.Build.0 = Debug|x64 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|x64.ActiveCfg = Debug|x64 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|x64.Build.0 = Debug|x64 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|x86.ActiveCfg = Debug|x86 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Debug|x86.Build.0 = Debug|x86 - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|Any CPU.Build.0 = Release|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|ARM.ActiveCfg = Release|Any CPU - {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|ARM.Build.0 = Release|Any CPU {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|ARM64.ActiveCfg = Release|Any CPU {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|ARM64.Build.0 = Release|Any CPU {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|x64.ActiveCfg = Release|x64 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|x64.Build.0 = Release|x64 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|x86.ActiveCfg = Release|x86 {A732BAA0-7E07-462F-B11B-179210D50C1A}.Release|x86.Build.0 = Release|x86 - {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|ARM.ActiveCfg = Debug|ARM - {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|ARM.Build.0 = Debug|ARM {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|ARM64.ActiveCfg = Debug|ARM64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|ARM64.Build.0 = Debug|ARM64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|x64.ActiveCfg = Debug|x64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|x64.Build.0 = Debug|x64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|x86.ActiveCfg = Debug|Win32 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Debug|x86.Build.0 = Debug|Win32 - {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|Any CPU.ActiveCfg = Release|Win32 - {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|ARM.ActiveCfg = Release|ARM - {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|ARM.Build.0 = Release|ARM {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|ARM64.ActiveCfg = Release|ARM64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|ARM64.Build.0 = Release|ARM64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|x64.ActiveCfg = Release|x64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|x64.Build.0 = Release|x64 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|x86.ActiveCfg = Release|Win32 {9D73F8C2-332B-4AA9-95E3-59C92E68EFB4}.Release|x86.Build.0 = Release|Win32 - {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|ARM.ActiveCfg = Debug|ARM - {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|ARM.Build.0 = Debug|ARM {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|ARM64.ActiveCfg = Debug|ARM64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|ARM64.Build.0 = Debug|ARM64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|x64.ActiveCfg = Debug|x64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|x64.Build.0 = Debug|x64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|x86.ActiveCfg = Debug|Win32 {DDB1A216-1527-4F49-8729-17A6519659C8}.Debug|x86.Build.0 = Debug|Win32 - {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|Any CPU.ActiveCfg = Release|Win32 - {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|ARM.ActiveCfg = Release|ARM - {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|ARM.Build.0 = Release|ARM {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|ARM64.ActiveCfg = Release|ARM64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|ARM64.Build.0 = Release|ARM64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|x64.ActiveCfg = Release|x64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|x64.Build.0 = Release|x64 {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|x86.ActiveCfg = Release|Win32 {DDB1A216-1527-4F49-8729-17A6519659C8}.Release|x86.Build.0 = Release|Win32 - {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|ARM.ActiveCfg = Debug|ARM - {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|ARM.Build.0 = Debug|ARM {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|ARM64.ActiveCfg = Debug|ARM64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|ARM64.Build.0 = Debug|ARM64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|x64.ActiveCfg = Debug|x64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|x64.Build.0 = Debug|x64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|x86.ActiveCfg = Debug|Win32 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Debug|x86.Build.0 = Debug|Win32 - {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|Any CPU.ActiveCfg = Release|Win32 - {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|ARM.ActiveCfg = Release|ARM - {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|ARM.Build.0 = Release|ARM {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|ARM64.ActiveCfg = Release|ARM64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|ARM64.Build.0 = Release|ARM64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|x64.ActiveCfg = Release|x64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|x64.Build.0 = Release|x64 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|x86.ActiveCfg = Release|Win32 {E1C44B28-965C-45AB-BCB4-475B627E32A6}.Release|x86.Build.0 = Release|Win32 - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|ARM.ActiveCfg = Debug|ARM - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|ARM.Build.0 = Debug|ARM - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|ARM64.Build.0 = Debug|ARM64 + {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|ARM64.ActiveCfg = Debug|x64 + {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|ARM64.Build.0 = Debug|x64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|x64.ActiveCfg = Debug|x64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|x64.Build.0 = Debug|x64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|x86.ActiveCfg = Debug|x86 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Debug|x86.Build.0 = Debug|x86 - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|Any CPU.Build.0 = Release|Any CPU - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|ARM.ActiveCfg = Release|ARM - {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|ARM.Build.0 = Release|ARM {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|ARM64.ActiveCfg = Release|ARM64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|ARM64.Build.0 = Release|ARM64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|x64.ActiveCfg = Release|x64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|x64.Build.0 = Release|x64 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|x86.ActiveCfg = Release|x86 {1FD2F1DA-ACF3-408F-BD13-9D1BA24833E0}.Release|x86.Build.0 = Release|x86 - {9B147973-329B-4331-8207-B6832696D01A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9B147973-329B-4331-8207-B6832696D01A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9B147973-329B-4331-8207-B6832696D01A}.Debug|ARM.ActiveCfg = Debug|ARM - {9B147973-329B-4331-8207-B6832696D01A}.Debug|ARM.Build.0 = Debug|ARM - {9B147973-329B-4331-8207-B6832696D01A}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {9B147973-329B-4331-8207-B6832696D01A}.Debug|ARM64.Build.0 = Debug|ARM64 + {9B147973-329B-4331-8207-B6832696D01A}.Debug|ARM64.ActiveCfg = Debug|x64 + {9B147973-329B-4331-8207-B6832696D01A}.Debug|ARM64.Build.0 = Debug|x64 {9B147973-329B-4331-8207-B6832696D01A}.Debug|x64.ActiveCfg = Debug|x64 {9B147973-329B-4331-8207-B6832696D01A}.Debug|x64.Build.0 = Debug|x64 {9B147973-329B-4331-8207-B6832696D01A}.Debug|x86.ActiveCfg = Debug|x86 {9B147973-329B-4331-8207-B6832696D01A}.Debug|x86.Build.0 = Debug|x86 - {9B147973-329B-4331-8207-B6832696D01A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9B147973-329B-4331-8207-B6832696D01A}.Release|Any CPU.Build.0 = Release|Any CPU - {9B147973-329B-4331-8207-B6832696D01A}.Release|ARM.ActiveCfg = Release|ARM - {9B147973-329B-4331-8207-B6832696D01A}.Release|ARM.Build.0 = Release|ARM {9B147973-329B-4331-8207-B6832696D01A}.Release|ARM64.ActiveCfg = Release|AR64 {9B147973-329B-4331-8207-B6832696D01A}.Release|ARM64.Build.0 = Release|AR64 {9B147973-329B-4331-8207-B6832696D01A}.Release|x64.ActiveCfg = Release|x64 {9B147973-329B-4331-8207-B6832696D01A}.Release|x64.Build.0 = Release|x64 {9B147973-329B-4331-8207-B6832696D01A}.Release|x86.ActiveCfg = Release|x86 {9B147973-329B-4331-8207-B6832696D01A}.Release|x86.Build.0 = Release|x86 - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|ARM.ActiveCfg = Debug|ARM - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|ARM.Build.0 = Debug|ARM - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|ARM64.Build.0 = Debug|ARM64 + {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|ARM64.ActiveCfg = Debug|x64 + {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|ARM64.Build.0 = Debug|x64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|x64.ActiveCfg = Debug|x64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|x64.Build.0 = Debug|x64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|x86.ActiveCfg = Debug|x86 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Debug|x86.Build.0 = Debug|x86 - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|Any CPU.Build.0 = Release|Any CPU - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|ARM.ActiveCfg = Release|ARM - {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|ARM.Build.0 = Release|ARM {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|ARM64.ActiveCfg = Release|ARM64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|ARM64.Build.0 = Release|ARM64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|x64.ActiveCfg = Release|x64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|x64.Build.0 = Release|x64 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|x86.ActiveCfg = Release|x86 {C7796A44-CD3E-4A04-9BED-42D2233C1182}.Release|x86.Build.0 = Release|x86 - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|ARM.ActiveCfg = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|ARM.Build.0 = Debug|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|ARM64.ActiveCfg = Debug|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|ARM64.Build.0 = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x64.ActiveCfg = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x64.Build.0 = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x86.ActiveCfg = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x86.Build.0 = Debug|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|Any CPU.Build.0 = Release|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|ARM.ActiveCfg = Release|Any CPU - {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|ARM.Build.0 = Release|Any CPU + {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x64.ActiveCfg = Debug|x64 + {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x64.Build.0 = Debug|x64 + {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x86.ActiveCfg = Debug|x86 + {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Debug|x86.Build.0 = Debug|x86 {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|ARM64.ActiveCfg = Release|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|ARM64.Build.0 = Release|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|x64.ActiveCfg = Release|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|x64.Build.0 = Release|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|x86.ActiveCfg = Release|Any CPU {6A457D15-4080-4CCA-9980-D418C2EE2BDF}.Release|x86.Build.0 = Release|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|ARM.ActiveCfg = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|ARM.Build.0 = Debug|Any CPU {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|ARM64.ActiveCfg = Debug|Any CPU {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|ARM64.Build.0 = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x64.ActiveCfg = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x64.Build.0 = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x86.ActiveCfg = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x86.Build.0 = Debug|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|Any CPU.Build.0 = Release|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|ARM.ActiveCfg = Release|Any CPU - {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|ARM.Build.0 = Release|Any CPU + {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x64.ActiveCfg = Debug|x64 + {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x64.Build.0 = Debug|x64 + {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x86.ActiveCfg = Debug|x86 + {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Debug|x86.Build.0 = Debug|x86 {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|ARM64.ActiveCfg = Release|Any CPU {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|ARM64.Build.0 = Release|Any CPU {D2D4B83C-1E8B-44F0-BCC3-217B6D9141FB}.Release|x64.ActiveCfg = Release|Any CPU diff --git a/src/Samples/TestEmbedded/TestEmbeddedLibrary/TestEmbeddedLibrary.csproj b/src/Samples/TestEmbedded/TestEmbeddedLibrary/TestEmbeddedLibrary.csproj index d7cca46b2..96e92869c 100644 --- a/src/Samples/TestEmbedded/TestEmbeddedLibrary/TestEmbeddedLibrary.csproj +++ b/src/Samples/TestEmbedded/TestEmbeddedLibrary/TestEmbeddedLibrary.csproj @@ -1,8 +1,7 @@  - net6.0-windows;net5.0-windows;netstandard2.0;net48 - x64;x86 + x64;x86;ARM64 @@ -12,7 +11,7 @@ - + diff --git a/src/Samples/TestEmbedded/UnitTestEmbedded/UnitTestEmbedded.csproj b/src/Samples/TestEmbedded/UnitTestEmbedded/UnitTestEmbedded.csproj index 7b47bac35..6ddb56373 100644 --- a/src/Samples/TestEmbedded/UnitTestEmbedded/UnitTestEmbedded.csproj +++ b/src/Samples/TestEmbedded/UnitTestEmbedded/UnitTestEmbedded.csproj @@ -11,7 +11,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From 90e400a7a50ea76403f0e17a7870bb063a3f5536 Mon Sep 17 00:00:00 2001 From: Angela Zhang Date: Thu, 18 Nov 2021 15:01:30 -0800 Subject: [PATCH 2/5] Update embedded.md --- docs/embedded.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/embedded.md b/docs/embedded.md index c4efd7344..731f0de5c 100644 --- a/docs/embedded.md +++ b/docs/embedded.md @@ -1,18 +1,13 @@ # Embedded C#/WinRT Support -## Overview - -**Note**: Embedded support is currently **in preview**. +**Note**: Embedded support is currently **in preview** in C#/WinRT v1.4.1. -Embedded support is a C#/WinRT feature that allows you to compile C# runtime and projection sources into your library or app's output. This is done by setting the build property `CsWinRTEmbedded` to `true` in the app or library's project file. +## Overview -Enabling embedded support compiles the sources for WinRT.Runtime with the project. -You must specify the types in your component or app which you want to embed using the `CsWinRTIncludes` property. +Embedded support is a C#/WinRT feature that allows you to compile C# runtime (WinRT.Runtime) and projection sources into your library or app's output. This is done by setting the build property `CsWinRTEmbedded` to `true` in the app or library's project file. You must specify the types in your component or app which you want to embed using the `CsWinRTIncludes` property. The specified types will be projected and embedded into the project's *.dll*. This means that projects using embedded support no longer have a dependency on the projection assembly for the component, `WinRT.Runtime.dll`, or `Microsoft.Windows.SDK.NET.dll` in the case of dependencies on the Windows SDK projection. -For an example, you can look at the [sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/TestEmbedded). - Embedded support introduces new features and benefits to the C#/WinRT toolchain: * Decreased component/app size: The developer only needs to include the minimum necessary parts of the Windows SDK required by their component or app, reducing the size of the output .dll significantly. * Downlevel support: App developers on .NET 5+ can target Windows 7 (`net5.0-windows`) and light-up on Windows 10 @@ -21,6 +16,8 @@ Embedded support introduces new features and benefits to the C#/WinRT toolchain: It is important to remember that embedded support constrains the scope of Windows Runtime types to your binary (e.g., usage of WinRT types must be self-contained). +For an example, you can look at the [sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/TestEmbedded). + ## Scenarios This feature allows C# apps and libraries to target `net5.0` (and above), .NET Framework 4.6.1+, `netcoreapp3.1`, and `netstandard2.0` while also using Windows SDK types. @@ -101,3 +98,7 @@ You can fix this by unloading the native component project in Visual Studio, and and set Windows Desktop Compatible to Yes for all configurations/platforms. If you find any other issues using embedded support, please [file an issue](https://github.com/microsoft/CsWinRT/issues/new/choose)! + +## Resources + +- [Embedded sample](https://github.com/microsoft/CsWinRT/tree/master/src/Samples/TestEmbedded) From a9fee9eeae4bfd73abb010066235df13c98ac231 Mon Sep 17 00:00:00 2001 From: angelazhangmsft Date: Thu, 18 Nov 2021 15:03:29 -0800 Subject: [PATCH 3/5] undo change to projection sample --- .../SimpleMathProjection/SimpleMathProjection.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj b/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj index f18f52853..1d478fcfb 100644 --- a/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj +++ b/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj @@ -1,14 +1,14 @@  - net6.0-windows10.0.22000.0 + net6.0-windows10.0.19041.0 10.0.17763.0 x64 - + From bbd3940360ab9d1dec7623da3454730ed081fc17 Mon Sep 17 00:00:00 2001 From: angelazhangmsft Date: Thu, 18 Nov 2021 15:03:56 -0800 Subject: [PATCH 4/5] undo change --- .../SimpleMathProjection/SimpleMathProjection.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj b/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj index 1d478fcfb..e92488e03 100644 --- a/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj +++ b/src/Samples/Net5ProjectionSample/SimpleMathProjection/SimpleMathProjection.csproj @@ -1,7 +1,7 @@  - net6.0-windows10.0.19041.0 + net5.0-windows10.0.19041.0 10.0.17763.0 x64 From fd23ca4106f75fe5562b3dca17d0b6b00916628e Mon Sep 17 00:00:00 2001 From: angelazhangmsft Date: Tue, 23 Nov 2021 09:12:49 -0800 Subject: [PATCH 5/5] WinRT runtime for C# --- docs/embedded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/embedded.md b/docs/embedded.md index 731f0de5c..b0c4f5409 100644 --- a/docs/embedded.md +++ b/docs/embedded.md @@ -4,7 +4,7 @@ ## Overview -Embedded support is a C#/WinRT feature that allows you to compile C# runtime (WinRT.Runtime) and projection sources into your library or app's output. This is done by setting the build property `CsWinRTEmbedded` to `true` in the app or library's project file. You must specify the types in your component or app which you want to embed using the `CsWinRTIncludes` property. +Embedded support is a C#/WinRT feature that allows you to compile the WinRT runtime for C# and the projection sources into your library or app's output. This is done by setting the build property `CsWinRTEmbedded` to `true` in the app or library's project file. You must specify the types in your component or app which you want to embed using the `CsWinRTIncludes` property. The specified types will be projected and embedded into the project's *.dll*. This means that projects using embedded support no longer have a dependency on the projection assembly for the component, `WinRT.Runtime.dll`, or `Microsoft.Windows.SDK.NET.dll` in the case of dependencies on the Windows SDK projection.