diff --git a/docs/guides-basic/assets/native-aot-addin.png b/docs/guides-basic/assets/native-aot-addin.png new file mode 100644 index 00000000..6a011a21 Binary files /dev/null and b/docs/guides-basic/assets/native-aot-addin.png differ diff --git a/docs/guides-basic/assets/native-aot-command-message.png b/docs/guides-basic/assets/native-aot-command-message.png new file mode 100644 index 00000000..9d25aac1 Binary files /dev/null and b/docs/guides-basic/assets/native-aot-command-message.png differ diff --git a/docs/guides-basic/assets/native-aot-command-ribbon.png b/docs/guides-basic/assets/native-aot-command-ribbon.png new file mode 100644 index 00000000..0483f940 Binary files /dev/null and b/docs/guides-basic/assets/native-aot-command-ribbon.png differ diff --git a/docs/guides-basic/assets/native-aot-dynamic-application-range-set.png b/docs/guides-basic/assets/native-aot-dynamic-application-range-set.png new file mode 100644 index 00000000..111d8910 Binary files /dev/null and b/docs/guides-basic/assets/native-aot-dynamic-application-range-set.png differ diff --git a/docs/guides-basic/assets/native-aot-intellisense-fx.png b/docs/guides-basic/assets/native-aot-intellisense-fx.png new file mode 100644 index 00000000..ce3025e5 Binary files /dev/null and b/docs/guides-basic/assets/native-aot-intellisense-fx.png differ diff --git a/docs/guides-basic/assets/native-aot-ribbon-message1.png b/docs/guides-basic/assets/native-aot-ribbon-message1.png new file mode 100644 index 00000000..330ff737 Binary files /dev/null and b/docs/guides-basic/assets/native-aot-ribbon-message1.png differ diff --git a/docs/guides-basic/assets/native-aot-ribbon-message2.png b/docs/guides-basic/assets/native-aot-ribbon-message2.png new file mode 100644 index 00000000..288fa47b Binary files /dev/null and b/docs/guides-basic/assets/native-aot-ribbon-message2.png differ diff --git a/docs/guides-basic/assets/native-aot-ribbon-ui.png b/docs/guides-basic/assets/native-aot-ribbon-ui.png new file mode 100644 index 00000000..0d132b2d Binary files /dev/null and b/docs/guides-basic/assets/native-aot-ribbon-ui.png differ diff --git a/docs/guides-basic/dotnet-native-aot-support.md b/docs/guides-basic/dotnet-native-aot-support.md new file mode 100644 index 00000000..48dea6eb --- /dev/null +++ b/docs/guides-basic/dotnet-native-aot-support.md @@ -0,0 +1,320 @@ +--- +title: ".NET Native AOT support" +--- + +Excel-DNA can produce native 64-bit Excel add-ins, that can run on machines that don't have the .NET runtime installed, using .NET 8.0 +[Native AOT](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/) +deployment and **ExcelDna.AddIn.NativeAOT** package. + +Publishing the following **MyAddin.csproj** C# project produces native 64-bit **MyAddin-AddIn64.xll** Excel add-in: + +```xml + + + + net8.0-windows + enable + enable + + win-x64 + true + + + + + + + +``` + +# Supported functionality in native add-ins + +## Function + +```csharp +internal class Functions +{ + [ExcelFunction] + public static string NativeHello(string name) + { + return $"Hello {name}!"; + } + + [ExcelFunction] + public static int NativeSum(int i1, int i2) + { + return i1 + i2; + } +} +``` + +| Cell | Formula | Result +| ----- | -------------------- | ------ +| A1 | =NativeHello("AOT") | Hello AOT! +| A2 | =NativeSum(2, 3) | 5 + +## Async function + +```csharp +[ExcelAsyncFunction] +public static async Task NativeAsyncTaskHello(string name, int msDelay) +{ + await Task.Delay(msDelay); + return $"Hello native async task {name}"; +} +``` + +| Cell | Formula | Immediate Result | Final Result +| ----- | ----------------------------------- | ---------------- | ------------------------- +| A1 | =NativeAsyncTaskHello("Test", 5000) | #N/A | Hello native async task Test + +## AddIn + +```csharp +public class AddIn : IExcelAddIn +{ + public void AutoOpen() + { + var thisAddInName = Path.GetFileName((string)XlCall.Excel(XlCall.xlGetName)); + var message = string.Format("Excel-DNA Native AOT Add-In '{0}' loaded!", thisAddInName); + + MessageBox.Show(message, thisAddInName, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + public void AutoClose() + { + } +} +``` + +![AutoOpen](./assets/native-aot-addin.png) + +## Command + +```csharp +[ExcelCommand(MenuText = "MyNativeCommand")] +public static void NativeCommand() +{ + MessageBox.Show("My NativeCommand"); +} +``` + +![](./assets/native-aot-command-ribbon.png) + +![](./assets/native-aot-command-message.png) + +## Ribbon + +```csharp +public class RibbonController : IExcelRibbon +{ + public string GetCustomUI(string RibbonID) + { + return @" + + + + + +