-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update authoring samples to .NET 6 (#1066)
* update authoring samples to .NET 6 update samples and cleanup some of the docs * Update authoring.md * Update authoring.md * Update authoring.md * add packaged cpp app * address feedback and delete readme.txt
- Loading branch information
1 parent
2990b7b
commit b01c69d
Showing
47 changed files
with
779 additions
and
184 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 22 additions & 25 deletions
47
src/Samples/AuthoringDemo/AuthoringDemo/AuthoringDemo.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework> | ||
<Platforms>x64</Platforms> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework> | ||
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> | ||
<Platforms>x64;x86;arm64</Platforms> | ||
</PropertyGroup> | ||
|
||
<!-- CsWinRT properties --> | ||
<PropertyGroup> | ||
<CsWinRTComponent>true</CsWinRTComponent> | ||
<CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata> | ||
<!--<CsWinRTEnableLogging>true</CsWinRTEnableLogging>--> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.1.4" /> | ||
</ItemGroup> | ||
<!-- CsWinRT properties --> | ||
<PropertyGroup> | ||
<CsWinRTComponent>true</CsWinRTComponent> | ||
<CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata> | ||
<!-- Uncomment the line below to generate a log.txt in the obj folder --> | ||
<!--<CsWinRTEnableLogging>true</CsWinRTEnableLogging>--> | ||
</PropertyGroup> | ||
|
||
<!-- NuGet package generation properties --> | ||
<PropertyGroup> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>1.0.0</Version> | ||
<PackageOutputPath>.\nuget</PackageOutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="nuget\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.4.1" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<!-- NuGet package generation properties --> | ||
<!-- Uncomment the PropertyGroup below to generate a NuGet package for the C# WinRT component --> | ||
<!--<PropertyGroup> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>1.0.0</Version> | ||
</PropertyGroup>--> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="AuthoringDemo" version="1.0.0" targetFramework="native" /> | ||
<package id="Microsoft.Windows.CppWinRT" version="2.0.201217.4" targetFramework="native" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
#include "pch.h" | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
#pragma once | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include <winrt/Windows.Foundation.h> | ||
#include <winrt/Windows.Foundation.Collections.h> | ||
#include <winrt/AuthoringDemo.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
# C#/WinRT Authoring Sample | ||
|
||
This sample demonstrates how to author a simple C#/WinRT component, create a NuGet package for the component, and consume the component as a package reference from a C++/WinRT console app. This sample currently uses [CsWinRT version 1.1.4](https://www.nuget.org/packages/Microsoft.Windows.CsWinRT/1.1.4). Refer to the [authoring docs](https://github.com/microsoft/CsWinRT/blob/master/docs/authoring.md) for more details. | ||
This sample demonstrates how to author a simple C#/WinRT component and consume the component as a project reference. | ||
|
||
- **AuthoringDemo** is is a C# .NET 5 authored component using a **Class Library (.NET Core)** project with some project file modifications. There are two runtime classes authored in *Example.cs* and *FolderEnumeration.cs*, which demonstrate the usage of basic types and WinRT types. | ||
- **AuthoringDemo** is a C# .NET 6 class library project that uses the C#/WinRT NuGet package to generate a WinRT component. There are two runtime classes authored in *Example.cs* and *FolderEnumeration.cs*, which demonstrate the usage of basic types and WinRT types. | ||
|
||
- **CppConsoleApp** is a **Windows Console Application (C++/WinRT)** project that demonstrates consuming the **AuthoringDemo** component with a NuGet package reference. | ||
The following apps demonstrate how to consume the C#/WinRT component **AuthoringDemo**: | ||
|
||
Before building the solution, right click on **AuthoringDemo** solution node and select **Restore NuGet packages**. Set **CppConsoleApp** as the startup project. | ||
- [**CppConsoleApp**](CppConsoleApp) is a **Windows Console Application (C++/WinRT)** project that consumes the **AuthoringDemo** component with a project reference. | ||
|
||
- [**WinUI3CppApp**](WinUI3CppApp) is a C++/WinRT desktop app using the Windows App SDK **Blank App, Packaged (WinUI 3 in Desktop)** template (see [create a WinUI3 C++ Packaged app](https://docs.microsoft.com/windows/apps/winui/winui3/create-your-first-winui3-app?pivots=winui3-packaged-cpp)). | ||
|
||
|
||
|
||
## Prerequisites | ||
|
||
* [.NET 6](https://dotnet.microsoft.com/download/dotnet/6.0) | ||
* Visual Studio 2022 | ||
|
||
**Note**: This sample can be modified to target .NET 5 and Visual Studio 2019. This involves editing the `TargetFramework` properties to target `net5.0-windows10.0.19041.0`. | ||
|
||
## Building and running the sample | ||
|
||
1. Open **AuthoringDemo.sln** in Visual Studio 2022. | ||
|
||
2. Ensure that the **CppConsoleApp** project is set as the startup project. | ||
|
||
3. From Visual Studio, choose **Start Debugging** (F5). | ||
|
||
## Resources | ||
|
||
- [Authoring C#/WinRT components](https://github.com/microsoft/CsWinRT/blob/master/docs/authoring.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace WinUI3CppApp | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Application | ||
x:Class="WinUI3CppApp.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:WinUI3CppApp"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /> | ||
<!-- Other merged dictionaries here --> | ||
</ResourceDictionary.MergedDictionaries> | ||
<!-- Other app resources here --> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "pch.h" | ||
|
||
#include "App.xaml.h" | ||
#include "MainWindow.xaml.h" | ||
|
||
using namespace winrt; | ||
using namespace Windows::Foundation; | ||
using namespace Microsoft::UI::Xaml; | ||
using namespace Microsoft::UI::Xaml::Controls; | ||
using namespace Microsoft::UI::Xaml::Navigation; | ||
using namespace WinUI3CppApp; | ||
using namespace WinUI3CppApp::implementation; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
/// <summary> | ||
/// Initializes the singleton application object. This is the first line of authored code | ||
/// executed, and as such is the logical equivalent of main() or WinMain(). | ||
/// </summary> | ||
App::App() | ||
{ | ||
InitializeComponent(); | ||
|
||
#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION | ||
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) | ||
{ | ||
if (IsDebuggerPresent()) | ||
{ | ||
auto errorMessage = e.Message(); | ||
__debugbreak(); | ||
} | ||
}); | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Invoked when the application is launched normally by the end user. Other entry points | ||
/// will be used such as when the application is launched to open a specific file. | ||
/// </summary> | ||
/// <param name="e">Details about the launch request and process.</param> | ||
void App::OnLaunched(LaunchActivatedEventArgs const&) | ||
{ | ||
window = make<MainWindow>(); | ||
window.Activate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "App.xaml.g.h" | ||
|
||
namespace winrt::WinUI3CppApp::implementation | ||
{ | ||
struct App : AppT<App> | ||
{ | ||
App(); | ||
|
||
void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&); | ||
|
||
private: | ||
winrt::Microsoft::UI::Xaml::Window window{ nullptr }; | ||
}; | ||
} |
Binary file added
BIN
+432 Bytes
src/Samples/AuthoringDemo/WinUI3CppApp/Assets/LockScreenLogo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.25 KB
src/Samples/AuthoringDemo/WinUI3CppApp/Assets/SplashScreen.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.71 KB
src/Samples/AuthoringDemo/WinUI3CppApp/Assets/Square150x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+637 Bytes
src/Samples/AuthoringDemo/WinUI3CppApp/Assets/Square44x44Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+283 Bytes
...ringDemo/WinUI3CppApp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.05 KB
src/Samples/AuthoringDemo/WinUI3CppApp/Assets/Wide310x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace WinUI3CppApp | ||
{ | ||
[default_interface] | ||
runtimeclass MainWindow : Microsoft.UI.Xaml.Window | ||
{ | ||
MainWindow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Window | ||
x:Class="WinUI3CppApp.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:WinUI3CppApp" | ||
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="sayHelloButton" Click="sayHelloButton_Click">Click Me</Button> | ||
</StackPanel> | ||
</Window> |
Oops, something went wrong.