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

extension-points

Was er macht

Dieser Skill erklärt und verfolgt, wie MSBuild Erweiterungspunkte findet, etwa eigene Hooks und Build-Dateien, die NuGet-Pakete mitbringen. Er ist für Build-Ingenieure, die verstehen müssen, warum ein eigener Build-Schritt fehlt oder in der falschen Reihenfolge läuft.

Wann du ihn nutzt

  • ✓Wenn ein eigener Build-Hook oder Import nicht ausgeführt wird.
  • ✓Wenn eine Build-Datei aus einem NuGet-Paket fehlt oder ersetzt zu sein scheint.
  • ✓Wenn du wissen willst, woher eine Build-Anpassung geladen wird.

Link zum Skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/extension-points/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/extension-points/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

“Die Build-Ziele meines NuGet-Pakets laufen in meinem Projekt nicht. Verfolge, wo MSBuild sie lädt und warum.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Agent folgt der Importreihenfolge aus den Standard-Build-Dateien, prüft die Hook-Eigenschaften und den Aufbau des Pakets und erklärt, welche Datei geladen oder übersprungen wird.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von GitHub.

MSBuild Extension Points

How the MSBuild pipeline provides hooks for SDKs, NuGet packages, repos, and users to inject custom logic.

CustomBefore / CustomAfter Hooks

Every major .targets file defines import hooks:

<PropertyGroup>
  <CustomBeforeMicrosoftCommonTargets Condition="'$(CustomBeforeMicrosoftCommonTargets)' == ''">
    $(MSBuildExtensionsPath)\v$(MSBuildToolsVersion)\Custom.Before.Microsoft.Common.targets
  </CustomBeforeMicrosoftCommonTargets>
</PropertyGroup>

<Import Project="$(CustomBeforeMicrosoftCommonTargets)"
    Condition="'$(CustomBeforeMicrosoftCommonTargets)' != '' and Exists('$(CustomBeforeMicrosoftCommonTargets)')"/>
<!-- ... core targets ... -->
<Import Project="$(CustomAfterMicrosoftCommonTargets)"
    Condition="'$(CustomAfterMicrosoftCommonTargets)' != '' and Exists('$(CustomAfterMicrosoftCommonTargets)')"/>

Rules

  • Default path includes version (v$(MSBuildToolsVersion)) for side-by-side installations.
  • Always check Exists(). The file may not be present on every machine.
  • Append to the property (don't overwrite) to chain multiple hooks:
<PropertyGroup>
  <CustomBeforeMicrosoftCommonTargets>
    $(CustomBeforeMicrosoftCommonTargets);$(MSBuildThisFileDirectory)MyExtension.targets
  </CustomBeforeMicrosoftCommonTargets>
</PropertyGroup>

Wildcard Import Directories

MSBuild imports all files in extension directories, sorted alphabetically:

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\*"
    Condition="'$(ImportByWildcardBeforeMicrosoftCommonProps)' == 'true'
               and Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore')" />

Key paths

Property Resolves to Scope
$(MSBuildUserExtensionsPath) %APPDATA%\Microsoft\MSBuild Per-user
$(MSBuildExtensionsPath) MSBuild install directory Machine-wide
$(MSBuildProjectExtensionsPath) obj/ directory Per-project (NuGet)

Name files with numeric prefixes for ordering: 01-first.props, 02-second.props.

Import Gating — Control Properties

Every wildcard import is gated by a boolean property:

<PropertyGroup>
  <ImportByWildcardBeforeMicrosoftCommonProps
      Condition="'$(ImportByWildcardBeforeMicrosoftCommonProps)' == ''">true</ImportByWildcardBeforeMicrosoftCommonProps>
  <ImportDirectoryBuildProps
      Condition="'$(ImportDirectoryBuildProps)' == ''">true</ImportDirectoryBuildProps>
</PropertyGroup>

Available control properties

Property What it disables
ImportDirectoryBuildProps Directory.Build.props auto-discovery
ImportDirectoryBuildTargets Directory.Build.targets auto-discovery
ImportProjectExtensionProps NuGet-generated *.props in obj/
ImportProjectExtensionTargets NuGet-generated *.targets in obj/
ImportByWildcardBefore* Machine-level ImportBefore extensions
ImportByWildcardAfter* Machine-level ImportAfter extensions

NuGet Package Build Extension Layout

NuGet packages inject build logic via build/ or buildTransitive/ folders:

MyPackage/
  build/
    MyPackage.props      ← imported via *.props wildcard
    MyPackage.targets    ← imported via *.targets wildcard
  buildTransitive/
    MyPackage.props      ← imported by transitive consumers
    MyPackage.targets

Rules

  • File names must match the package ID exactly.
  • build/ affects direct consumers only. buildTransitive/ affects the entire dependency chain.
  • Props are imported early (before the project), targets are imported late (after the project).

Forwarding chain: buildTransitive/ → build/ → shared

Forward buildTransitive/*.props and buildTransitive/*.targets through their sibling build/*.props / build/*.targets files (chain buildTransitive → build → shared) instead of importing buildMultiTargeting/ directly. This keeps build/ as the single source of truth with a clear ownership chain, so transitive consumers stay in sync with direct consumers instead of the two layouts drifting apart.

When build/ is packed per-TFM (build/<tfm>/, via TfmSpecificPackageFile, a per-TFM <PackagePath>, or SDK conventions) while buildMultiTargeting/ is not, a buildTransitive/<tfm>/ forwarder must include the TFM segment — dropping it resolves to a non-existent package-root build/MyPackage.props and fails tra

Häufige Fragen

Was ist ein CustomBefore-Hook?

Es ist eine Hook-Datei, die MSBuild vor den eigentlichen Build-Zielen importiert, sodass sie eigene Schritte ergänzen kann.

Deckt es NuGet-Build-Dateien ab?

Ja. Es deckt ab, wie Build-Dateien von Paketen importiert und zugeordnet werden.

Ändert es den Build?

Es erklärt und verfolgt die Importe. Änderungen werden erst nach Prüfung vorgenommen.

Details

Originalbeschreibung des Autors

Own MSBuild import and hook discovery. USE FOR: CustomBefore/CustomAfter hooks, ordered wildcard and NuGet auto-imports, control properties, build/buildTransitive packed layout, package ID and file-name matching, per-TFM forwarders, and tracing why assets or hooks are missing, broken, or replaced. An import guard remains in scope when it is one defect in a broader hook/import flow. DO NOT USE for a focused safety verdict on whether one specific Import needs Exists or is an intentionally unguarded package contract; use msbuild-antipatterns. NEVER INVOKE when imports and hook placement already w

repo: dotnet/skills

Beliebtheit

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

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills