Zum Inhalt springen

Solution and project formats CodeCharter can analyze

Which solution files, C# projects and shared projects CodeCharter reads, which project types it skips, and how shared files count.

CodeCharter analyzes C# code. It opens your solution or project through MSBuild, the same way your build does, and reads every C# project it finds there. This page lists the formats it reads, how it treats shared projects, and what happens to the other project types a solution may contain.

Solutions

Format What CodeCharter does
.sln Opens the solution and analyzes its C# projects.
.slnx The XML solution format; treated like a .sln.
.slnf A solution filter. Pass it as the path explicitly. CodeCharter works with the filter you named and never switches to a different solution it finds nearby: either it analyzes the projects the filter selects, or it stops with a message naming the filter.
.csproj A single C# project, analyzed on its own.

When you pass a directory, or no path at all, CodeCharter searches it for the shallowest .sln or .slnx and falls back to a .csproj when the directory holds no solution. See codecharter analyze for the exact search order.

C# projects

Every .csproj the solution lists is loaded and analyzed, including test projects. A project that targets several frameworks is analyzed once. Source files a project links from outside its own folder, such as <Compile Include="..\Common\Clock.cs" Link="Clock.cs" />, are part of that project's analysis.

Shared projects (.shproj and .projitems)

A shared project has no build output of its own. Its .projitems file lists source files, and every C# project that imports the .projitems compiles those files as if they were its own. The .shproj file next to it only describes the shared project for Visual Studio.

CodeCharter follows the same model:

  • Files are attributed to the importing projects. A source file of a shared project is analyzed as part of each C# project that imports its .projitems. Code in the shared folder is never lost because the folder has no .csproj of its own.
  • Findings are reported once. When several projects compile the same shared file, a finding at one place in that file is reported once, not once per importing project. Baselines and quality gates count it once as well.
  • The .shproj itself is not loaded. It holds no code. CodeCharter notes in the run's diagnostics that it did not load the shared project; that does not make the run incomplete.

Other project types

CodeCharter reads C# only. Projects of other types that a solution lists are skipped, for example:

  • Visual Basic projects (.vbproj)
  • F# projects (.fsproj)
  • C++ projects (.vcxproj) and C++ shared items (.vcxitems)
  • JavaScript and TypeScript projects (.esproj)
  • SQL Server database projects (.sqlproj)
  • Packaging and deployment projects such as .wapproj or .dcproj

A skipped project costs the analysis nothing it would have read, so the run stays conclusive. A C# project that references such a project through a <ProjectReference> is different: its own code depends on types CodeCharter cannot load, so the run reports the load failure and is inconclusive (exit code 2, see Run context and reach).

Shared files and --affected-by

codecharter coverage --affected-by runs only the test projects a change can reach. For shared files it selects the projects that compile them:

  • A changed source file or .projitems of a shared project selects every C# project that imports that .projitems, and the test projects that reach them.
  • A changed .shproj selects the projects importing the .projitems of the same name next to it.
  • A changed source file that a project links from outside its folder selects that project.
  • A changed file that no project owns and no project imports or links still widens the run to every test project, as does a changed .projitems when an import in the solution cannot be resolved without evaluating MSBuild.

The coverage checks count shared files the same way. A project whose code comes entirely from a shared project counts as a project with code to measure, and a changed shared file that only test projects import needs no coverage data, because test projects are not instrumented. Neither does a changed source that only projects no test project references compile, such as a sample solution's project, since no test project's run measures it. A reference counts whether a project file or a file it imports, such as a Directory.Build.props, declares it, and a source outside the run root, or one an import, item or reference CodeCharter cannot resolve may bring into a tested project, still needs data. See Affected-by: narrowing the test suite for the full rules.

When CodeCharter runs as an MCP server, it also watches the folders outside the solution that hold source files the analysis read, such as a shared project next to the solution folder, so an edit there refreshes the cached analysis.