Skip to content

MSBuild workspace fails to load projects using Central Package Management (CPM) #318

@rcdailey

Description

@rcdailey

Summary

Projects using NuGet Central Package Management (CPM) via Directory.Packages.props fail to load in the Roslyn MSBuild workspace. The solution "loads" but all projects referencing CPM-managed packages report [Failure] diagnostics, resulting in zero code intelligence for affected files.

Environment

  • csharp-ls: 0.22.0
  • .NET SDK: 10.0.102
  • OS: Fedora Linux (x86_64)
  • Solution format: .slnx

Reproduction

Given a solution using CPM with Directory.Packages.props:

<!-- Directory.Packages.props -->
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="System.Reactive.Linq" Version="6.1.0" />
  </ItemGroup>
</Project>
<!-- MyProject.csproj -->
<ItemGroup>
  <PackageReference Include="System.Reactive.Linq" />
</ItemGroup>

This is valid CPM configuration (dotnet build succeeds). However, csharp-ls reports:

msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file
'MyProject.csproj' with message: The following PackageReference items cannot define
a value for Version: System.Reactive.Linq. Projects using Central Package Management
must define a Version value on a PackageVersion item.

And for dependent projects:

msbuildWorkspace.Diagnostics: [Failure] Msbuild failed when processing the file
'DependentProject.csproj' with message: MyProject does not provide an inclusive lower
bound for dependency System.Reactive.Linq. System.Reactive.Linq 3.0.0 was resolved instead.

Impact

All projects in the solution that reference CPM-managed packages (or depend on projects that do) fail to load. The solution appears to finish loading (Finished loading solution), but no diagnostics, symbols, or code intelligence are available for any file in the affected projects.

Steps to reproduce

  1. Create a .NET solution with CPM enabled (Directory.Packages.props with ManagePackageVersionsCentrally)
  2. Add a PackageVersion entry and reference it from a project without a Version attribute
  3. Run csharp-ls --solution MySolution.slnx -l debug
  4. Open a file from the project via textDocument/didOpen
  5. Observe [Failure] diagnostics in the log and no publishDiagnostics for the file

Notes

This may be an issue in the Roslyn MSBuildWorkspace layer rather than csharp-ls itself. dotnet build uses the real MSBuild which handles CPM correctly; the Roslyn workspace loader may use a different code path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions