Document F# support with <PackageReference ...>
See original GitHub issueIn recent Visual Studio versions (some time in 2020) the F# “Library (.NET Framework)” template was changed to use SDK-style projects and only support <PackageReference .../>
NuGet references, thus breaking the Excel-DNA NuGet package.
Some steps to manually configure such a project:
- Install the ExcelDna.AddIn package
- In the .fsproj file, add the following Properties:
<PropertyGroup>
<ExcelDnaAllowPackageReferenceProjectStyle>true</ExcelDnaAllowPackageReferenceProjectStyle>
<RunExcelDnaSetDebuggerOptions>false</RunExcelDnaSetDebuggerOptions>
</PropertyGroup>
- Add a new file to the project, called
<MyProject>-AddIn.dna
with the following content:
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="MyProject Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2018/05/dnalibrary">
<ExternalLibrary Path="MyProject.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
</DnaLibrary>
-
The name of the .dna file will be used as the root name for the add-in. The NuGet package would normally set this as '<ProjectName>-AddIn.dna`, but it could be ‘Anything.dna’ too.
-
You might want to customize the
<DnaLibrary Name="..." .../>
and check that the<ExternalLibrary Path=..." />
refers to the correct output .dll file name. -
Add some code to the .fs file:
module MyFunctions
open ExcelDna.Integration
[<ExcelFunction(Description="My first .NET function")>]
let HelloDna name =
"Hello " + name
-
Configure debugging in the project properties:
- Set the ‘Launch’ option to ‘Executable’
- Set the Executable as the path to Excel, e.g. for 32-bit Excel I used: C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE
- Set the Application Arguments to be the ‘<MyProject>-AddIn.xll’ file in the output directory (or <MyProject>-AddIn64.xll is your Excel version is 64-bit).
-
Press F5 to compile, start Excel, load the add-in.
-
Check that the =HelloDna(…) function works.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top GitHub Comments
The
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
property is particularly useful for F# projects, to prevent the extra bunch of localized resource directories.Can confirm this works. Here’s what I ended up with: https://github.com/matthewcrews/ExcelTestAddIn/blob/master/TestAddIn/TestAddIn.fsproj