dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

New files are not added to the .csproj #4866

Closed Romaleks360 closed 4 days ago

Romaleks360 commented 3 years ago

Issue Description

New files created in the Explorer panel (either manually or via the C# Extensions "New Class" option) are not included in the current project. IntelliSense works in them, but they belong to OmniSharpMiscellaneousFiles.csproj.

I am using VSCode with Unity. I found two ways to add a new file to the project:

  1. Create a new file, then open the Unity Editor window to trigger scripts recompilation. That can take a lot of time. After the compilation process finishes, IntelliSense is working in the new file as usual.
  2. Create a new file, then manually add its path to Assembly-CSharp.csproj \\\. After that IntelliSense is working in the new file as usual.

I want this process to be done automatically.

Steps to Reproduce

Create a project with Unity, add a new .cs file in the Explorer panel.

Expected Behavior

The new file is added to the project.

Actual Behavior

The file is not included in the current project. OmniSharp Log shows this warning:

[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
        No document found. File: c:\path_to_new_file.cs.

Logs

OmniSharp log

``` OmniSharp server started. Path: c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\OmniSharp.exe PID: 3608 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK [info]: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: StandAlone 17.0.0 - "c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator MSBUILD_EXE_PATH environment variable set to 'c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin\MSBuild.exe' [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: StandAlone 17.0.0 - "c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin" CscToolExe = csc.exe CscToolPath = c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin\Roslyn MSBuildExtensionsPath = c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild MSBuildToolsPath = c:\Users\Jack\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'c:\Projects\Unimate'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'c:\Projects\Unimate\Unimate.sln'. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Projects\Unimate\Assembly-CSharp.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Projects\Unimate'. [info]: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Projects\Unimate' on host 12960. [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Projects\Unimate\Assembly-CSharp.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Projects\Unimate\Assembly-CSharp.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Projects\Unimate\Assembly-CSharp.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: Assembly-CSharp [info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers Solution initialized -> queue all documents for code analysis. Initial document count: 15. Received response for /v2/blockstructure but could not find request. [warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService No document found. File: c:\Projects\Unimate\Assets\Unimate\Core\Operations\CompoundDrawOperation.cs. ```

Environment information

VSCode version: 1.61.2 C# Extension: 1.23.16

Dotnet Information ����� SDK ��� .NET (��ࠦ��騩 �� global.json): Version: 5.0.402 Commit: e9d3381880 �।� �믮������: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.402\ Host (useful for support): Version: 5.0.11 Commit: f431858f8b .NET SDKs installed: 5.0.402 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |cpptools|ms-vscode|1.7.1| |csharp|ms-dotnettools|1.23.16| |csharpextensions|jchannon|1.3.1| |material-icon-theme|PKief|4.10.0| |shader|slevesque|1.1.5| |unity-debug|Unity|3.0.2|;
JoeRobich commented 3 years ago

@Romaleks360 Sorry you are running into issues. The C# extension for VS Code does not have a 'New Class' command. I think this would be an issue for the csharpextensions extension.

Romaleks360 commented 3 years ago

@Romaleks360 Sorry you are running into issues. The C# extension for VS Code does not have a 'New Class' command. I think this would be an issue for the csharpextensions extension.

Hello @JoeRobich! Thank you for your reply. Sure it doesn't, but this is not the point of my issue. The point is when I create a new .cs file inside VSCode (either manually in Explorer or via csharpextensions, doesn't matter), it isn't included in the project and exists in some temp project generated by OmniSharp. I can't reference this class in the project, and I can't reference project entities inside this new class as well. Without csharpextensions the result is the same. Creating a new file inside Visual Studio or Unity results in a new class being added to the project immediately. I can begin referencing other classes of my project inside the new file right after creating it. Unfortunately, this doesn't work in VSCode for me. I have to manually add this new file to the project by editing or regenerating .csproj.

I did my best to describe the problem well. I am ready to add more info if needed.

filipw commented 3 years ago

Doesn't Unity use old-style .NET projects, where each file must be manually added to the compilation in csproj file? OmniSharp doesn't take care of doing that, you need to do it manually.

Romaleks360 commented 3 years ago

Doesn't Unity use old-style .NET projects, where each file must be manually added to the compilation in csproj file? OmniSharp doesn't take care of doing that, you need to do it manually.

You are right. Yet it would be very convenient to automate this process, as Visual Studio does. Doing it manually takes a lot of time, and it's an absolute must-have feature. I basically can't create a new editable file without leaving VSCode, that's weird.

JoeRobich commented 4 days ago

It is now recommended to use the Unity extension for VS Code.