Skip to content

Commit

Permalink
Added AdaptiveCards Template WinRT Component (#8805)
Browse files Browse the repository at this point in the history
* added a new project file

* added test app and c# winrt component

* mostly working?

* fix impl

* updated nuget path

* added c# runtime component

* updated

* updated

* updated

* updated

* updated

* updated

* updated

* updated

* update

* removed winrt prject from AC and added C++ console sample app and the AC project to visualizer

* removed nuget config changes

---------

Co-authored-by: Paul Campbell <paulcam@microsoft.com>
  • Loading branch information
jwoo-msft and paulcam206 committed May 1, 2024
1 parent b1972c6 commit fcebb6d
Show file tree
Hide file tree
Showing 14 changed files with 532 additions and 7 deletions.
35 changes: 33 additions & 2 deletions source/dotnet/AdaptiveCards.Visualizer.Wpf.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29317.48
# Visual Studio Version 17
VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdaptiveCards", "Library\AdaptiveCards\AdaptiveCards.csproj", "{D40ACA37-F5EA-4D3F-B443-CE714AA479A1}"
EndProject
Expand All @@ -15,6 +15,13 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "AdaptiveCards.Sample.WPFVis
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdaptiveCards.Templating", "Library\AdaptiveCards.Templating\AdaptiveCards.Templating.csproj", "{83599799-97B3-4B42-A580-B4CA81DD54CF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TemplateCppConsoleTestApp", "Library\CppConsoleApp\CppConsoleApp.vcxproj", "{ED459EEC-7211-403E-8C08-78A43A05A7BE}"
ProjectSection(ProjectDependencies) = postProject
{3F9B2B81-512C-4276-A06D-69A8C30DE847} = {3F9B2B81-512C-4276-A06D-69A8C30DE847}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdaptiveCards.Template", "Library\AdaptiveCards.Templating.CSharp.WinRT\AdaptiveCards.Template.csproj", "{3F9B2B81-512C-4276-A06D-69A8C30DE847}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -103,6 +110,30 @@ Global
{83599799-97B3-4B42-A580-B4CA81DD54CF}.Release|x64.Build.0 = Release|Any CPU
{83599799-97B3-4B42-A580-B4CA81DD54CF}.Release|x86.ActiveCfg = Release|Any CPU
{83599799-97B3-4B42-A580-B4CA81DD54CF}.Release|x86.Build.0 = Release|Any CPU
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Debug|Any CPU.ActiveCfg = Debug|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Debug|Any CPU.Build.0 = Debug|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Debug|x64.ActiveCfg = Debug|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Debug|x64.Build.0 = Debug|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Debug|x86.ActiveCfg = Debug|Win32
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Debug|x86.Build.0 = Debug|Win32
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Release|Any CPU.ActiveCfg = Release|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Release|Any CPU.Build.0 = Release|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Release|x64.ActiveCfg = Release|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Release|x64.Build.0 = Release|x64
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Release|x86.ActiveCfg = Release|Win32
{ED459EEC-7211-403E-8C08-78A43A05A7BE}.Release|x86.Build.0 = Release|Win32
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Debug|Any CPU.ActiveCfg = Debug|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Debug|Any CPU.Build.0 = Debug|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Debug|x64.ActiveCfg = Debug|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Debug|x64.Build.0 = Debug|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Debug|x86.ActiveCfg = Debug|x86
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Debug|x86.Build.0 = Debug|x86
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Release|Any CPU.ActiveCfg = Release|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Release|Any CPU.Build.0 = Release|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Release|x64.ActiveCfg = Release|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Release|x64.Build.0 = Release|x64
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Release|x86.ActiveCfg = Release|x86
{3F9B2B81-512C-4276-A06D-69A8C30DE847}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
88 changes: 88 additions & 0 deletions source/dotnet/AdaptiveCards.sln

Large diffs are not rendered by default.

105 changes: 104 additions & 1 deletion source/dotnet/AdaptiveCardsNet6.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<Platforms>x86;x64;arm64</Platforms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<CsWinRTComponent>true</CsWinRTComponent>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdaptiveCards.Templating" Version="1.5.0" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// AdaptiveCards template windows runtime component library
namespace AdaptiveCards.Template
{
/// <summary>
/// AdaptiveCards template windows runtime component library
/// </summary>
public sealed class AdaptiveCardTemplate
{
/// <summary>
/// Given a JSON template, create a AdaptiveCardTemplate object that can be used to expand the template
/// </summary>
/// <param name="jsonTemplate">JSON serialized AdaptiveCard Template</param>
public AdaptiveCardTemplate(String jsonTemplate)
{
adaptiveCardTemplate = new AdaptiveCards.Templating.AdaptiveCardTemplate(jsonTemplate);
}

/// <summary>
/// Expands the template with the given data
/// </summary>
/// <param name="rootData">JSON serialized data for AdaptiveCard template</param>
/// <returns></returns>
public string Expand(String rootData)
{
return adaptiveCardTemplate.Expand(rootData);
}

private AdaptiveCards.Templating.AdaptiveCardTemplate adaptiveCardTemplate;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" NoWarn="NU1605" />
<PackageReference Include="Vsxmd" Version="1.4.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
149 changes: 149 additions & 0 deletions source/dotnet/Library/CppConsoleApp/CppConsoleApp.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
<MinimalCoreWin>true</MinimalCoreWin>
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{ed459eec-7211-403e-8c08-78a43a05a7be}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CppConsoleApp</RootNamespace>
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22621.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
<ProjectName>TemplateCppConsoleTestApp</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|arm64">
<Configuration>Debug</Configuration>
<Platform>arm64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|arm64">
<Configuration>Release</Configuration>
<Platform>arm64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="PropertySheet.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<PreprocessorDefinitions>_CONSOLE;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<ControlFlowGuard>Guard</ControlFlowGuard>
<AdditionalOptions>%(AdditionalOptions) /permissive- /bigobj</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalOptions>/profile /DEBUGTYPE:FIXUP %(AdditionalOptions)</AdditionalOptions>
<AdditionalLibraryDirectories>$(VC_LibraryPath_VC_OneCore_CurrentPlatform_spectre);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ProgramDatabase</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="PropertySheet.props" />
</ItemGroup>
<ItemGroup>
<Manifest Include="TemplateCppConsoleTestApp.exe.manifest">
<DeploymentContent>true</DeploymentContent>
</Manifest>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\..\packages\AdaptiveCards.Template.1.0.0\build\AdaptiveCards.Template.targets" Condition="Exists('..\..\packages\AdaptiveCards.Template.1.0.0\build\AdaptiveCards.Template.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\..\packages\AdaptiveCards.Template.1.0.0\build\AdaptiveCards.Template.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\AdaptiveCards.Template.1.0.0\build\AdaptiveCards.Template.targets'))" />
</Target>
</Project>
37 changes: 37 additions & 0 deletions source/dotnet/Library/CppConsoleApp/CppConsoleApp.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Manifest Include="TemplateCppConsoleTestApp.exe.manifest" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions source/dotnet/Library/CppConsoleApp/PropertySheet.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<!--
To customize common C++/WinRT project properties:
* right-click the project node
* expand the Common Properties item
* select the C++/WinRT property page
For more advanced scenarios, and complete documentation, please see:
https://github.com/Microsoft/cppwinrt/tree/master/nuget
-->
<PropertyGroup />
<ItemDefinitionGroup />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="TemplateCppConsoleTestApp"/>
<file name="WinRT.Host.dll">
<activatableClass
name="AdaptiveCards.Template.AdaptiveCardTemplate"
threadingModel="both"
xmlns="urn:schemas-microsoft-com:winrt.v1" />
</file>
</assembly>
25 changes: 25 additions & 0 deletions source/dotnet/Library/CppConsoleApp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "pch.h"

using namespace winrt;
using namespace Windows::Foundation;

// Sample Test App for AdaptiveCards.Template project which is a C#/WinRT component
int main()
{
init_apartment();

hstring input{
L"{\"type\": \"AdaptiveCard\",\"body\": [{\"type\": \"TextBlock\",\"text\": \"Hello, ${hi}!\"}]}"};

AdaptiveCards::Template::AdaptiveCardTemplate adaptiveCardTemplate{ input };

hstring data{ L"{\"hi\": \"world\"}" };
auto result = adaptiveCardTemplate.Expand(data);

std::cout << "Expanded: " << to_string(result) << std::endl;

return 0;
};
5 changes: 5 additions & 0 deletions source/dotnet/Library/CppConsoleApp/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AdaptiveCards.Template" version="1.0.0" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
</packages>
3 changes: 3 additions & 0 deletions source/dotnet/Library/CppConsoleApp/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
9 changes: 9 additions & 0 deletions source/dotnet/Library/CppConsoleApp/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once

#include <iostream>

#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/AdaptiveCards.Template.h>

0 comments on commit fcebb6d

Please sign in to comment.