dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 670 forks source link

Project does not contain 'Compile' target if there's an empty TFM #5786

Open kemsky opened 1 year ago

kemsky commented 1 year ago

CSharp: Report an issue - finds nothing.

I'm using pre-release version: v2.0.206 on Ubuntu 22.04, VSCode installed from official apt repository. which dotnet and dotnet --list-sdks work from code terminal.

Environment data

dotnet --info output: .NET SDK: Version: 7.0.100 Commit: e12b7af219

Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: ubuntu.22.04-x64 Base Path: /home/xxx/.dotnet/sdk/7.0.100/

Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4

.NET SDKs installed: 3.1.422 [/home/xxx/.dotnet/sdk] 6.0.400 [/home/xxx/.dotnet/sdk] 7.0.100 [/home/xxx/.dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.28 [/home/xxx/.dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.8 [/home/xxx/.dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [/home/xxx/.dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.28 [/home/xxx/.dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.8 [/home/xxx/.dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [/home/xxx/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found: None

Environment variables: DOTNET_ROOT [/home/xxx/.dotnet]

global.json file: Not found VS Code version: 1.79.0 C# Extension version: v2.0.206

OmniSharp log

Dotnet path: /home/xxx/.config/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.5/dotnet Activating C# standalone... info: LanguageServerHost[0] Starting server... [Info - 12:27:06 AM] [LanguageServerProjectSystem]Loaded MSBuild at /home/xxx/.dotnet/sdk/7.0.100 [Info - 12:27:06 AM] [LanguageServerProjectSystem]Loading /home/xxx/Documents/projects/xxx/xxx.sln... [Warn - 12:27:12 AM] [LanguageServerProjectSystem]Failure while loading /home/xxx/Documents/projects/xxx/xxx.Web/xxx.Web.csproj: Project does not contain 'Compile' target. [Info - 12:27:12 AM] [LanguageServerProjectSystem]Completed (re)load of all projects in 00:00:06.5244896

Steps to reproduce

I don't know, new version just does not work no matter what.

jasonmalinowski commented 1 year ago

@kemsky The xxx.Web.csproj project that is giving you an error, what type of web project is that?

kemsky commented 1 year ago

@jasonmalinowski, web project has Microsoft.NET.Sdk.Web, actually I cut output, there are other projects in solution but none of them loads, error message is exactly the same, all other projects are Microsoft.NET.Sdk. Is there any way to enable more detailed error reporting?

kemsky commented 1 year ago

@jasonmalinowski, ok, I understood what happens. I have Directory.Build.props where I set <TargetFrameworks>net7.0;</TargetFrameworks>, project files do not have such item. If I add <TargetFramework>net7.0</TargetFramework> directly to each project - it works.

jasonmalinowski commented 1 year ago

@kemsky And did you have the DevKit extension installed, or are using just the C# extension by itself?

kemsky commented 1 year ago

@jasonmalinowski, I tried with and without DevKit, the problem is caused by redundant ; in <TargetFrameworks>net7.0;</TargetFrameworks>

jasonmalinowski commented 1 year ago

There's another bug which means we're taking this code path that's reporting the error even if DevKit is installed, so I guess that question of mine might have not been the best. Other than the error, with either DevKit installed or not, do you still see other features like colorization or Intellisense working?

kemsky commented 1 year ago

@jasonmalinowski, colorization and Intellisense are working in both cases.

There is a different bug (go to definition does not work correctly when type is imported from other project, it navigates to decompiled code instead of source code), it is present only when DevKit is installed.

jasonmalinowski commented 1 year ago

Yep, that other one is known and is tracked as https://github.com/microsoft/vscode-dotnettools/issues/40. Based on your descriptions I think the error is going to be harmless in your case. Was the extra semicolon intentional or just some leftover from a prior change?

kemsky commented 1 year ago

@jasonmalinowski, there is initial delay before intellisense starts working plus unrelated bug https://github.com/microsoft/vscode-dotnettools/issues/40 so I decided that this error was critical as it usually happens with project load errors.

Was the extra semicolon intentional or just some leftover from a prior change?

Previously we had net6.0 target, so there was a list. Visual studio, rider and ci/cd can build and load this solution without any issues.

jasonmalinowski commented 1 year ago

Yep, I just wanted to verify you weren't expecting some other behavior here before we add a "skip blank TFMs" check in our code to silence this.

jasonmalinowski commented 1 year ago

@kemsky And just as an FYI, we shipped verison 2.0.212 of the C# extension earlier today which won't fix the error you're reporting in this bug, but will fix the go to definition issues you were seeing too. So I'd recommend you upgrade if you haven't already.

Zaitonn commented 9 months ago

the same problem appears when net6.0 and net6.0-windows are added into TargetFrameworks at the same time

Error csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net6.0-windows;net6.0;</TargetFrameworks>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup Condition="'$(TargetFramework)'=='net6.0-windows'">
        <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
        <PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
        <PackageReference Include="SystemInfoLibrary-devel" Version="1.5.0.25" />
    </ItemGroup>

</Project>

output:

[Info  - 23:21:22] [LanguageServerProjectSystem] Completed (re)load of all projects in 00:00:02.3964907
[Info  - 23:21:37] [LanguageServerProjectSystem] Successfully completed load of c:\GitHub\Serein2\Serein.Core\Serein.Core.csproj
[Info  - 23:21:37] [LanguageServerProjectSystem] Completed (re)load of all projects in 00:00:02.1641771
[Error - 23:21:52] [LanguageServerProjectSystem] Failure while loading c:\GitHub\Serein2\Serein.Core\Serein.Core.csproj: Project does not contain 'Compile' target.
[Info  - 23:21:52] [LanguageServerProjectSystem] Completed (re)load of all projects in 00:00:02.7280420

but if i remove <TargetFrameworks>net6.0-windows;net6.0;</TargetFrameworks> and add <TargetFramework>net6.0</TargetFramework> , the error disappears