Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update projection sample #896

Merged
merged 13 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<Platforms>x64</Platforms>
</PropertyGroup>

<PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
../SimpleMathProjection/nuget
https://api.nuget.org/v3/index.json;
../SimpleMathProjection/nuget
</RestoreSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VCRTForwarders.140" Version="1.0.6" />
<PackageReference Include="SimpleMathComponent" Version="0.1.0-prerelease" />
</ItemGroup>
</Project>
18 changes: 12 additions & 6 deletions src/Samples/Net5ProjectionSample/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# C#/WinRT End to End Sample
# C#/WinRT Projection Sample

This sample demonstrates how to invoke C#/WinRT to build a .NET5 projection for a C++/WinRT Runtime Component, create a NuGet package for the component, and reference the NuGet package from a .NET5 console app.
This sample demonstrates how to do the following:

- Use the C#/WinRT package to generate a C# 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 5+ console application

## Requirements

- Visual Studio 16.8
- .NET 5.0 SDK
- Nuget.exe 5.8.0-preview.2 (for command line MSBuild)
- nuget.exe 5.8.0-preview.2 (for command line MSBuild)

## Build and run the sample

Using Visual Studio:
For building in Visual Studio 2019:

1. Build the *CppWinRTComponentProjectionSample* solution first. This builds the WinMD for SimpleMathComponent, generates a projection interop assembly for the component using C#/WinRT, and generates the SimpleMathComponent NuGet package for the component which .NET 5+ apps can reference.

1. Build the *CppWinRTComponentProjectionSample* solution first. This generates the projection and interop assembly using cswinrt, and creates the SimpleMathComponent NuGet package which can be referenced in consuming apps. 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.
2. Build and run the *ConsoleAppSample* solution which references and restores the SimpleMathComponent NuGet package to consume the projection.

2. Build the *ConsoleAppSample* 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.

For building with the command line, execute the following:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ApplicationType>Windows Store</ApplicationType>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.19041.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
<WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
Expand Down Expand Up @@ -69,6 +69,30 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DesktopCompatible>true</DesktopCompatible>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<Platforms>x64</Platforms>
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SimpleMathComponent\SimpleMathComponent.vcxproj" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.0.1" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.2.6" />
</ItemGroup>

<!--CsWinRT properties-->
Expand All @@ -24,9 +25,4 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<!--Specify Windows SDK Metadata-->
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
<group targetFramework=".NETCoreApp3.0" />
<group targetFramework="UAP10.0" />
<group targetFramework=".NETFramework4.6" />
<group targetFramework="net5.0">
<dependency id="Microsoft.Windows.CsWinRT" version="1.0.1" exclude="Build,Analyzers" />
</group>
<group targetFramework="net5.0-windows10.0.19041.0" />
</dependencies>
</metadata>
<files>
<!--Support net46+, netcore3, net5, uap, c++ -->
<!--Architecture-netural assemblies-->
<file src="..\..\_build\x64\Debug\SimpleMathComponent\bin\SimpleMathComponent\SimpleMathComponent.winmd" target="lib\netcoreapp3.0\SimpleMathComponent.winmd" />
<file src="..\..\_build\x64\Debug\SimpleMathComponent\bin\SimpleMathComponent\SimpleMathComponent.winmd" target="lib\uap10.0\SimpleMathComponent.winmd" />
<file src="..\..\_build\x64\Debug\SimpleMathComponent\bin\SimpleMathComponent\SimpleMathComponent.winmd" target="lib\net46\SimpleMathComponent.winmd" />
<file src="..\..\_build\x64\Debug\SimpleMathProjection\bin\SimpleMathProjection.dll" target="lib\net5.0\SimpleMathProjection.dll" />
<file src="..\..\_build\x64\Debug\SimpleMathComponent\bin\SimpleMathComponent\SimpleMathComponent.dll" target="runtimes\win10-x64\native\SimpleMathComponent.dll" />
<file src="..\..\_build\x64\Debug\SimpleMathProjection\bin\SimpleMathProjection.dll" target="lib\net5.0-windows10.0.19041.0\SimpleMathProjection.dll" />
<!--Arch-specific implementation DLLs should be copied into RID-relative folders -->
<file src="..\..\_build\x64\Debug\SimpleMathComponent\bin\SimpleMathComponent\SimpleMathComponent.dll" target="runtimes\win10-x64\native\SimpleMathComponent.dll" />
</files>
</package>