Zum Inhalt springen
Skillpedia
Deployment & Cloud (DevOps)5.8k · #14597

directory-build-organization

Was er macht

Dieser Skill führt dazu, gemeinsame Build-Einstellungen, Ziele und Paketversionen in geteilten Directory.Build-Dateien abzulegen, damit Projekte sie nicht wiederholen. Er ist für Teams mit mehreren .NET-Projekten, die dieselbe Einrichtung wiederholen.

Wann du ihn nutzt

  • ✓Wenn mehrere .NET-Projekte dieselben Build-Einstellungen oder Paketversionen wiederholen.
  • ✓Wenn du gemeinsame Build-Richtlinien über eine Solution zentralisieren willst.
  • ✓Wenn eine bestehende Directory.Build-Einrichtung ein Import- oder Schichtungsproblem hat.

Link zum Skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/directory-build-organization/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/directory-build-organization/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Meine Solution hat zehn Projekte mit denselben Build-Einstellungen, die in jedes kopiert wurden. Verschiebe die gemeinsamen Einstellungen an eine Stelle.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Agent prüft, wo jede projektspezifische Einstellung liegt, schlägt einen Aufbau mit Directory.Build.props- und Targets-Dateien vor und erklärt, welche Einstellungen in welche Datei gehören.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von GitHub.

Organizing Build Infrastructure with Directory.Build Files

Intent control

  • For "should we", "how should we organize", "recommend", "advise", or review requests, inspect the actual project files and return a proposed layout only. Do not create or edit files unless the user explicitly asks to apply, move, centralize, or clean up the configuration.
  • Before summarizing, verify which project retains each project-specific property, item, or target. Name the actual file; do not infer it from sibling names.
  • Recommend a verification command only after discovering a real .sln, .slnx, .proj, or project file at that path. If no repo-root entry point exists, give commands for the discovered projects or state that the entry point was not found.
  • Every advice response must explain that Microsoft.Common.props searches upward from each project and automatically imports the nearest Directory.Build.props early; project values can then override shared defaults. Explain the equivalent late Microsoft.Common.targets import when recommending Directory.Build.targets.

Directory.Build.props vs Directory.Build.targets

Understanding which file to use is critical. They differ in when they are imported during evaluation:

Evaluation order:

Microsoft.Common.props imports Directory.Build.props early
→ project body and package/project imports evaluate
→ Microsoft.Common.targets imports Directory.Build.targets late
Use .props for Use .targets for
Setting property defaults Custom build targets
Common item definitions Late-bound property overrides
Properties projects can override Post-build steps
Assembly/package metadata Conditional logic on final values
Analyzer PackageReferences Targets that depend on SDK-defined properties

Rule of thumb: Properties and items go in .props. Custom targets and late-bound logic go in .targets.

Because .props is imported before the project file, the project can override any value set there. Because .targets is imported after everything, it gets the final say—but projects cannot override .targets values.

⚠️ Critical: TargetFramework Availability in .props vs .targets

Property conditions on $(TargetFramework) in .props files silently fail for single-targeting projects — the property is empty during .props evaluation. Move TFM-conditional properties to .targets instead. ItemGroup and Target conditions are not affected.

See targetframework-props-pitfall.md for the full explanation.

Directory.Build.props

Good candidates: language settings, assembly/package metadata, build warnings, code analysis, common analyzers.

<Project>
  <PropertyGroup>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <Company>Contoso</Company>
    <Authors>Contoso Engineering</Authors>
  </PropertyGroup>
</Project>

Do NOT put here: project-specific TFMs, project-specific PackageReferences, targets/build logic, or properties depending on SDK-defined values (not available during .props evaluation).

Directory.Build.targets

Good candidates: custom build targets, late-bound property overrides (values depending on SDK properties), post-build validation.

<Project>
  <Target Name="ValidateProjectSettings" BeforeTargets="Build">
    <Error Text="All libraries must target netstandard2.0 or higher"
           Condition="'$(OutputType)' == 'Library' AND '$(TargetFramework)' == 'net472'" />
  </Target>

  <PropertyGroup>
    <!-- DocumentationFile depends on OutputPath, which is set by the SDK -->
    <DocumentationFile Condition="'$(IsPackable)' == 'true'">$(OutputPath)$(AssemblyName).xml</DocumentationFile>
  </PropertyGroup>
</Project>

Directory.Packages.props (Central Package Management)

Central Package Management (CPM) provides a single source of truth for all NuGet package versions. See https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management for details.

Enable CPM in Directory.Packages.props at the repo root:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>

  <ItemGroup
Häufige Fragen

Props oder Targets?

Props-Dateien werden früh importiert und können von Projekten überschrieben werden, Targets-Dateien werden spät importiert.

Ändert es Dateien ohne Nachfrage?

Bei Beratungsanfragen schlägt es nur einen Aufbau vor und ändert Dateien erst, wenn du die Änderung anwenden lässt.

Deckt es zentrale Paketversionen ab?

Ja. Es deckt das Zentralisieren von Paketversionen in einer gemeinsamen Datei ab.

Details

Originalbeschreibung des Autors

USE ONLY for (1) two or more projects with repeated MSBuild policy, targets, or package versions, or (2) an existing Directory.Build.props/targets/rsp hierarchy with an import, placement, or layering defect. A one-project repo without an existing Directory.Build file is outside scope; do not load this skill. Covers centralizing shared policy and targets, Directory.Packages.props across projects, parent hierarchy/import structure, props-versus-targets placement, and folder/project exceptions. An existing hierarchy defect remains in scope when only one project is affected. For property value or

repo: dotnet/skills

Beliebtheit

GitHub-Sterne
5.8k
Platz im Ranking
#14597
Lizenz
MIT
Aktualisiert
2.11.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills