├── CppApplication ├── CppApplication.cpp └── CppApplication.vcxproj ├── PublishAotLibrary ├── Class1.cs └── PublishAotLibrary.csproj ├── README.md └── CppPublishAotReference.sln /CppApplication/CppApplication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" int ManagedAdd(int x, int y); 4 | 5 | int main() 6 | { 7 | std::cout << "2 + 2 = " << ManagedAdd(2, 2) << std::endl; 8 | } 9 | -------------------------------------------------------------------------------- /PublishAotLibrary/Class1.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace PublishAotLibrary 4 | { 5 | public class Class1 6 | { 7 | [UnmanagedCallersOnly(EntryPoint = "ManagedAdd")] 8 | public static int ManagedAdd(int x, int y) => x + y; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /PublishAotLibrary/PublishAotLibrary.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | true 6 | true 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample of a C++ project referencing a Native AOT compiled DLL 2 | 3 | ## Building from command line 4 | 5 | ``` 6 | cd CppApplication 7 | msbuild CppApplication.vcxproj 8 | ``` 9 | 10 | The important bit in the vcxproj is this: 11 | 12 | ```xml 13 | 14 | true 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | $(ComputeLinkInputsTargets); 24 | BuildNativeAotProject 25 | 26 | 27 | 28 | 29 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 46 | 47 | ``` 48 | -------------------------------------------------------------------------------- /CppPublishAotReference.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34408.163 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppApplication", "CppApplication\CppApplication.vcxproj", "{B4A84F85-F446-48A1-AAE7-6048B9342B1F}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PublishAotLibrary", "PublishAotLibrary\PublishAotLibrary.csproj", "{82C6F743-5A83-4ED2-82CE-E667ADA966BE}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Debug|Any CPU.ActiveCfg = Debug|x64 21 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Debug|Any CPU.Build.0 = Debug|x64 22 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Debug|x64.ActiveCfg = Debug|x64 23 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Debug|x64.Build.0 = Debug|x64 24 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Debug|x86.ActiveCfg = Debug|Win32 25 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Debug|x86.Build.0 = Debug|Win32 26 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Release|Any CPU.ActiveCfg = Release|x64 27 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Release|Any CPU.Build.0 = Release|x64 28 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Release|x64.ActiveCfg = Release|x64 29 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Release|x64.Build.0 = Release|x64 30 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Release|x86.ActiveCfg = Release|Win32 31 | {B4A84F85-F446-48A1-AAE7-6048B9342B1F}.Release|x86.Build.0 = Release|Win32 32 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Debug|x64.Build.0 = Debug|Any CPU 36 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Debug|x86.Build.0 = Debug|Any CPU 38 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Release|x64.ActiveCfg = Release|Any CPU 41 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Release|x64.Build.0 = Release|Any CPU 42 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Release|x86.ActiveCfg = Release|Any CPU 43 | {82C6F743-5A83-4ED2-82CE-E667ADA966BE}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {58254033-A904-4AF0-98B0-477A85B8FEC1} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /CppApplication/CppApplication.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 17.0 23 | Win32Proj 24 | {b4a84f85-f446-48a1-aae7-6048b9342b1f} 25 | CppApplication 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | true 77 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 78 | true 79 | 80 | 81 | Console 82 | true 83 | 84 | 85 | 86 | 87 | Level3 88 | true 89 | true 90 | true 91 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | true 93 | 94 | 95 | Console 96 | true 97 | true 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | 108 | 109 | Console 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | true 118 | true 119 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | true 121 | 122 | 123 | Console 124 | true 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | true 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | $(ComputeLinkInputsTargets); 144 | BuildNativeAotProject 145 | 146 | 147 | 148 | 149 | 152 | 153 | 156 | 157 | 158 | 159 | 160 | 162 | 163 | 164 | 166 | 167 | 168 | 169 | 170 | 171 | --------------------------------------------------------------------------------