Asp.net

如何在 ASP.NET Core 1.0 中獲取 bin 文件夾

  • February 20, 2016

用 asp.net core 1.0 增加了很多功能。但是沒有辦法獲得 Bin 文件夾路徑。

誰能知道我們如何獲取 asp.net core 1.0 應用程序的 bin 文件夾路徑。

好吧,bin 文件夾確實存在,但它被移動到解決方案文件旁邊的**artifacts 文件夾中。**由於 ASP.NET Core RC 1 編譯記憶體中的所有內容,您會發現空的 bin 文件夾。但是,如果您將“生成時生成輸出”選項設置為 true(右鍵點擊項目文件 -> 屬性和建構選項卡),那麼您將在 bin 文件夾中找到生成的文件。

我不認為有任何直接屬性可用於獲取此路徑,但您可以使用@Nikolay Kostov 指出的相同解決方案來獲取應用程序路徑。然後使用 System.IO 類跳轉到 bin 文件夾。

程式碼已更新為此處提到的 ASP.NET Core。

<http://www.talkingdotnet.com/get-application-wwwroot-path-aspnet-core-rc2/>

public Startup(IHostingEnvironment env, IApplicationEnvironment appenv)
{
    string sAppPath = env.ContentRootPath;
    string sRootPath = Path.GetFullPath(Path.Combine(sAppPath, @"..\..\"));
    string sBinFolderPath = @"artifacts\bin\" + appenv.ApplicationName;
    string sBinPath = Path.Combine(sRootPath, sBinFolderPath);
}

替代方式(對應於 AppDomain.BaseDirectory):

AppContext.BaseDirectory

引用自:https://stackoverflow.com/questions/35527144