Skip to main content

0020: Static .NET discovery, SDK selection from disk, csharp-ls, TRX results

  • Status: Proposed (implemented in Phase 2, task 013)
  • Date: 2026-12-05

Context​

C# is the second complete slice. Its project system is MSBuild, which runs code (tasks, targets, imported props) whenever it evaluates a project. Its files are XML, which can carry external entities. The SDK in use depends on global.json and its rollForward policy. Microsoft's own C# language server ships inside a proprietary VS Code extension, and its standalone build uses a custom solution-loading protocol. Test results are only structured in log files.

Decision​

  • Static discovery, XML without DTDs. .sln is read as text, .slnx and .csproj with roxmltree and DTDs refused, so no entity is resolved. Targets get kind (executable, library, test), target frameworks and project references. Anything that would need MSBuild evaluation (conditions, $(...), Directory.Build.props) is reported as unresolved.
  • One project per solution folder. It matches the Cargo workspace rule, so the language server is rooted at the solution and documents of all its projects share one server.
  • SDK selection without running dotnet. The SDK folder beside the dotnet host is listed (the same data as dotnet --list-sdks), the nearest global.json is read, and its rollForward policy is applied as documented. The highest netX.Y target framework must be satisfiable by the picked SDK. Provider tasks are refused with guidance when the toolchain is missing.
  • csharp-ls as the C# server. It is MIT, Roslyn-based, installs with dotnet tool install, speaks standard LSP over stdio and loads the solution in its root. Real completion, hover, diagnostics and definition were verified against it.
  • dotnet tasks as typed argv. Build, run, test and restore name only files discovery found, plus --framework for multi-targeted projects. MSBuild's classic logger is forced (MSBUILDTERMINALLOGGER=off) and telemetry is off. Diagnostics come from MSBuild's file(line,col): error CODE: message lines (deduplicated); assemblies from its Name -> path lines.
  • Tests from TRX. dotnet test --logger trx writes into a fresh folder under the system temporary folder. The parser reads at most 64 files of at most 16 MiB each, as XML without DTDs, and then removes the folder.
  • netcoredbg for debug plans. MIT, implements DAP, works with modern .NET on Linux, macOS and Windows. The plan uses an assembly MSBuild reported. The DAP client is task 015.

Alternatives considered​

  • Roslyn's language server (Microsoft.CodeAnalysis.LanguageServer). MIT, and now published on nuget.org as a prerelease per platform. It needs a custom solution/open notification and has no stable standalone release or install path; it can replace csharp-ls later behind the same semantic provider.
  • The C# Dev Kit server. Its licence ties it to Visual Studio Code; not usable.
  • OmniSharp. MIT and mature, but in maintenance mode and heavier to install.
  • dotnet msbuild -getProperty for exact project data. Exact, but it evaluates MSBuild, so it is code execution and needs trust. A trusted, explicit refresh can add it later.
  • Parse dotnet test console output. Formats differ between test frameworks and versions. TRX is structured.

Consequences​

  • New dependencies: tree-sitter-c-sharp (MIT) and roxmltree (MIT or Apache-2.0, already in the tree through fonts).
  • The LSP client now always sends "jsonrpc": "2.0"; csharp-ls refused messages without it, which earlier servers accepted.
  • Facts MSBuild computes (conditional frameworks, output types set in props files) are shown as unresolved rather than known.