Skip to content

project segment: show TargetFramework from .csproj when working in solution folder containing only .sln #7399

@AcGrube

Description

@AcGrube

Code of Conduct

  • I agree to follow this project's Code of Conduct

What would you like to see changed?

Context

The project segment correctly detects .sln files and shows the .NET icon, but does not
display any version information when working in a solution folder where only a .sln file
is present (no .csproj directly in the folder).

This is the standard workflow for .NET developers: the .sln file lives at the repo root,
while individual .csproj files live in subdirectories. Git operations (git status,
git push, etc.) are always performed from the solution folder, not from individual
project folders.

Current behavior

Given this folder structure:

MyApp/
  MyApp.sln          ← working directory
  src/
    MyApp.Api/
      MyApp.Api.csproj  (TargetFramework: net8.0)
    MyApp.Domain/
      MyApp.Domain.csproj

When in MyApp/, the project segment shows the .NET icon but no version.

Expected behavior

The segment should resolve the TargetFramework of the startup/first project in the
solution and display it.

Proposed implementation

When the current directory contains a .sln file but no .csproj directly, the segment
should search one level deeper (non-recursively to avoid performance impact) for .csproj
files and read the TargetFramework element from the first match.

Alternatively, a new property search_subdirectories (boolean, default false) could
opt in to this behavior explicitly, giving users control over performance vs. information
tradeoff.

Reference

This is related to the closed issue #1568 ("Enhance dotnet segment to support .Net
framework") and the associated discussion #1564. Those issues addressed .NET Framework
vs. .NET Core detection; this issue specifically addresses the solution folder workflow
where no .csproj is directly present.

oh-my-posh version: 26.25.0
OS: Windows 11
Shell: PowerShell 7.5.4
Terminal: Windows Terminal

Configuration

{
  "type": "project",
  "style": "powerline",
  "foreground": "#1E1E2E",
  "background": "#89B4FA",
  "powerline_symbol": "\uE0B0",
  "template": " {{ if .Error }}{{ else }}\uDB82\uDEAE {{ if .Target }}{{ .Target }}{{ else }}{{ .Version }}{{ end }} {{ end }}",
  "properties": {
    "always_enabled": false
  }
}

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions