25

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.

Jalpesh Vadgama
  • 13,653
  • 19
  • 72
  • 94

5 Answers5

38

Alternative way (corresponds to the AppDomain.BaseDirectory):

AppContext.BaseDirectory
Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
31

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
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
10

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);
}
VirendraJ
  • 556
  • 5
  • 14
0

You can't really get the /bin/ folder since it is not relevant to your project and the ASP.NET environment doesn't know what a /bin/ folder is.

And also there isn't exactly a /bin/ folder. You may want to read this article: http://docs.asp.net/en/latest/conceptual-overview/understanding-aspnet5-apps.html

But you can get the so called ApplicationBasePath which is the directory in which you application runs:

public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
     string baseDir = appEnv.ApplicationBasePath;
     // Other startup code
}
Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
  • It is giving the folder with src which I don't want – Jalpesh Vadgama Feb 20 '16 at 18:22
  • Well there isn't exactly a `/bin/` folder. You may want to read this article: http://docs.asp.net/en/latest/conceptual-overview/understanding-aspnet5-apps.html so the project root is the place where the code is started – Nikolay Kostov Feb 20 '16 at 18:23
  • @JalpeshVadgama: This means you're running in the IDE. – Joshua Aug 02 '16 at 22:11
  • The `src` folder is for published client script source. Where do you think ASP.NET put's the DLL your project compiles to? If you copy something to output during build, like a SQL script, it is copied to a `bin` folder, and to use that SQL script, you need to know the full disk path to wherever that script file is. – ProfK May 18 '17 at 13:22
  • 1
    Ancient history now but IApplicationEnvironment has been removed. https://github.com/aspnet/Announcements/issues/171 – Will Nov 17 '21 at 12:17
0

AppDomain.CurrentDomain.BaseDirectory;

EricImhauser
  • 701
  • 2
  • 7
  • 17