Search code examples
c#.netvstoconfigurationmanager

prevent App.Config compiled into the dll VSTO (C# \ .Net)


I checked prior posts like How do I prevent the app.config from being integrated into a .net Library (dll)

but these did not help me with my situation.

I am having trouble keeping my Outlook addin app.config not compiled into the dll. I assume it's being compiled, as when it first loads I ask the application to show me the path of its configuration file using:

MessageBox.Show(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.ToString());

This returns a path for a file at

C:\Users\...\AppData\ [random name]\outlookadddin.config

instead of using the app.config which is located in the same folder as the the dll itself.

Can I force configuration manager to refer to the dll in the same folder as the assembly rather than creating one of its own?

UPDATE: after finding this: how do I make my application read the application config instead of machine.config?

it seems to partially advance a solution, shortly explained, its a known issue with VSTO being deployed via ClickOnce \ MSI. you need to add |VSTOLOCAL to the registery manifest key path.

Problem im facing now, is that if i install my addin on a Network drive, using |VSTOLOCAL it simply won't load, removing |VSTOLOCAL and it works like a charm. any ideas ?


Solution

  • OK i finally found an answer to this: it appears since vsto 4.0 - you MUST have |vstolocal at the end of the manifest registry key for it to use the .config file from the folder and not from the cache.

    My issue was solved by adding |VSTOLOCAL to the regkey, but since i want the addin dll to be placed on a NETWORK drive, this caused trust issues with outlook, which for some reason appearse to be not supporting network drive-installed addins by default.

    These were solved by adding this registry key:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\vsto runtime Setup\v4]
    "EnableVSTOLocalUNC"=dword:00000001
    

    Everything works well now. Thanks everyone.