-
Notifications
You must be signed in to change notification settings - Fork 386
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
Default working directory inconsistent between dotnet run and Visual Studio #3619
Comments
Any temporary work around for this issue? Can we use a fixed path for the database file? I am facing this issue on mac |
@girishnuli : As we found out in dotnet/EntityFramework.Docs#735, you could change the working directory of the project ( |
@BillHiebert I was under the (incorrect) impression that with #2239 we were changing the current directory to be consistent inside and outside of Visual Studio, while at same time being consistent with .NET Framework projects. It looks like however, that while we changed it change it to be consistent with desktop inside of Visual Studio, it now inconsistent with itself outside of Visual Studio. Sounds like we need to change this design slightly. At minimum we should consistent with ourselves in all cases, and stretch goal is to be consistent with desktop. @dsplaisted Do you have an opinion on this? |
I don't want to change this in an update - it will lead to confusion. I'd prefer to do this in a major update. |
I think that when running I don't have all the cases in my head, but I think we should probably undo the change made in #3073, at least for some subset of projects (SDK-style perhaps). That means it would be inconsistent with desktop projects, but mostly consistent within .NET Core projects between VS and the command line. |
Direct support for making the working directory the same as the project root would be a decent compromise. If you want this behavior after the #3073 "fix", VS requires you to set an absolute path, which means the setting cannot be checked in to source code control. The current behavior of #3073 also means VS is the odd-ball on a mix-IDE team: dotnet-cli, VS Code, and JetBrains Rider all behave like "dotnet run" from the project root. |
Any plans on this? This also makes it rather tricky to use dynamic loading (like |
@vitek-karas We do plan on addressing this, on your particular issue, you should not be relying on "Current Directory" to find dlls, or other things related to your project; anyone can launch your exe with a different working directory. |
I found a workaround from https://github.com/aspnet/websdk/issues/238:
|
The current working directory is absolutely essential on unix, maybe not that used on windows.
and
should not expose different behavior (the CWD should be the same ( This is the universal convention respected by all good citizens in the unix world (python, ruby, go, ...). And if the C# parser would just ignore the first line of a file if it starts by a But first, make |
Triage: We need investigation on what the correct change here is, as its unclear. Please factor in #5053 when you do this. |
Just got hit by this issue too. |
@akeeton Nice, it is working for me, thanks! but it is some kind of bug at Visual Studio? |
Any updates on this? I just got hit by this issue also, and the |
This seems to have been closed without a resolution? |
The issue is still open :) |
@akeeton's solution solved my issue, which was that |
lets wait for the outcome of #5053 |
@davkean wrote:
FWIW, I hit this issue using System.CommandLine to bind a
I made no explicit decision about using current directory or otherwise - I assumed initializing with a relative path would behave the same regardless of how I start the app. |
(first reported at dotnet/EntityFramework.Docs#735)
It seems that there was a decision in #2239 to change the current directory to be the output directory.
I am not sure about the rationale or what the behavior was before, but what I am seeing is that (using .NET Core SDK 2.1.300, .NET Core 2.1 and Visual Studio 2017 15.7.3), the default working directory is inconsistent between executing an application in Visual Studio (using F5 or Ctrl+F5), which results in the working directory set to the output directory, and other ways, which use the project folder, like dotnet run, dotnet ef migrations commands in the CLI and even the EF Core migration tools that run in the Package Manager Console inside Visual Studio.
I am aware that it is possible to explicitly set the working directory to an absolute path using Visual Studio and that this is recorded in launch settings, which other tools pick up. This issue is about the default behavior when the working directory is not explicitly configured.
To repro, it is enough to just create a simple application that prints Directory.GetCurrentDirectory().
Here are the repro steps that shows how this impacts the location of an application's SQLite database file (based on the walkthrough at https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite):
Create a new console app from the command line:
Add the following EF Core packages:
(the latter is only necessary to repro the inconsistency with PMC)
Add the following sample model into Model.cs:
Add the following code into Program.cs:
Execute the following commands to create the database:
Note that the database was created in the project directory.
Executing the application from the command line results in this output.
Now try to execute the application from Visual Studio (F5 or Ctrl+F5). The output shows an exception indicating that the table doesn't exist. That is because opening a connection with a database file that doesn't exist creates an empty database file:
Now, let's try to update the database using the EF Core PMC commands. First, drop the database from the OS command-line to make sure we will observe the default behavior of the PMC commands:
C:\Users\myself\source\repos\ConsoleApp.SQLite>dotnet ef database drop --force
Switch to the Package Manager Console inside Visual Studio, type:
PM> update-database -verbose
You will see that one of the last lines indicates:
Closing connection to database 'main' on server 'C:\Users\myself\source\repos\ConsoleApp.SQLite\blogging.db'.
cc @bricelam
The text was updated successfully, but these errors were encountered: