dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 667 forks source link

Source Generator exception (DotNetJS) only on Mac #5390

Closed promontis closed 1 year ago

promontis commented 1 year ago

Issue Description

I'm trying to use the sample project of DotNetJS (https://github.com/Elringus/DotNetJS). This project generates an interop between c# and js, using a source generator. When I run dotnet publish (which triggers the source generator) in VS Code on a Mac, I get the following exception:

CSC : warning CS8032: An instance of analyzer Generator.SourceGenerator cannot be created from /Users/michel/.nuget/packages/dotnetjs/0.15.1/analyzers/dotnet/cs/Generator.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [/Users/michel/Dev/stylister-garden-cra/libs/Solver/Stylister.Solver.csproj]

Note, that it does work on Windows!

Is it not possible to use source generators in VS Code on a Mac?

Steps to Reproduce

On a Mac (Windows works)... Clone https://github.com/Elringus/DotNetJS Open repo using VS Code Open Terminal in VS Code Cd to Samples/HelloWorld/Project Run dotnet publish

Expected Behavior

To not get an exception, and the source generator is running.

Actual Behavior

Exception.

Logs

OmniSharp log

Starting OmniSharp server at 9/30/2022, 11:20:05 PM Target: /Users/michel/Dev/stylister-garden-cra

OmniSharp server started with .NET 6.0.202 . Path: /Users/michel/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 80684

    Starting OmniSharp on Unknown 0.0 (Unknown)
    Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
    Using the 'dotnet' on the PATH.
    DotNetPath set to dotnet
    Located 2 MSBuild instance(s)
        1: .NET Core SDK 6.0.202 17.1.1 - "/usr/local/share/dotnet/sdk/6.0.202/"
        2: .NET Core SDK 6.0.201 17.1.0 - "/usr/local/share/dotnet/sdk/6.0.201/"
    Registered MSBuild instance: .NET Core SDK 6.0.202 17.1.1 - "/usr/local/share/dotnet/sdk/6.0.202/"
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    No solution files found in '/Users/michel/Dev/stylister-garden-cra'
    Queue project update for '/Users/michel/Dev/stylister-garden-cra/libs/Solver/Stylister.Solver.csproj'
    Queue project update for '/Users/michel/Dev/stylister-garden-cra/libs/Solver.Test/Stylister.Solver.Test.csproj'
    Detecting CSX files in '/Users/michel/Dev/stylister-garden-cra'.
    Did not find any CSX files
    Configuration finished.
    Omnisharp server running using Stdio at location '/Users/michel/Dev/stylister-garden-cra' on host 80611.
    Loading project: /Users/michel/Dev/stylister-garden-cra/libs/Solver/Stylister.Solver.csproj
    Successfully loaded project file '/Users/michel/Dev/stylister-garden-cra/libs/Solver/Stylister.Solver.csproj'.
    Adding project '/Users/michel/Dev/stylister-garden-cra/libs/Solver/Stylister.Solver.csproj'
    Loading project: /Users/michel/Dev/stylister-garden-cra/libs/Solver.Test/Stylister.Solver.Test.csproj
    Successfully loaded project file '/Users/michel/Dev/stylister-garden-cra/libs/Solver.Test/Stylister.Solver.Test.csproj'.
    Adding project '/Users/michel/Dev/stylister-garden-cra/libs/Solver.Test/Stylister.Solver.Test.csproj'
    Update project: Stylister.Solver
    Update project: Stylister.Solver.Test

Environment information

VSCode version: 1.71.2 C# Extension: 1.25.0

Mono Information OmniSharp using mono :6.12.0
Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.202 Commit: f8a55617d2 Runtime Environment: OS Name: Mac OS X OS Version: 12.0 OS Platform: Darwin RID: osx.12-arm64 Base Path: /usr/local/share/dotnet/sdk/6.0.202/ Host (useful for support): Version: 6.0.4 Commit: be98e88c76 .NET SDKs installed: 6.0.201 [/usr/local/share/dotnet/sdk] 6.0.202 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |add-reference|adrianwilczynski|1.0.2| |Antlrvsix-vscode|KenDomino|1.2.0| |csharp|ms-dotnettools|1.25.0| |csharpier-vscode|csharpier|1.3.5| |dotnet|formulahendry|0.0.4| |dotnet-test-explorer|formulahendry|0.7.8| |EditorConfig|EditorConfig|0.16.4| |nugetpackagemanagergui|aliasadidev|2.0.4| |prettier-vscode|esbenp|9.9.0| |vscode-eslint|dbaeumer|2.2.6| |vscode-graphql|GraphQL|0.7.5| |vscode-graphql-syntax|GraphQL|1.0.4| |vscode-jest-runner|firsttris|0.4.57| |vscode-nuget-gallery|patcx|0.0.24| |vscode-nuget-package-manager|jmrog|1.1.6| |vscode-sort-json|richie5um2|1.20.0| |vscode-tailwindcss|bradlc|0.8.7| |vscode-xml|redhat|0.21.2022062916|;
JoeRobich commented 1 year ago

@promontis In this case you require a newer .NET 6 SDK. From the OmniSharp output I see you are using the 6.0.2xx SDKs which align with VS 17.1. The source generator is trying to load Roslyn 4.2 dependencies which align with VS 17.2.

promontis commented 1 year ago

Latest SDK solved it!! Thnx!!!