Repository navigation
Change default working directory to the output folder - #3073
Conversation
| private async Task<string> GetOutputDirectoryAsync(ConfiguredProject configuredProject) | ||
| { | ||
| var properties = configuredProject.Services.ProjectPropertiesProvider.GetCommonProperties(); | ||
| var outdir = await properties.GetEvaluatedPropertyValueAsync("OutDir").ConfigureAwait(false); |
There was a problem hiding this comment.
Are we safe to rely on OutDir in all cases?
There was a problem hiding this comment.
There was a problem hiding this comment.
Definitely no guarantee, unfortunately: even without the ASP.NET confusion, a project (or NuGet package) could customize outputs so they don't respond to the convention.
That said, ASP.NET Core projects look to me like they behave ok, so something must have changed since that blog post.
I think this design is safe for this, but see Nat's other comment too for belt + suspenders.
There was a problem hiding this comment.
I push another change which adds the fallback logic suggested by Rainer
| // the project), or the project folder. | ||
| string defaultWorkingDir = projectFolder; | ||
| // If no working directory specified in the profile, we default to output directory. | ||
| string defaultWorkingDir = await GetOutputDirectoryAsync(configuredProject).ConfigureAwait(false); |
There was a problem hiding this comment.
Is it possible for OutDir to be unset (manually or otherwise), making it necessary to fallback on project folder?
There was a problem hiding this comment.
It's definitely possible for it to be manually unset. It'd probably break lots of other things, though.
It might be wise to check for check for empty as well as directory existence.
…changes the location of Directory.GetCurrentDirectory(): dotnet/project-system#3073. Updated launchSettings.json to prevent being broken from this.
|
Has this behaviour been changed in newer versions? Using .Net Core 2.1.302 it seems working directory it not changed, i.e. it is whatever it is from where I'm experiencing issues with |
|
Output from |
|
Looks like this problem is still around: Directory.GetCurrentDirectory still returns the project file for me |
|
@siberianguy @BillHiebert @micdah @Pilchie |
|
@Compufreak345 @siberianguy Can you please open a new issue for this? |
|
@siberianguy @jjmew I created issue #5053 for it. As I tried creating a reproducable example I found that this behaviour occures with a new WebApplication but not with a new ConsoleApplication. |

Changed the default working directory to be the output folder rather than the project root. This addresses issue #2239.
Note that there is a very slight behavior change. If the executable path specified in the profile is a relative path, it is assumed to be relative to the working directory (whether is comes from msbuild, the profile, or the default). This means that if no working directory is specified, it is now relative to the output directory rather than the project root - which I think makes more sense anyway.