是否存在.NET Core中的AppDomain.RelativeSearchPath替换?

问题描述 投票:0回答:1

我有以下代码来检索桌面.NET Framework中的应用程序二进制目录:

static string GetBinDirectory()
{
    var relativePath = AppDomain.CurrentDomain.RelativeSearchPath;
    var basePath = AppDomain.CurrentDomain.BaseDirectory;
    return string.IsNullOrEmpty(relativePath) || !relativePath.IsSubdirectoryOf(basePath)
        ? basePath
        : relativePath;
}

此代码在诸如运行NUnit测试的程序集阴影复制等极端情况下工作正常。我开始将此代码迁移到.NET Core平台。

我发现ASP.NET Core中有IHostingEnvironment.ContentRootPath属性。

在纯.NET Core中获取应用程序二进制文件的正确途径是哪种方法?

哪个是AppDomain.RelativeSearchPath财产的替代品?

c# asp.net-core .net-core
1个回答
3
投票

您可能正在寻找PlatformServices.Default.Application.ApplicationBasePath,它是应用程序所在文件夹的路径。

© www.soinside.com 2019 - 2024. All rights reserved.