AutoGenerateBindingRedirects doesn't work properly
When an addin's csproj has both the AutoGenerateBindingRedirects and GenerateBindingRedirectsOutputType properties defined to true, the App.config file is (potentially) enriched with needed bindingRedirects when it is copied as MyAddIn.dll.config.
However, within the CreateExcelAddIn task, the handling of App.config uses the original App.config, and therefore misses the bindingRedirects.
As a workaround, one can add to the csproj a target along the lines of :
<!-- The CreateExcelAddIn task called in ExcelDnaBuild uses directly the App.config file, so it misses auto-generated bindingRedirect -->
<Target Name="CopyAppConfig" AfterTargets="ExcelDnaBuild">
<Message Importance="High" Text="Copy $(TargetPath).config to $(TargetDir)EudaPlugin-AddIn[64][-packed].xll.config" />
<Copy SourceFiles="$(TargetPath).config" DestinationFiles="$(TargetDir)MyAddIn-AddIn.xll.config" />
<Copy SourceFiles="$(TargetPath).config" DestinationFiles="$(TargetDir)MyAddIn-AddIn-packed.xll.config" />
<Copy SourceFiles="$(TargetPath).config" DestinationFiles="$(TargetDir)MyAddIn-AddIn64.xll.config" />
<Copy SourceFiles="$(TargetPath).config" DestinationFiles="$(TargetDir)MyAddIn-AddIn64-packed.xll.config" />
</Target>
But it would probably be better to try to use the processed MyAddIn.dll.config file in the task.
Thanks for reporting this one @lanfeust69.
I've been meaning to do some work on this for a while, ever since I tried to use slow-cheetah with Excel-DNA add-ins, which also makes changes to the final App.config file, that are not picked-up by the CreateExcelAddIn.
The workaround you have probably works for 95% of the use-cases, but I'm afraid a fix wouldn't be as simple as baking in what your workaround does, because:
- A class library can have more than one
.dnafile, and an.xllw/ a.configgets created for each one - The relationship between the assembly and the add-in is described inside each
.dnafile viaExternalLibraryso to get the "correct" enriched.configfor each.dna. We'd have to know which assembly to use first - and that might mean parsing each.dnafile during the build process :unamused: ... That also brings the question of what to do when a.dnafile has more than oneExternalLibraryelement (supported).
Any chance you're interested in sending a PR to improve this story?
@augustoproiete : thanks for the additional insights.
I didn't have the time to dig things deeper and come up with a PR, and that's why I opened the issue in the first place, to keep track 🙂.
I don't expect to be able to investigate further in the coming weeks, but hopefully I can find a bit of time later on...