question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document F# support with <PackageReference ...>

See original GitHub issue

In 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:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
govertcommented, Jan 4, 2021

The <SatelliteResourceLanguages>en-US</SatelliteResourceLanguages> property is particularly useful for F# projects, to prevent the extra bunch of localized resource directories.

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
1reaction
matthewcrewscommented, Jan 4, 2021

Can confirm this works. Here’s what I ended up with: https://github.com/matthewcrews/ExcelTestAddIn/blob/master/TestAddIn/TestAddIn.fsproj

  <ItemGroup>
    <PackageReference Include="ExcelDna.AddIn" Version="1.1.1" PrivateAssets="All" />
  </ItemGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

PackageReference support in FSharp projects · Issue #7743
MSBuild appears to support PackageReference for F# projects and will restore packages when specifying the target "restore" however Visual Studio ...
Read more >
PackageReference in project files - NuGet
NET Framework projects support PackageReference, but currently default to packages.config . To use PackageReference, migrate the dependencies ...
Read more >
.net - Problems with conditional PackageReference & ...
Problems with conditional PackageReference & ProjectReference nodes in .csproj files in Visual Studio, but not with dotnet build.
Read more >
PackageReference is not supported for non-dotnet core projects
Rider cannot handle PackageReference sections in classic .net csproj projects, as Visual Studio 2017 can, described here:
Read more >
package Reference (GNU Guix Reference Manual)
9.2.1 package Reference. This section summarizes all the options available in package declarations (see Defining Packages). Data Type: package.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found