Excel-DNA Add-In with connection strings stored in external configuration file

牧云@^-^@ 提交于 2020-02-25 06:56:28

问题


I'm using Excel-Dna in a project where connection strings are stored in an external file called connections.config, which is referenced in the App.config file. When building the project, both config files are copied to the bin folder and the App.config file is renamed <Name>-AddIn64-packed.xll.config as it should be.

The problem is that the packed xll still relies on both config files. Everything works fine when including the connection strings directly in the App.config, but I need to keep them outside of the source code.

Any thoughts on how to proceed?


回答1:


As discussed by Hanselman in his blog. Host your own NuGet Server.

My personal preference is a Choco Nuget Server.

  1. Setup your NuGet Server
  2. Add your xlls to some folder
  3. Pack your files with NuGet

    nuget pack -version 0.0.1

  4. Push your NuGet Package up to the server

    nuget push -source \mycompany\repo\ mypackage.1.0.0.nupkg

Recommended Remove any user credentials such as passwords or usernames




回答2:


Excel-DNA currently does not support App.config external configuration settings via configSource on -packed XLLs if the main .config file + external file is not physically present in the folder where the -packed XLL is.

If you want to use configSource in your case, you'll have to keep these external files together with the -packed XLL, on the same folder.

e.g.

  • <Name>-AddIn-packed.xll
  • <Name>-AddIn-packed.xll.config
  • <Name>-AddIn64-packed.xll
  • <Name>-AddIn64-packed.xll.config
  • connections.config

As an alternative, if you want to have the connection strings on an external file, but still embedded within the -packed XLL, then do not use configSource at all, add your connections.config as an embedded resource of your assembly, and read your connection strings from there.



来源:https://stackoverflow.com/questions/52735817/excel-dna-add-in-with-connection-strings-stored-in-external-configuration-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!