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

global.json is ignored if cwd is out of project or solution directory #28399

Open
gorsheninmv opened this issue Oct 7, 2022 · 7 comments
Open
Assignees
Labels
Area-CLI untriaged Request triage from a team member

Comments

@gorsheninmv
Copy link

Is your feature request related to a problem? Please describe.

Suppose I have a solution and global.json for that. There is a particular sdk version in the global.json. Then I go to the solution directory or any directory inside of the directory and all work fine, dotnet cli detects the global.json file and chooses the correct sdk version.
However, if cwd is not in the directory of solution, the global.json file is ignored, the latest version of sdk is choosen.

Describe the solution you'd like

Search for global.json file relatively csproj or sln file if one of them is set.

Additional context

These feature would be useful in some custom CI\CD pipelies. Otherwise, one has to change cwd to detect global.json correctly.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Oct 7, 2022
@marcpopMSFT
Copy link
Member

Do you have a reason to have a different CWD than the project you're acting on? The global.json lookup was designed as you described. CC @vitek-karas @elinor-fung for the host.

@gorsheninmv
Copy link
Author

In our case we use kind of a custom CI\CD batch of scripts and run dotnet inside of them. It`s convenient to run subprocess like dotnet publish(build) /full/path/to/csproj/file. And I should not forget to change CWD while running the subprocess.

Another reason is msbuild from BuildTools (or Visual Studio) can handle the situation when CWD is out of a solution directory and it would be nice to have the same and more versatile behavior.

@vitek-karas
Copy link
Member

Currently the behavior is by-design. Adding @richlander who was looking into improvements in this area.

@taori
Copy link

taori commented Oct 13, 2023

Also running into this issue.

@olexandrvynnychenko
Copy link

I have a similar issue.

My global.json is NOT in the solution folder, but in the folder of the project inside the solution folder. dotnet watch run works fine if run in the project folder. But global.json is ignored if dotnet watch run --project ProjectFolder/ProjectFile is run in the solution folder.

So it looks like global.json is not really supported when option --project is used.

@baronfel
Copy link
Member

That's because global.json only influences which version of the dotnet CLI and SDK is loaded - once you have loaded a dotnet CLI, that version takes over actually invoking the watch command. There's not really a good way around this behavior.

@vitek-karas
Copy link
Member

My global.json is NOT in the solution folder, but in the folder of the project inside the solution folder.

Additionally, there's no good way today to support solutions with multiple projects where each project has different requirements on the SDK (through different global.json) - building the solution is going to be done with a single instance of the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

7 participants