I have created a Nuget.org package, with the following (abridged) code:
namespace MyNugetPackageNS
module MyNugetModule =
open ExcelDna.Integration
// this function is NOT seen in the package user's Excel session
[<ExcelFunction(Category="Test", Description="Add 1.")>]
let plusOne ([<ExcelArgument(Description= "Value.")>] value: double) : obj =
value + 1.0 |> box
I was hoping that if a user installs the package and adds it into his own library, all the Excel functions defined in the package (e.g. plusOne) would automatically be visible within Excel, but it isn't the case. It seems that the user has to "wrap" the package Excel functions in order to make them visible in Excel, e.g. :
namespace UserNS
module UserModule =
// need to install the nuget package from Nuget.org
open MyNugetPackageNS.MyNugetModule
open ExcelDna.Integration
// this function is seen in the package user's Excel session
[<ExcelFunction(Category="Test", Description="Add 1.")>]
let plusOne2 ([<ExcelArgument(Description= "Value.")>] value: double) : obj =
MyNugetModule.plusOne value
My question : Is there a way to make the package's Excel functions automatically "visible" in the package user's Excel session, without wrapping each function before hand?
=================
EDIT:
Following Augusto's tip, I added Excel-DNA Registration package to my Nuget project, and based on the examples found here, I added the MakeAddInsVisible
snippet which explicitly loads the Nuget project's Excel functions.
namespace MyNugetPackageNS
open ExcelDna.Integration
open ExcelDna.Registration
type MakeAddInsVisible () =
interface IExcelAddIn with
member this.AutoOpen () =
ExcelRegistration.GetExcelFunctions ()
|> ExcelRegistration.RegisterFunctions
member this.AutoClose () = ()
module MyNugetModule =
open ExcelDna.Integration
// this function is STILL NOT seen in the package user's Excel session
[<ExcelFunction(Category="Test", Description="Add 1.")>]
let plusOne ([<ExcelArgument(Description= "Value.")>] value: double) : obj =
value + 1.0 |> box
I also added the ExplicitRegistration
flag to my Nuget project's .dna file :
<DnaLibrary Name="MyNugetPackageNS Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2018/05/dnalibrary">
<ExternalLibrary Path="MyNugetPackageNS.dll" ExplicitExports="true" ExplicitRegistration="true" LoadFromBytes="true" Pack="true" IncludePdb="false" />
</DnaLibrary>
"Locally" (meaning when I use MyNugetPackageNS as a normal package, before exporting it to Nuget.org), this seems to work as expected: Because of the ExplicitRegistration="true"
flag in the .dna file, the Excel functions are still registered because of the presence of the MakeAddInsVisible
snippet (and no Excel function would be registered when the snippet is commented out).
Now I exported this new code to nuget.org and downloaded the package into the nuget package user's project (without any modifications to the above namespace UserNS ...
code).
Unfortunately MyNugetPackageNS
Excel functions are still invisible from the nuget package user's Excel session.
What did I miss?