2016-02-20 33 views
12

使用asp.net core 1.0添加了很多功能。但是沒有辦法獲得Bin文件夾的路徑。如何在ASP.NET Core 1.0中獲取bin文件夾

任何人都可以請知道我們如何才能獲得asp.net核心1.0應用程序的bin文件夾路徑。

+0

你爲什麼要一個bin文件夾? –

+0

@MuqeetKhan原因之一是檢索生成的XML文檔文件。 –

回答

7

好,bin文件夾確實存在,但它被移動到解決方案文件旁邊的工件文件夾。由於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); 
} 
0

你不能真正得到/bin/文件夾,因爲它是不相關的項目和ASP.NET環境不知道/bin/文件夾是什麼。

而且還不完全是/bin/文件夾。你可能想看看這篇文章:http://docs.asp.net/en/latest/conceptual-overview/understanding-aspnet5-apps.html

但你可以得到所謂的ApplicationBasePath這是在你運行應用程序的目錄:

public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) 
{ 
    string baseDir = appEnv.ApplicationBasePath; 
    // Other startup code 
} 
+0

它給與我不想要的src的文件夾 –

+0

那麼確實沒有'/ bin /'文件夾。你可能想閱讀這篇文章:http://docs.asp.net/en/latest/conceptual-overview/understanding-aspnet5-apps.html所以項目的根目錄是代碼開始的地方 –

+0

@JalpeshVadgama:This意味着你正在IDE中運行。 – Joshua

22

這個工程檢索組件的目錄,從中我們可以判斷bin位置。

var location = System.Reflection.Assembly.GetEntryAssembly().Location; 
var directory = System.IO.Path.GetDirectoryName(location); 
System.Console.WriteLine(directory); 

輸出

C:\MyApplication\bin\Debug\netcoreapp1.0 
+0

在我的本地環境中適用於我,但它可以在Azure API Service上工作嗎? – fahadash

+0

@fahadash我還沒有嘗試過。 –

7

替代方式(相當於AppDomain.BaseDirectory):

AppContext.BaseDirectory 
相關問題