Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrameworkReference issue with xll (.NET 6) #671

Open
Sandoli opened this issue Jan 19, 2024 · 3 comments
Open

FrameworkReference issue with xll (.NET 6) #671

Sandoli opened this issue Jan 19, 2024 · 3 comments

Comments

@Sandoli
Copy link

Sandoli commented Jan 19, 2024

I want to build a xll from a .csproj in .NET 6.

  <ItemGroup>
    <PackageReference Include="ExcelDna.AddIn" Version="1.7.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="6.0.0" />
    <FrameworkReference Include="Microsoft.AspNetCore.App" Version="6.0.0" />
  </ItemGroup>

This xll depends on Microsoft.Extensions.Configuration because I want to read the .xll.config file.
The xll also transitively depends on FrameworkReference "Microsoft.AspNetCore.App" because of other mandatory stuff.

Now when packing the xll, I observes that Microsoft.Extensions.Configuration.dll and other needed dlls are not packed.
They are not copied in the output folder by MSBuild, this works as intended as the dlls are part of Microsoft.AspNetCore.App. I understand this is the reason of their absence in the packed xll.

Now, while trying to load the xll with Excel, I have this error :

ComAddIn [Error] The Ribbon/COM add-in helper required by add-in TestAddin Add-In could not be registered.
This may be due to the helper add-in being disabled by Excel.
To repair, open Disabled items in the Options->Add-Ins page and re-enable target add-in, then restart Excel.
Error details: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at ExcelDna.Integration.ExcelComAddInHelper.LoadComAddIn(ExcelComAddIn addIn) : TargetInvocationException - Exception has been thrown by the target of an invocation.

I can confirm that if I get rid of the FrameworkReference, all the dlls are packed as intended and the xll loads successfully. But this is not my use case.
I tried to play with the runtimeconfig.json file but I did not manage to make it work.

My runtimeconfig.json file looks like below:

  "runtimeOptions": {
    "tfm": "net6.0",
    "rollForward": "LatestMinor",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.0"
      }
    ]
  }
}

Could you tell me what I missed please?

@govert
Copy link
Member

govert commented Jan 19, 2024

With Excel-DNA (at least at the moment) you can't target the ASP.NET version of the framework. I can't remember whether there is a serious problem, or it just worked out in the way we load the runtime. Anyway, we currently always load the Microsoft.WindowsDesktop.App framework, and your project's .runtimeconfig.json is ignored.
Since all add-ins targeting .NET 6+ shared the runtime environment, your add-in is not as isolated as with .NET Framework 4.x.

The Microsoft.Extensions.Configuration libraries should, however, work fine with just the Desktop runtime. You might try to see how things look without the ASP.NET bits. I expect the right dependencies will then get copied to the output and packed in the add-in.

If you need to host some http server from the add-in, then you can directly get an HttpListener working, like I mentioned:https://groups.google.com/g/exceldna/c/aIK6qLflaDQ/m/cT4kc_nYAQAJ

@Sandoli
Copy link
Author

Sandoli commented Jan 22, 2024

Hi Govert,

Thank you. As you suggested I am heading towards a removal of the ASP.NET bits.

Thanks also for the link on the HttpListener, it could help.

@govert
Copy link
Member

govert commented Mar 11, 2024

We’ve now added an option to Excel-DNA to load the runtime using the add-in project’s .runtimeconfig.json file.
This feature is added to the preview version 1.8.0-alpha3.

I’ve made a small test project that shows how the ASP.NET Core SDK can now be loaded and used from an add-in.
govert/TestAspNetAddIn (github.com)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants