You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Working directory for ASP.NET Core WebApplication is set to project folder #5053
Feature-DebuggingLaunching an application via F5, setting debug properties and launch profiles.Triage-InvestigateReviewed and investigation needed by dev team
Summary:
When I run a newly created empty WebApplication and start Debugging the WorkingDirectory is the projects root folder. When I create an empty console application it is the Output Directory. I expect both to be the same (and am quite sure this was the case some time in the past?).
Steps to Reproduce:
Create an empty web application project with .Net Core 2.1 or 2.2.
Paste this code:
Console.WriteLine("CurrentDirectory in Main: {0}",System.IO.Directory.GetCurrentDirectory());
Run the project without IIS (IIS will show the same behavior but logging it is a bit more complicated).
Expected Behavior:
The output is CurrentDirectory in Main: {ProjectPath}\bin\Debug\netcoreapp2.2
Actual Behavior:
The output is CurrentDirectory in Main: {ProjectPath}
User Impact:
I can't use a library that expects the WorkingDirectory to be in the output directory without adding some code changing the working directory to where it should have been in the first place.
Other notes
This issue seems to have been reappearing and fixed for console applications and now seems to appear for web applications as well.
Reacted by paule96, Evgeniy Andreev, Aleks Ch, Sascha Beyer, Johan Benschop, Nirmal Guru, Bruno Zell, Michael Scheffler, Luis Cantero, Esteban and 22 more
I think Microsoft have to make a clear statement, is working directory for console and web apps supposed to be the same, or are they promoting what @davkean wrote in issue #2239.
For console apps it has to be output directory.
Triage: This needs investigation as to what the right behavior is, please reach out to @BillHiebert on ASP.NET tooling to figure out if there's work for either team to do here.
ASP.NET applications use the project folder as the process working directory on purpose. This enables a workflow where you can modify resources (CSS, JS, HTML, images, ...) in VS and have those picked up in a browser via hot reload or manual refresh without having to build or publish.
Changing this would break well established workflows.
ASP.NET applications use the project folder as the process working directory on purpose. This enables a workflow where you can modify resources (CSS, JS, HTML, images, ...) in VS and have those picked up in a browser via hot reload or manual refresh without having to build or publish.
Changing this would break well established workflows.
Well, this is by design for the front then.
So I'll continue changing the default directory in all my APIs then...
ASP.NET applications use the project folder as the process working directory on purpose. This enables a workflow where you can modify resources (CSS, JS, HTML, images, ...) in VS and have those picked up in a browser via hot reload or manual refresh without having to build or publish.
Changing this would break well established workflows.
The real workaround for this """feature""" is to set the "workingDirectory" in launchSettings.json to $(TargetDir). Or from the menu Debug -> Debug Properties -> Launch Profiles -> Working Directory = $(TargetDir)
But I have to note that I find the fact that ASP.NET projects were hardcoded to behave peculiarly in many ways (including this), instead of having a proper template for ASP.NET with an appropriate launchSettings.json frankly, quite ludicrous
Reacted by HeinziAT, Maintenance-Partnership-Systems, Andres Hoyos, flier268, Dubzer and VisualMelon
ASP.NET applications use the project folder as the process working directory on purpose. This enables a workflow where you can modify resources (CSS, JS, HTML, images, ...) in VS and have those picked up in a browser via hot reload or manual refresh without having to build or publish.
Changing this would break well established workflows.
The real workaround for this """feature""" is to set the "workingDirectory" in launchSettings.json to $(TargetDir). Or from the menu Debug -> Debug Properties -> Launch Profiles -> Working Directory = $(TargetDir)
But I have to note that I find the fact that ASP.NET projects were hardcoded to behave peculiarly in many ways (including this), instead of having a proper template for ASP.NET with an appropriate launchSettings.json frankly, quite ludicrous
Awesome, I didn't know we can set this from the launchSettings.json, I should have checked before.
Feature-DebuggingLaunching an application via F5, setting debug properties and launch profiles.Triage-InvestigateReviewed and investigation needed by dev team
Activity
pi3k14 commentedon Jul 16, 2019
I think Microsoft have to make a clear statement, is working directory for console and web apps supposed to be the same, or are they promoting what @davkean wrote in issue #2239.
For console apps it has to be output directory.
pi3k14 commentedon Jul 16, 2019
This websdk #238 might be relevant.
bricelam commentedon Sep 17, 2019
Issue #3619 is about changing console apps to match the behavior of web apps
AcellaEDU commentedon Dec 25, 2019
It is actual for netcore 3.1 (AST.NET CORE 3.1 MVC/SPA )
davkean commentedon Jan 20, 2020
Triage: This needs investigation as to what the right behavior is, please reach out to @BillHiebert on ASP.NET tooling to figure out if there's work for either team to do here.
davkean commentedon Jan 28, 2020
Please factor in #3619 when you look into this.
7 remaining items
jjmew commentedon Nov 16, 2021
We have reached out to the Web Tools team for additional input
tmeschter commentedon Dec 3, 2021
Likely By Design.
drewnoakes commentedon Dec 7, 2021
ASP.NET applications use the project folder as the process working directory on purpose. This enables a workflow where you can modify resources (CSS, JS, HTML, images, ...) in VS and have those picked up in a browser via hot reload or manual refresh without having to build or publish.
Changing this would break well established workflows.
jmevel commentedon Dec 7, 2021
Well, this is by design for the front then.
So I'll continue changing the default directory in all my APIs then...
peterhirn commentedon Jan 9, 2022
@jmevel Can you elaborate on how you accomplish this?
I tried setting the working directory in the project file
But
TargetDir,TargetPath, etc. are returning empty values.jmevel commentedon Jan 9, 2022
Sorry maybe my comment wasn't clear enough. I was talking about changing the current directory simply with Directory.SetCurrentDirectory
dmytroshchotkin commentedon Feb 7, 2023
As nicely described (here), you can use
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)panagiotidisc commentedon Jan 9, 2024
The real workaround for this """feature""" is to set the
"workingDirectory"inlaunchSettings.jsonto$(TargetDir). Or from the menu Debug -> Debug Properties -> Launch Profiles -> Working Directory =$(TargetDir)But I have to note that I find the fact that ASP.NET projects were hardcoded to behave peculiarly in many ways (including this), instead of having a proper template for ASP.NET with an appropriate launchSettings.json frankly, quite ludicrous
jmevel commentedon Feb 5, 2024
Awesome, I didn't know we can set this from the
launchSettings.json, I should have checked before.Thanks for the tips