简体   繁体   中英

Referencing (config file) assembly location while debugging VSTO addin

Due to problem with referencing application config in excel addins ( Excel Add-In not loading app.config with service reference config information ) I have referenced the assembly location for the config file.

The problem I am now encountering is that each time I launch a debug instance, the assembly is put in a different path (GUID folders under local AppData directory). So I cannot put a copy of the config file in there.

Any suggestions to get around this?

Best solution turned out to be discard above solution and use solution from post: Change default app.config at runtime

Because while the original link would then allow you to access the config file, you would have to manually extract the information to bind the webservice.

However originally I did persist with the original and found: To enable the solution in original link to work I had to change the way of accessing directory (which I have now submitted this change to the original linked solution):

AppDomain.CurrentDomain.BaseDirectory

rather than

new FileInfo(Assembly.GetCallingAssembly().Location).DirectoryName

AppDomain.CurrentDomain.BaseDirectory would reference a stable location while debugging (the source directory where the original app.config is located), and the correct install directory for the installed version of the Addin (the addin directory rather than Microsoft Excel directory).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM