-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the projection sample to .NET 6 (#1054)
- Loading branch information
1 parent
9ad6e66
commit b216a38
Showing
24 changed files
with
131 additions
and
179 deletions.
There are no files selected for viewing
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
14 changes: 0 additions & 14 deletions
14
src/Samples/Net5ProjectionSample/ConsoleAppSample/Program.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/Samples/Net5ProjectionSample/SimpleMathComponent/PropertySheet.props
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/Samples/Net5ProjectionSample/SimpleMathComponent/SimpleMath.idl
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
src/Samples/Net5ProjectionSample/SimpleMathProjection/nuget/SimpleMathProjection.nuspec
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using System; | ||
|
||
var x = new SimpleMathComponent.SimpleMath(); | ||
Console.WriteLine("Adding 5.5 + 6.5 ..."); | ||
Console.WriteLine(x.add(5.5, 6.5).ToString()); |
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
File renamed without changes.
File renamed without changes.
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,42 @@ | ||
# C#/WinRT Projection Sample | ||
|
||
This sample demonstrates how to do the following: | ||
|
||
- Use the C#/WinRT package to generate a C# .NET projection interop assembly from a C++/WinRT component | ||
- Distribute the component along with the interop assembly as a NuGet package | ||
- Consume the component from a .NET 6 C# console application | ||
|
||
## Requirements | ||
|
||
* [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) with the Universal Windows Platform development workload installed. In **Installation Details** > **Universal Windows Platform development**, check the **C++ (v14x) Universal Windows Platform tools** option. | ||
* [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0) | ||
* nuget.exe 5.8.0-preview.2 or later (for command line MSBuild) | ||
|
||
**Note**: This sample uses .NET 6 and therefore requires Visual Studio 2022 to build and run. If you prefer, you can use Visual Studio 2019 and modify the sample to target [.NET 5](https://dotnet.microsoft.com/download/dotnet/5.0). To do this, you will need to modify the `TargetFramework` and the *nuspec* file in the `SimpleMathProjection` project to target `net5.0-windows10.0.19041.0`. | ||
|
||
## Build and run the sample | ||
|
||
For building in Visual Studio: | ||
|
||
1. Open *CppWinRTComponentProjectionSample.sln* in Visual Studio. Ensure that *SimpleMathProjection* is set as the startup project, and set the Platform and Configuration to x64 and Release. Right click on the solution and build. This will do the following: | ||
- Build *SimpleMathComponent*: this will generate *SimpleMathComponent.winmd* and *SimpleMathComponent.dll* | ||
- Generate the projection interop assembly for the component using C#/WinRT, *SimpleMathProjection.dll* | ||
- Generate a NuGet package for the component. To ensure the solution has built successfully, navigate to the *SimpleMathProjection/nuget* folder in your file explorer. You should see the generated NuGet package (*SimpleMathComponent.0.1.0-prerelease.nupkg*). which can be referenced by C# .NET app consumers. | ||
|
||
2. Open *ConsoleAppSample.sln* in Visual Studio. Build and run the solution which references and restores the SimpleMathComponent NuGet package to consume the projection. | ||
|
||
- If you run into errors restoring NuGet packages, look at the docs on [NuGet restore options](https://docs.microsoft.com/nuget/consume-packages/package-restore). You may need to configure your NuGet package manager settings to allow for package restores on build. You may also need to run `nuget.exe restore ConsoleAppSample.sln` from a command prompt. | ||
|
||
For building with the command line, execute the following: | ||
|
||
```cmd | ||
nuget restore CppWinRTComponentProjectionSample.sln | ||
msbuild /p:platform=x64;configuration=release CppWinRTComponentProjectionSample.sln | ||
nuget restore ConsoleAppSample.sln | ||
msbuild /p:platform=x64;configuration=release ConsoleAppSample.sln | ||
``` | ||
|
||
## Resources | ||
|
||
- [Walkthrough documentation](https://docs.microsoft.com/windows/uwp/csharp-winrt/net-projection-from-cppwinrt-component) for this sample | ||
- [C#/WinRT NuGet properties](../../../nuget/README.md) |
13 changes: 3 additions & 10 deletions
13
...Sample/SimpleMathComponent/SimpleMath.cpp → ...Sample/SimpleMathComponent/SimpleMath.cpp
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
13 changes: 3 additions & 10 deletions
13
...onSample/SimpleMathComponent/SimpleMath.h → ...onSample/SimpleMathComponent/SimpleMath.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
15 changes: 15 additions & 0 deletions
15
src/Samples/NetProjectionSample/SimpleMathComponent/SimpleMath.idl
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 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace SimpleMathComponent | ||
{ | ||
[default_interface] | ||
runtimeclass SimpleMath | ||
{ | ||
SimpleMath(); | ||
Double add(Double firstNumber, Double secondNumber); | ||
Double subtract(Double firstNumber, Double secondNumber); | ||
Double multiply(Double firstNumber, Double secondNumber); | ||
Double divide(Double firstNumber, Double secondNumber); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.