How to get bin folder in ASP.NET Core 1.0
Solution 1
Well, the bin folder does exists but it is moved to artifacts folder next to the solution file. Since ASP.NET Core RC 1 compiles everything in memory, you will find empty bin folder. But if you set "Produce output on build" option to true (Right click Project file -> Properties and Build tab) then you will find the generated files in bin folder.
I don't think so there is any direct property available as to get the path of this but you can use the same solution pointed out by @Nikolay Kostov to get application path. And then using System.IO classes jump to bin folder.
Code updated to for ASP.NET Core as mentioned here.
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);
}
Solution 2
Alternative way (corresponds to the AppDomain.BaseDirectory):
AppContext.BaseDirectory
Solution 3
This works to retrieve the assembly's directory, from which we can determine the bin
location.
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
var directory = System.IO.Path.GetDirectoryName(location);
System.Console.WriteLine(directory);
Output
C:\MyApplication\bin\Debug\netcoreapp1.0
Jalpesh Vadgama
Hi I am Jalpesh Vadgama a Computer Geek, Mentor, Developer, Microsoft MVP and Life long learner. I have more than 10 years of experience in Microsoft.NET and related technologies. I have been awarded Microsoft Most Valuable Profesional 5 times for technical community contribution. My technical blog: http://www.dotnetjalps.com You can reach me via email at : [email protected] On Twitter: @Jalpesh On LinkedIn - http://www.linkedin.com/in/jalpeshvadgama
Updated on July 09, 2022Comments
-
Jalpesh Vadgama almost 2 years
With asp.net core 1.0 There are lots of functionality added. But there is not way to get Bin Folder path.
Can anyone please know how we can get the bin folder path for asp.net core 1.0 application.