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

时间:2016-06-24 19:17:54

标签: c# asp.net-core .net-core

我有以下代码来检索桌面.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属性?

1 个答案:

答案 0 :(得分:3)

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

相关问题