【发布时间】:2019-04-01 14:41:43
【问题描述】:
.netstandard 2.0 中 AppDomain.CurrentDomain.SetupInformation.PrivateBinPath 的替代方法是什么
【问题讨论】:
-
这具体返回什么,即你想模仿什么。您是否尝试过任何替代方案,或在网上找到任何可能有助于缩小范围的资源
标签: .net .net-4.5 c#-2.0 .net-standard-2.0
.netstandard 2.0 中 AppDomain.CurrentDomain.SetupInformation.PrivateBinPath 的替代方法是什么
【问题讨论】:
标签: .net .net-4.5 c#-2.0 .net-standard-2.0
看来IHostingEnvironment 可能是您正在寻找的,文档指南在这里:https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.ihostingenvironment?view=aspnetcore-2.2
【讨论】:
其实我是在寻找包含代码的程序集的路径:
我发现了这个功能,我认为可以满足我的需求:
public static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
【讨论】: