How to change the loading path of references in .NET?

前端 未结 3 1130
逝去的感伤
逝去的感伤 2021-01-16 07:20

I want a setup like this:

+- /ApplicationFolder
  -- App.exe
  -- Core.dll
  -- AnotherShared.dll
  +- /PluginsFolder
    -- plugin1.dll
    -- plugin2.dll
<         


        
相关标签:
3条回答
  • 2021-01-16 07:25

    you can try this: How can I set PrivateBinPath in MEF?

    or you can try handling the Appdomain.AssemblyResolve event that is raised anytime .net cant locate an assembly. there you can implement custom logic to locate and load assemblies from anywhere.

    the AssemblyResolve eventhandler jsut returns either the assembly that is beeing looked for or null, so you could return the already loaded Core.dll from available from the AppDomain.GetAssemblies() method.

    however in your case it should be ok to simply not include Code.dll with plugin1.dll, .net should already realize that Core.dll is loaded and use that instance

    0 讨论(0)
  • 2021-01-16 07:43

    When you create an AppDomain you can define a path for loading assemblies. Set AppDomainSetup.PrivateBinPath and pass to AppDomain.Create domain.

    Using an AppDomain is a good idea for plugins (allows different CAS and unloading).

    To avoid VS/msbuild copying referenced assemblies to the output directory, change "Copy Local" to false in the properties of the reference.

    0 讨论(0)
  • 2021-01-16 07:50

    My MEF application is set up so that plugin projects compile to their own folder (as the is the default), then I use a post-build command to copy specific files to the output extensions folder.

    The other way is to have the project build directly into the appropriate output folder and, as the other poster said, open the "Properties" panel for each relevant reference in your plugin project and set "Copy Local" to false.

    0 讨论(0)
提交回复
热议问题