microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
216 stars 9 forks source link

[Feature Suggestion] Open all .sln files even without csproj in workspace #563

Open dileep-hegde opened 11 months ago

dileep-hegde commented 11 months ago

Describe the Issue

When we create a new solution file using the dotnet CLI and try to open that in VS Code, Solution Explorer is not showing.

A blank solution gives more control and flexibility over project configuration and structure.

Steps To Reproduce

  1. Create a new Solution file using the dotnet CLI Command: dotnet new sln.
  2. Open that in VS Code through link in Explorer Open a folder containing a .NET project or solution.

Expected Behavior

Opening a blank Solution should add Solution Explorer tab.

Also, if we can have an option to create a solution with 'Blank Solution' Template will be helpful.

Environment Information

lifengl commented 11 months ago

This is intentional. The extension is only loaded when there is any .csproj in the workspace, or any .cs file is opened. It is not activated by a single .sln file. Generally, some developers may open a C++ workspace, and do not expect the C# extension to be loaded. In your case, you can still use "Open solution" command to open the blank solution. It will require one more step, but save time for others who do not need it.

dileep-hegde commented 11 months ago

Hi @lifengl

That's true. while it is better to have one more step to open a Solution when we don't have a specific project yet. But, when we first open a folder with a blank solution, then create a project and add it to the solution. Solution Explorer is not showing.

The Solution Explorer is showing only when we have a project before opening the folder.

I think, using "Open solution" command is not the ideal solution for everyone. Moreover, we should know that command exists to use it.

At least, once we add the project to the solution, it should detect the changes and trigger the Solution Explorer.

As the issue is still there. Requesting you to reopen and consider this.

Thank you

dileep-hegde commented 11 months ago

Hi @timheuer,

I'm not sure whether I can tag you here. But, as @lifengl has closed this issue abruptly with no further response. As the issue is still there. I just wanted someone to look into the issue.

Solution Explorer is not showing when we open a blank solution. So he suggested to use "Open solution" command to open it and told this is intended as c# extension should not be loaded for other developers.

But, the issue is when we first open a folder with a blank solution, then create a c# project and add it to the solution. Yet, Solution Explorer doesn't show up.

[My thoughts] At least, once we add the c# project to the solution, it should detect the changes and trigger the Solution Explorer. Or a pop up should come with an option to open it in Solution Explorer.

Requesting to reopen and consider this issue as per my thoughts mentioned above.

timheuer commented 11 months ago

Hi @dileep-hegde -- see below...it does refresh for me.

Steps:

  1. Created an empty directory on my drive (emptysol2)
  2. dotnet new sln (created emptysol2.sln)
  3. Opened that directory in VSCode
  4. Launched command pallette with "Open Solution"
  5. Solution opened in solution explorer
  6. Clicked "+" in solution explorer to add a project, created a project
  7. Solution explorer recognized new project
  8. Went to command line and dotnet new webapi -o webapp in the directory where the emptysol2.sln was
  9. dotnet sln add .\webapp\webapp.csproj
  10. Saw the new web app also in solution explorer in VSCode

2023-09-28_08-41-42

dileep-hegde commented 11 months ago

Hi @timheuer,

Thanks for the quick response.

It only works after using "Open Solution" command atleast once.

But, my concern is that without using the command, if we create a c# project after opening a blank solution doesn't trigger Solution Explorer.

As I already mentioned, everytime having an extra step to open a blank solution doesn't look like a ideal solution for everyone and also the developers would be able to use it only when they are aware of this command.

So, I think, the ideal solution would be to automatically trigger the Solution Explorer, once we add the c# project to the solution Or a pop up should come at the bottom with an option like "open it in Solution Explorer".

So, as I mentioned above if it can automatically do that extra step without expecting the user to be PRO would be the better solution

Thank you for taking your time to listen to my thoughts.

timheuer commented 11 months ago

Got it, thanks @dileep-hegde -- I think what @lifengl points out is that .sln format is not unique to C# so our concern was opening without a context of also csproj may result in attempting to open an sln that has something like vcxproj that we know would always be unsupported...

Will keep this open to reconsider with the team...might be okay to make that assumption.

lifengl commented 11 months ago

yeah, that is a fair scenario to think about, although the .sln file is not essential piece. If we take it out, creating the first .csproj inside a blank workspace would also be a valid scenario. Unless the user is deeply influenced by Visual Studio, creating a solution file provides very little value, until there are at least two projects. Users who work mostly with CLI commands may start with creating a .csproj.

Basically, to reduce overhead of the extension to users who don't need it, the condition to load the C# Dev Kit (there is any .csproj file or user edits a .cs file) is checked by VS Code. Before that, the extension will not be loaded, so it would not be able to add any file watcher. If vs code triggers it to load when a .csproj is created, it would be reasonable to ask the extension to handle it. Otherwise, I think it would be reasonable that the extension is triggered only after user opens a C# code file in VS code, after creating the project. That is when the developer would benefit from the language service, and maybe other features from the solution explorer. I feel this is a part of the nature flow of using VS Code after creating the project with CLI command, and a pop-up before that point is not necessary (and many developers hate pop-ups in the middle of their workflow).

dileep-hegde commented 11 months ago

Hi again, @timheuer and @lifengl. 👋🏻

Thank you for reopening and considering this issue. 👍🏻

Upon further analysis, the following are my findings. Please check this.

Scenario 1 | Working

[!NOTE]

  1. Opening .cs file triggers C# dev kit, then opens solution explorer.
  2. Moreover, if we don't create a .sln file before opening .cs file, it automatically creates a .sln file and add the project as well. But, not as expected, it creates .sln file inside the project folder

Scenario 2 | BUG 🐞

[!IMPORTANT]

  1. As, C# dev kit is getting triggered when we just open a folder with a blank solution in VS Code, I think, both VS Code and C# dev kit is not detecting any further changes.
  2. But why in this scenario, C# dev kit doesn't check changes in real time.

Scenario 3 | BUG 🐞

Case 1: Unknown Behavior

[!WARNING]

  1. Using the folder where previously only C# dev kit detected is tricky.
  2. This behavior might be because we are trying to create a .sln file even before VS Code triggers extensions.

Case 2: Unexpected Behavior

[!IMPORTANT]

  1. Also, if we open an empty folder in VS Code and like in case 1, if we create a .sln file before it triggers extension. It will work the same this time. Because previously both C# dev kit and solution explorer were triggered in this folder.
  2. So, I think, it is something to do with using existing folder and/or same VS Code session or triggering extensions.

I think, it looks good, if everything works the same irrespective of the approach.

Thank you