OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.73k stars 418 forks source link

v1.25.0 gives CS0103 error for System.Console on .csx file #2405

Open roumcha opened 2 years ago

roumcha commented 2 years ago

Issue Description

When editing a script in a folder which contains omnisharp.json but no project, C# extension v1.25.0 gives CS0103 error for System.Console.

To avoid this, I need create a C# project in the folder.

Is this a bug or expected behavior since v1.25.0?

v1.24.4 2022-05-28

v1.25.0 2022-05-28 (1)

Steps to Reproduce

  1. Create a folder and add omnisharp.json { "script": { "defaultTargetFramework": "net6.0" } } to the folder. (omnisharp.json seems to be needed to avoid a syntax highlighting failure and also avoid CS0518 in a script in a folder with a project)
  2. Open the folder in VSCode.
  3. Create a .csx file and write some code.
  4. System.Console doesn't get suggested or syntax-highlighted but gets underlined in red.
  5. Run dotnet new console in the folder. Reload VSCode.
  6. Error disappears.

Expected Behavior

Writing script files without creating a project.

Actual Behavior

Logs

OmniSharp log

Starting OmniSharp server at 2022/5/28 23:52:03 Target: c:\Users\User\Desktop\test3 OmniSharp server started with .NET 6.0.300 . Path: c:\Users\User\.vscode\extensions\ms-dotnettools.csharp-1.25.0-win32-x64\.omnisharp\1.39.0-net6.0\OmniSharp.dll PID: 19276 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 10.0.22000.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 3 MSBuild instance(s) 1: .NET Core SDK 6.0.300 17.2.0 - "C:\Program Files\dotnet\sdk\6.0.300\" 2: .NET Core SDK 6.0.105 17.0.0 - "C:\Program Files\dotnet\sdk\6.0.105\" 3: .NET Core SDK 6.0.100 17.0.0 - "C:\Program Files\dotnet\sdk\6.0.100\" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: .NET Core SDK 6.0.300 17.2.0 - "C:\Program Files\dotnet\sdk\6.0.300\" [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.MSBuild.ProjectSystem No solution files found in 'c:\Users\User\Desktop\test3' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Users\User\Desktop\test3'. [info]: OmniSharp.Script.ScriptProjectSystem Found 1 CSX files. [info]: OmniSharp.Script.ScriptContextProvider Searching for compilation dependencies with the fallback framework of 'net6.0'. [fail]: OmniSharp.Script.ScriptContextProvider Failed to resolve compilation dependencies [info]: OmniSharp.Script.ScriptContextProvider Unable to find dependency context for CSX files. Will default to non-context usage (Desktop CLR scripts). [info]: OmniSharp.Script.ScriptProjectSystem Added CSX project 'c:\Users\User\Desktop\test3\a.csx' to the workspace. [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Users\User\Desktop\test3' on host 17432. Received response for /v2/getcodeactions but could not find request.

C# log

None

Environment information

VSCode version: 1.67.2 C# Extension: 1.25.0

Dotnet Information .NET SDK (global.json �𔽉f): Version: 6.0.300 Commit: 8473146e7d �����^�C���‹�: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.300\ Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6 .NET SDKs installed: 6.0.100 [C:\Program Files\dotnet\sdk] 6.0.105 [C:\Program Files\dotnet\sdk] 6.0.300 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.5 [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| |---|---|---| |code-runner|formulahendry|0.11.7| |cpptools|ms-vscode|1.9.8| |csharp|ms-dotnettools|1.25.0| |docomment|k--kato|0.1.31| |dotnet-interactive-vscode|ms-dotnettools|1.0.3256010| |gc-excelviewer|GrapeCity|4.2.54| |git-graph|mhutchie|1.30.0| |indent-rainbow|oderwat|8.3.1| |Ionide-fsharp|Ionide|6.0.4| |jupyter|ms-toolsai|2022.4.1021342353| |jupyter-renderers|ms-toolsai|1.0.7| |markdown-all-in-one|yzhang|3.4.3| |markdown-pdf|yzane|1.4.4| |material-icon-theme|PKief|4.17.0| |partial-diff|ryu1kn|1.4.3| |prettier-vscode|esbenp|9.5.0| |python|ms-python|2022.6.2| |r|REditorSupport|2.5.0| |remote-repositories|ms-vscode|0.10.0| |remote-wsl|ms-vscode-remote|0.66.3| |remotehub|GitHub|0.32.0| |vscode-dotnet-runtime|ms-dotnettools|1.5.0| |vscode-drawio|hediet|1.6.4| |vscode-eslint|dbaeumer|2.2.2| |vscode-language-babel|mgmcdermott|0.0.36| |vscode-language-pack-ja|MS-CEINTL|1.67.3| |vscode-markdownlint|DavidAnson|0.47.0| |vscode-pylance|ms-python|2022.5.3| |vscode-regexp-preivew|Lulus|1.0.0| |vscode-yaml|redhat|1.7.0| |xml|DotJoshJohnson|2.5.1|;
JoeRobich commented 2 years ago

@roumcha You really are on the cutting edge if you have a .NET 8 SDK installed. =)

.NET SDKs installed:
8.0.100 [C:\Program Files\dotnet\sdk]

@filipw Should we update the script support to use default references based on which TFM O# was built against?

roumcha commented 2 years ago

@JoeRobich Oops, I will fix it🙃

filipw commented 2 years ago

I will move this to OmniSharp Roslyn. Indeed, it would make sense to use default references based on O# TFM.

filipw commented 2 years ago

@roumcha in your case the problem is your configuration was invalid all along.

the config file should be

{
  "script": {
    "enableScriptNuGetReferences": true,
    "defaultTargetFramework": "net6.0"
  }
}

only with enableScriptNuGetReferences set to true, the defaultTargetFramework setting has any effect. Previously, when you set it "net6.0" only, it was still using the default desktop CLR references from the OmniSharp build.

roumcha commented 2 years ago

@filipw Oh I didn't know that. Thanks for telling me!

CHerSun commented 2 years ago

I have the same problem of CS0103 on Console.WriteLine("Hello, World") for a CSX file.

Using OmniSharp config:

{
  "script": {
    "enableScriptNuGetReferences": true,
    "defaultTargetFramework": "net6.0"
  }
}
yibinlin commented 1 year ago

+1 I have the same problem using the same configuration as @CHerSun

sharpSteff commented 1 year ago

with 1.39.2-net6.0 everything works fine

{
  "script": {
    "enabled": true,
    "enableScriptNuGetReferences": true,
    "defaultTargetFramework": "net6.0"
  }
}