Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you get current physical path inside Startup.cs? #405

Closed
developer1998 opened this issue Mar 24, 2015 · 4 comments
Closed

How do you get current physical path inside Startup.cs? #405

developer1998 opened this issue Mar 24, 2015 · 4 comments

Comments

@developer1998
Copy link

How do you get current physical path inside Startup.cs?
I tried so many things and it does not work. On top of that I am experiencing a very very strange behavior.
When I am debugging and type AppDomain.CurrentDomain.BaseDirectory I get the current path.
However I cannot even compile the code as I get this error on run time if I include AppDomain.CurrentDomain.BaseDirectory directly.
The name 'AppDomain' does not exist in the current context

Thanks.

@davidfowl
Copy link
Member

Don't use that API. Use the one provided by the framework. In your Startup.cs you can take IApplicationEnvironment in the Configure method:

public void Configure(IApplicationBuilder app, IApplicationEnvironment env)
{
   var path  = env.ApplicationBasePath;
}

The reason you're seeing that AppDomain doesn't exist is because it isn't available on CoreCLR. Your project by default compiles for both frameworks.

@developer1998
Copy link
Author

Thanks for your response David. Where does IApplicationEnvironment live?

my Configure looks like this, I am using beta3 btw:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) and I get this error

Error CS1061 'IHostingEnvironment' does not contain a definition for 'ApplicationBasePath' and no extension method 'ApplicationBasePath' accepting a first argument of type 'IHostingEnvironment' could be found (are you missing a using directive or an assembly reference?)

Thanks.

@davidfowl
Copy link
Member

Close, IApplicaitonEnvironment lives in the Microsoft.Framework.Runtime.Interfaces package (which you already reference transitively)

@developer1998
Copy link
Author

Thank you.

natemcmaster pushed a commit that referenced this issue Nov 21, 2018
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants