替换 .NET 6 / .NET Core 中已过时的 Assembly.CodeBase

Replacement for obsolete Assembly.CodeBase in .NET 6 / .NET Core

我们通过 ClickOnce 部署一个辅助可执行文件以及我们的 VSTO / Outlook 插件。

在 AddIn 中,我们有一个按钮可以在新进程中启动这个辅助可执行文件(这是必需的,因为 AddIn 以 32 位运行/与 Outlook 位结合)。

直到现在我通过使用 Assembly.CodeBase 来管理它来获取安装的 VSTO dll 的路径,我也可以在其中找到帮助程序可执行文件。

我不能使用 Assembly.Location,因为这指向另一个神秘的缓存路径,我只能在其中找到当前的 dll,而不是我安装的带有辅助可执行文件的一堆 dll。

现在的问题是:在 .NET core / .NET 6 中,Assembly.CodeBase 已过时,那么如何在我的 outlook 加载项中找到我的助手可执行文件?

还有其他想法,如何实现? 提前致谢。

您可以使用 System.AppDomain.CurrentDomain.BaseDirectory property which returns the base directory that the assembly resolver uses to probe for assemblies. See How to get folder path for ClickOnce application 作为其他选择。