@cratis/pi 7.101.0 → 7.103.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/harnesses/copilot/instructions/github-actions.instructions.md +17 -0
- package/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +10 -1
- package/package/corpus/harnesses/copilot/instructions/pull-requests.instructions.md +2 -0
- package/package/corpus/harnesses/copilot/instructions/secrets.instructions.md +4 -0
- package/package/corpus/hooks/README.md +11 -1
- package/package/corpus/hooks/scripts/cratis-check-pr.mjs +12 -1
- package/package/corpus/hooks/scripts/cratis-guard-secrets.sh +79 -23
- package/package/corpus/hooks/scripts/cratis-guard-writes.sh +145 -40
- package/package/corpus/rules/github-actions.md +17 -0
- package/package/corpus/rules/profiles.md +10 -1
- package/package/corpus/rules/pull-requests.md +2 -0
- package/package/corpus/rules/secrets.md +4 -0
- package/package/corpus/skills/analyzing-dotnet-performance/LICENSE +23 -0
- package/package/corpus/skills/analyzing-dotnet-performance/NOTICE +36 -0
- package/package/corpus/skills/analyzing-dotnet-performance/SKILL.md +214 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/async-patterns.md +122 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/collections-and-linq.md +220 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/critical-patterns.md +291 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/io-and-serialization.md +135 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/memory-and-strings.md +219 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/regex-patterns.md +95 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/structural-patterns.md +38 -0
- package/package/corpus/skills/binlog-generation/LICENSE +23 -0
- package/package/corpus/skills/binlog-generation/NOTICE +22 -0
- package/package/corpus/skills/binlog-generation/SKILL.md +129 -0
- package/package/corpus/skills/check-bin-obj-clash/LICENSE +23 -0
- package/package/corpus/skills/check-bin-obj-clash/NOTICE +27 -0
- package/package/corpus/skills/check-bin-obj-clash/SKILL.md +127 -0
- package/package/corpus/skills/check-bin-obj-clash/references/common-causes-and-fixes.md +206 -0
- package/package/corpus/skills/coverage-analysis/LICENSE +23 -0
- package/package/corpus/skills/coverage-analysis/NOTICE +32 -0
- package/package/corpus/skills/coverage-analysis/SKILL.md +198 -0
- package/package/corpus/skills/coverage-analysis/references/guidelines.md +68 -0
- package/package/corpus/skills/coverage-analysis/references/output-format.md +91 -0
- package/package/corpus/skills/coverage-analysis/references/report-generation.md +58 -0
- package/package/corpus/skills/coverage-analysis/references/setup-discovery.md +307 -0
- package/package/corpus/skills/coverage-analysis/scripts/Compute-CrapScores.ps1 +80 -0
- package/package/corpus/skills/coverage-analysis/scripts/CoverageData.ps1 +272 -0
- package/package/corpus/skills/coverage-analysis/scripts/Extract-MethodCoverage.ps1 +65 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/LICENSE +2 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/SKILL.md +201 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/build-once-and-shard.md +158 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/caching.md +86 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/flaky-and-hung-jobs.md +70 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/publish-pipelines.md +67 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/required-checks-and-path-filters.md +117 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/runner-sizing-and-images.md +65 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/security-and-pinning.md +73 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/sources.md +33 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/test-setup-cost.md +82 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/ci-timings.sh +356 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/jobs/1003.json +79 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/jobs/1007.json +79 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/jobs/1010.json +79 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/runs.json +102 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/LICENSE +2 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/SKILL.md +244 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/docker-images.md +86 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/dotnet-nuget.md +87 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/go-jvm-python-elixir.md +83 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/npm-yarn.md +78 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/other-environments.md +60 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/worked-examples.md +97 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/scripts/cratis-local-packages.sh +778 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/scripts/npm-restore-check.cjs +109 -0
- package/package/corpus/skills/csharp-refactoring/LICENSE +23 -0
- package/package/corpus/skills/csharp-refactoring/NOTICE +22 -0
- package/package/corpus/skills/csharp-refactoring/SKILL.md +175 -0
- package/package/corpus/skills/csharp-refactoring/references/operation-catalog.md +37 -0
- package/package/corpus/skills/directory-build-organization/LICENSE +23 -0
- package/package/corpus/skills/directory-build-organization/NOTICE +21 -0
- package/package/corpus/skills/directory-build-organization/SKILL.md +205 -0
- package/package/corpus/skills/directory-build-organization/references/common-patterns.md +56 -0
- package/package/corpus/skills/directory-build-organization/references/multi-level-examples.md +167 -0
- package/package/corpus/skills/directory-build-organization/references/targetframework-props-pitfall.md +54 -0
- package/package/corpus/skills/dotnet-aot-compat/LICENSE +23 -0
- package/package/corpus/skills/dotnet-aot-compat/NOTICE +18 -0
- package/package/corpus/skills/dotnet-aot-compat/SKILL.md +265 -0
- package/package/corpus/skills/dotnet-aot-compat/references/polyfills.md +43 -0
- package/package/corpus/skills/dotnet-trace-collect/LICENSE +23 -0
- package/package/corpus/skills/dotnet-trace-collect/NOTICE +65 -0
- package/package/corpus/skills/dotnet-trace-collect/SKILL.md +116 -0
- package/package/corpus/skills/dotnet-trace-collect/references/dotnet-monitor.md +97 -0
- package/package/corpus/skills/dotnet-trace-collect/references/dotnet-trace-collect-linux.md +84 -0
- package/package/corpus/skills/dotnet-trace-collect/references/dotnet-trace-collect.md +91 -0
- package/package/corpus/skills/dotnet-trace-collect/references/perfcollect.md +200 -0
- package/package/corpus/skills/dotnet-trace-collect/references/perfview.md +141 -0
- package/package/corpus/skills/dotnet-trace-collect/references/tool-selection.md +160 -0
- package/package/corpus/skills/dump-collect/LICENSE +23 -0
- package/package/corpus/skills/dump-collect/NOTICE +40 -0
- package/package/corpus/skills/dump-collect/SKILL.md +97 -0
- package/package/corpus/skills/dump-collect/references/container-dumps.md +412 -0
- package/package/corpus/skills/dump-collect/references/coreclr-dumps.md +108 -0
- package/package/corpus/skills/dump-collect/references/nativeaot-dumps.md +280 -0
- package/package/corpus/skills/eliminate-redundant-restores/LICENSE +23 -0
- package/package/corpus/skills/eliminate-redundant-restores/NOTICE +19 -0
- package/package/corpus/skills/eliminate-redundant-restores/SKILL.md +112 -0
- package/package/corpus/skills/extension-points/LICENSE +23 -0
- package/package/corpus/skills/extension-points/NOTICE +18 -0
- package/package/corpus/skills/extension-points/SKILL.md +248 -0
- package/package/corpus/skills/filter-syntax/LICENSE +23 -0
- package/package/corpus/skills/filter-syntax/NOTICE +17 -0
- package/package/corpus/skills/filter-syntax/SKILL.md +179 -0
- package/package/corpus/skills/including-generated-files/LICENSE +23 -0
- package/package/corpus/skills/including-generated-files/NOTICE +17 -0
- package/package/corpus/skills/including-generated-files/SKILL.md +139 -0
- package/package/corpus/skills/microbenchmarking/LICENSE +23 -0
- package/package/corpus/skills/microbenchmarking/NOTICE +36 -0
- package/package/corpus/skills/microbenchmarking/SKILL.md +131 -0
- package/package/corpus/skills/microbenchmarking/references/bdn-internals-and-tuning.md +143 -0
- package/package/corpus/skills/microbenchmarking/references/comparison-strategies.md +200 -0
- package/package/corpus/skills/microbenchmarking/references/diagnosers-and-exporters.md +150 -0
- package/package/corpus/skills/microbenchmarking/references/project-setup-and-running.md +189 -0
- package/package/corpus/skills/microbenchmarking/references/writing-benchmarks.md +310 -0
- package/package/corpus/skills/msbuild/LICENSE +23 -0
- package/package/corpus/skills/msbuild/NOTICE +55 -0
- package/package/corpus/skills/msbuild/SKILL.md +117 -0
- package/package/corpus/skills/msbuild/references/antipatterns/additional-antipatterns.md +291 -0
- package/package/corpus/skills/msbuild/references/antipatterns/incremental-build-inputs-outputs.md +57 -0
- package/package/corpus/skills/msbuild/references/antipatterns/private-assets.md +29 -0
- package/package/corpus/skills/msbuild/references/binlog-failure-analysis.md +85 -0
- package/package/corpus/skills/msbuild/references/binlog-generation.md +69 -0
- package/package/corpus/skills/msbuild/references/build-perf-baseline.md +493 -0
- package/package/corpus/skills/msbuild/references/build-perf-diagnostics.md +268 -0
- package/package/corpus/skills/msbuild/references/copy-to-output-directory.md +183 -0
- package/package/corpus/skills/msbuild/references/eval-performance.md +190 -0
- package/package/corpus/skills/msbuild/references/extension-points.md +281 -0
- package/package/corpus/skills/msbuild/references/incremental-build.md +365 -0
- package/package/corpus/skills/msbuild/references/msbuild-antipatterns.md +401 -0
- package/package/corpus/skills/orleans/LICENSE +21 -0
- package/package/corpus/skills/orleans/NOTICE +64 -0
- package/package/corpus/skills/orleans/SKILL.md +140 -0
- package/package/corpus/skills/orleans/references/anti-patterns.md +660 -0
- package/package/corpus/skills/orleans/references/configuration-api.md +933 -0
- package/package/corpus/skills/orleans/references/examples.md +66 -0
- package/package/corpus/skills/orleans/references/grain-api.md +784 -0
- package/package/corpus/skills/orleans/references/grains.md +75 -0
- package/package/corpus/skills/orleans/references/hosting.md +71 -0
- package/package/corpus/skills/orleans/references/implementation.md +591 -0
- package/package/corpus/skills/orleans/references/official-docs-index.md +250 -0
- package/package/corpus/skills/orleans/references/patterns.md +811 -0
- package/package/corpus/skills/orleans/references/persistence-api.md +495 -0
- package/package/corpus/skills/orleans/references/primitive-selection.md +35 -0
- package/package/corpus/skills/orleans/references/scheduling-and-services.md +295 -0
- package/package/corpus/skills/orleans/references/serialization-api.md +299 -0
- package/package/corpus/skills/orleans/references/streaming-api.md +396 -0
- package/package/corpus/skills/orleans/references/testing-patterns.md +210 -0
- package/package/corpus/skills/platform-detection/LICENSE +23 -0
- package/package/corpus/skills/platform-detection/NOTICE +17 -0
- package/package/corpus/skills/platform-detection/SKILL.md +230 -0
- package/package/corpus/skills/platform-detection/references/command-mode.md +27 -0
- package/package/corpus/skills/profiling/LICENSE +21 -0
- package/package/corpus/skills/profiling/NOTICE +50 -0
- package/package/corpus/skills/profiling/SKILL.md +144 -0
- package/package/corpus/skills/profiling/references/commands.md +439 -0
- package/package/corpus/skills/profiling/references/patterns.md +586 -0
- package/package/corpus/skills/profiling/references/profiling.md +190 -0
- package/package/corpus/skills/run-tests/LICENSE +23 -0
- package/package/corpus/skills/run-tests/NOTICE +19 -0
- package/package/corpus/skills/run-tests/SKILL.md +305 -0
- package/package/corpus/skills/target-authoring/LICENSE +23 -0
- package/package/corpus/skills/target-authoring/NOTICE +17 -0
- package/package/corpus/skills/target-authoring/SKILL.md +165 -0
- package/package/corpus/skills/vectorization/LICENSE +23 -0
- package/package/corpus/skills/vectorization/NOTICE +17 -0
- package/package/corpus/skills/vectorization/SKILL.md +189 -0
- package/package/profile-catalog.json +87 -1
- package/package.json +3 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
// Read-only guard: all validation completes before the shell restores either file.
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const {isDeepStrictEqual: equal} = require('util');
|
|
9
|
+
const [repo, backup] = process.argv.slice(2);
|
|
10
|
+
const read = (base, name) => fs.readFileSync(path.join(base, name), 'utf8');
|
|
11
|
+
const json = (base, name) => JSON.parse(read(base, name));
|
|
12
|
+
const refuse = message => { throw new Error(message); };
|
|
13
|
+
|
|
14
|
+
function overlayResolutions(original, expected) {
|
|
15
|
+
const before = original.resolutions || {};
|
|
16
|
+
const after = expected.resolutions || {};
|
|
17
|
+
return new Map(Object.entries(after).filter(([name, value]) => !equal(value, before[name])));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function checkManifest(original, current, overlay) {
|
|
21
|
+
for (const [name, value] of overlay) {
|
|
22
|
+
const actual = (current.resolutions || {})[name];
|
|
23
|
+
if (actual !== value && !equal(actual, (original.resolutions || {})[name]))
|
|
24
|
+
refuse('Changed overlay resolution: ' + name);
|
|
25
|
+
}
|
|
26
|
+
const withoutOverlay = manifest => {
|
|
27
|
+
const copy = JSON.parse(JSON.stringify(manifest));
|
|
28
|
+
if (copy.resolutions) {
|
|
29
|
+
for (const name of overlay.keys()) delete copy.resolutions[name];
|
|
30
|
+
if (!Object.keys(copy.resolutions).length) delete copy.resolutions;
|
|
31
|
+
}
|
|
32
|
+
return copy;
|
|
33
|
+
};
|
|
34
|
+
if (!equal(withoutOverlay(current), withoutOverlay(original)))
|
|
35
|
+
refuse('Unrelated package.json changes');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Yarn 4 lockfiles have quoted top-level descriptor keys and indented bodies.
|
|
39
|
+
// Preserve bytes for every unaffected block, including metadata and comments;
|
|
40
|
+
// unsupported syntax or install churn is a conflict, not permission to overwrite.
|
|
41
|
+
function lockBlocks(text) {
|
|
42
|
+
const starts = [...text.matchAll(/^[^\s#].*$/gm)];
|
|
43
|
+
const header = text.slice(0, starts.length ? starts[0].index : text.length);
|
|
44
|
+
const blocks = new Map();
|
|
45
|
+
for (let index = 0; index < starts.length; index++) {
|
|
46
|
+
const line = starts[index][0];
|
|
47
|
+
const key = line === '__metadata:' ? '__metadata' : JSON.parse(line.slice(0, -1));
|
|
48
|
+
if (!line.endsWith(':') || typeof key !== 'string' || blocks.has(key))
|
|
49
|
+
refuse('Unsupported or duplicate lockfile key');
|
|
50
|
+
blocks.set(key, text.slice(starts[index].index, starts[index + 1]?.index ?? text.length));
|
|
51
|
+
}
|
|
52
|
+
return {header, blocks};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function descriptorNames(key) {
|
|
56
|
+
return key.split(', ').map(descriptor => {
|
|
57
|
+
const match = descriptor.match(/^(@[^/]+\/[^@]+|[^@]+)@/);
|
|
58
|
+
if (!match) refuse('Unsupported lockfile descriptor: ' + descriptor);
|
|
59
|
+
return match[1];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function localBlock(key, body, overlay) {
|
|
64
|
+
if (key === '__metadata') return false;
|
|
65
|
+
const names = descriptorNames(key);
|
|
66
|
+
const name = names[0];
|
|
67
|
+
if (!overlay.has(name) || names.some(other => other !== name)) return false;
|
|
68
|
+
const match = body.match(/^ resolution: (.+)$/m);
|
|
69
|
+
if (!match) return false;
|
|
70
|
+
const resolution = JSON.parse(match[1]);
|
|
71
|
+
const prefix = name + '@' + overlay.get(name);
|
|
72
|
+
// Yarn may append archive/locator parameters, but not a different filename.
|
|
73
|
+
return [prefix, encodeURI(prefix)].some(value => resolution === value ||
|
|
74
|
+
resolution.startsWith(value + '::') || resolution.startsWith(value + '#'));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function checkLock(original, current, overlay) {
|
|
78
|
+
if (original === current) return;
|
|
79
|
+
const before = lockBlocks(original), after = lockBlocks(current);
|
|
80
|
+
if (before.header !== after.header) refuse('Changed lockfile header');
|
|
81
|
+
const localNames = new Set();
|
|
82
|
+
for (const [key, body] of after.blocks) {
|
|
83
|
+
if (before.blocks.get(key) === body) continue;
|
|
84
|
+
if (!localBlock(key, body, overlay)) refuse('Unrelated lockfile change: ' + key);
|
|
85
|
+
for (const name of descriptorNames(key)) localNames.add(name);
|
|
86
|
+
}
|
|
87
|
+
for (const [key, body] of before.blocks) {
|
|
88
|
+
if (after.blocks.get(key) === body) continue;
|
|
89
|
+
// Only entries for locally replaced package names may change or vanish.
|
|
90
|
+
// Changed entries were already checked against the exact tarball above.
|
|
91
|
+
if (key === '__metadata' ||
|
|
92
|
+
descriptorNames(key).some(name => !localNames.has(name)))
|
|
93
|
+
refuse('Changed or removed unrelated lockfile entry: ' + key);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const original = json(backup, 'package.json');
|
|
99
|
+
const expected = json(backup, 'expected-package.json');
|
|
100
|
+
const overlay = overlayResolutions(original, expected);
|
|
101
|
+
checkManifest(original, json(repo, 'package.json'), overlay);
|
|
102
|
+
const beforeExists = fs.existsSync(path.join(backup, 'yarn.lock'));
|
|
103
|
+
const afterExists = fs.existsSync(path.join(repo, 'yarn.lock'));
|
|
104
|
+
if (beforeExists !== afterExists) refuse('Lockfile created or removed; manual review required');
|
|
105
|
+
if (beforeExists) checkLock(read(backup, 'yarn.lock'), read(repo, 'yarn.lock'), overlay);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('ERROR: ' + error.message);
|
|
108
|
+
process.exitCode = 2;
|
|
109
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) .NET Foundation and Contributors
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
C# Refactoring (behavior-preserving)
|
|
2
|
+
Copyright (c) .NET Foundation and Contributors
|
|
3
|
+
Licensed under the MIT License. See LICENSE.
|
|
4
|
+
|
|
5
|
+
Upstream source: https://github.com/dotnet/skills/blob/a6bf43ab61967c30919334986515163ab24d7635/plugins/dotnet/skills/csharp-refactoring/SKILL.md
|
|
6
|
+
|
|
7
|
+
Changes made by Cratis:
|
|
8
|
+
|
|
9
|
+
LICENSE:
|
|
10
|
+
- Copy upstream MIT license and copyright verbatim.
|
|
11
|
+
|
|
12
|
+
SKILL.md:
|
|
13
|
+
- Normalize frontmatter serialization, add MIT license where absent; preserve name and description.
|
|
14
|
+
- Add marked modification/source comment and applicability/Cratis precedence line.
|
|
15
|
+
- Add the requested Cratis persisted-event, proxy, Orleans identity and framework-public-API contract section.
|
|
16
|
+
- Rewrite the description to the Cratis shape (what it does, Use when, Not for) and drop references to skills that are not part of this corpus.
|
|
17
|
+
- Remove references to the dotnet-upgrade skill; point to the repository's own upgrade workflow.
|
|
18
|
+
|
|
19
|
+
references/operation-catalog.md:
|
|
20
|
+
- Replace the upstream issue reference with a plain statement of the behavior.
|
|
21
|
+
|
|
22
|
+
NOTICE: Add this attribution, change list, and any download/execution disclosure.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: csharp-refactoring
|
|
3
|
+
description: 'Safely refactors C#/.NET code without changing behavior: rename, move, extract, inline, merge, consolidate, deduplicate, split, or modernize, including partial or generated declarations, public APIs, serialization and reflection names, friend assemblies, conditional compilation, and multi-targeted projects. Use when a request asks for a refactor, or calls a feature, bug fix, upgrade, or public nullability change a refactor and the behavior-changing part must be separated or declined. Not for ordinary feature or bug fixes, standalone framework or package upgrades, adding tests, or formatting-only work.'
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- Modified by Cratis from dotnet's original (MIT): frontmatter, applicability, navigation and the changes listed in NOTICE. Upstream: https://github.com/dotnet/skills (plugins/dotnet/skills/csharp-refactoring/SKILL.md; see NOTICE) -->
|
|
8
|
+
|
|
9
|
+
# C# Refactoring (behavior-preserving)
|
|
10
|
+
|
|
11
|
+
Cratis rules in `.cratis/ai/rules/` (including `csharp.md`, `specs.csharp.md`, and `orleans.md`) and the `cratis-*` skills win where they differ.
|
|
12
|
+
|
|
13
|
+
A refactor changes **structure**, never observable **behavior**. Do the edit with binding-aware tools,
|
|
14
|
+
then confirm behavior held with a build + the relevant tests. Keep the effort proportional to the change:
|
|
15
|
+
a one-line local rename does not need the ceremony a public multi-targeted change does.
|
|
16
|
+
|
|
17
|
+
## Mandatory gate: classify before validation or editing
|
|
18
|
+
|
|
19
|
+
Read only enough repository context to classify **each requested operation**. Do this before restoring,
|
|
20
|
+
building, or making an edit. Classification precedence is:
|
|
21
|
+
|
|
22
|
+
- If the request explicitly asks for at least one separable behavior-preserving operation, complete
|
|
23
|
+
that structural work and defer only the behavior-changing or contract-changing operations. Do not
|
|
24
|
+
invent or infer structural work to avoid the stop response.
|
|
25
|
+
- If the structural and behavior-changing parts cannot be separated, use the whole-request stop
|
|
26
|
+
response and state why they are inseparable.
|
|
27
|
+
- Otherwise, use the whole-request stop response only when **every** requested operation is outside
|
|
28
|
+
behavior-preserving refactoring.
|
|
29
|
+
|
|
30
|
+
For a whole request that is outside behavior-preserving refactoring:
|
|
31
|
+
|
|
32
|
+
1. State: `Not a behavior-preserving refactor: <specific reason>.`
|
|
33
|
+
2. State: `No files changed.`
|
|
34
|
+
3. State: `Next workflow: <workflow>.` Then stop. Do not add manual implementation steps, alternatives,
|
|
35
|
+
an offer to proceed without the workflow, or a follow-up question — even when that workflow is unavailable.
|
|
36
|
+
|
|
37
|
+
| Requested as a "refactor" | Classification and action |
|
|
38
|
+
|---|---|
|
|
39
|
+
| Framework or NuGet version change | **Upgrade.** Do not edit or validate the upgrade here; hand off to the repository's upgrade workflow. |
|
|
40
|
+
| New capability, flag, endpoint, tier, or behavior | **Feature.** Do not implement it here; hand off to the repository's feature workflow. |
|
|
41
|
+
| Threshold, rate, output, or bug-result change | **Behavior change.** Defer it and hand off to the repository's bug-fix or behavior-change workflow; still complete any clearly separable structural operation. |
|
|
42
|
+
| Tighten or loosen a shipped/public nullable annotation | **Source-contract change.** Leave the declaration and API record unchanged; hand off to the repository's API-contract workflow. |
|
|
43
|
+
|
|
44
|
+
For a mixed request, never stop after classification. Perform the separable structural operation,
|
|
45
|
+
explicitly defer the behavior/contract change, and never state `No files changed.` after completing
|
|
46
|
+
structural work. Never modify tests to make an unauthorized behavior change appear preserved.
|
|
47
|
+
|
|
48
|
+
## Work only in the current workspace
|
|
49
|
+
|
|
50
|
+
Use the current agent workspace as the boundary. If it is a Git checkout, resolve its repository root
|
|
51
|
+
(`git rev-parse --show-toplevel`) and stay inside it. If Git metadata is absent, treat the current working
|
|
52
|
+
directory and its subdirectories as the boundary, and use a solution or project named in the request
|
|
53
|
+
inside it; Git is not a prerequisite for a refactor. Resolve prompt-provided relative paths inside that
|
|
54
|
+
boundary.
|
|
55
|
+
|
|
56
|
+
Search and edit only that workspace. Never use filesystem-wide search or select a similarly named clone,
|
|
57
|
+
another worktree, build output, or unrelated temporary directory because a file also exists there. If a
|
|
58
|
+
named path is absent, stop and report the mismatch instead of guessing another workspace. If a tool rejects
|
|
59
|
+
an in-workspace path for a mechanical reason such as path form or unsupported tool root, retry through
|
|
60
|
+
another in-workspace mechanism. If the rejection is a permission or policy denial, report it instead of
|
|
61
|
+
working around it. Never search outside the boundary.
|
|
62
|
+
|
|
63
|
+
## Rename / move by bindings, not text
|
|
64
|
+
|
|
65
|
+
The #1 way a "rename" silently corrupts code is editing textual matches (comments, strings, unrelated
|
|
66
|
+
overloads) instead of real **bindings**. Find every binding reference first, then edit semantically. Use
|
|
67
|
+
the strongest tool available: an IDE/Roslyn workspace refactoring, then the C# LSP the
|
|
68
|
+
[`dotnet` plugin declares](https://github.com/dotnet/skills/blob/main/plugins/dotnet/lsp.json)
|
|
69
|
+
(`findReferences`, `goToDefinition`, `incomingCalls`, `rename` code action), then analyzer code-fixes /
|
|
70
|
+
Roslynator, then compiler-validated edits (edit the true bindings, rebuild, let the compiler flag misses).
|
|
71
|
+
Plain find/replace only when scope is provably tiny and every hit is verified. Include **every** `partial`
|
|
72
|
+
declaration, and edit the generator input, never generated (`*.g.cs`) output.
|
|
73
|
+
|
|
74
|
+
For the operation → Roslyn-provider mapping and representative PRs, see
|
|
75
|
+
[references/operation-catalog.md](references/operation-catalog.md).
|
|
76
|
+
|
|
77
|
+
## Consolidate toward the existing source of truth
|
|
78
|
+
|
|
79
|
+
When de-duplicating, preserve the ownership direction stated by the code or request. If `B` duplicates
|
|
80
|
+
an implementation already owned by `A`, keep `A` canonical and make `B` delegate to it; do not invert
|
|
81
|
+
the dependency merely because either direction compiles. Preserve public compatibility wrappers when
|
|
82
|
+
the duplicate surface is shipped, and migrate only in-repo callers that are safe to move.
|
|
83
|
+
|
|
84
|
+
## Decisions that change the edit
|
|
85
|
+
|
|
86
|
+
Use the first matching row instead of applying the requested operation mechanically:
|
|
87
|
+
|
|
88
|
+
| Situation | Do | Never |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| Inline an internal, unshipped pass-through wrapper | Migrate every binding reference to the target, remove the wrapper, then compile to catch misses. | Keep dead indirection "for compatibility" when no compatibility boundary exists. |
|
|
91
|
+
| Inline or remove a shipped/public wrapper | Migrate ordinary in-repo callers, but retain an `[Obsolete]` forwarding entry point unless the request explicitly authorizes a breaking change. | Delete a shipped API merely because all current source callers were migrated. |
|
|
92
|
+
| Rename a member reached by a string, reflection, DI, or configuration | Rename binding-based callers; preserve the observed external name with a forwarding shim or metadata, and exercise the old-name path. | Rewrite an external/configured name just to make the new source name consistent. |
|
|
93
|
+
| Extract duplicated logic whose callers pass different values | Extract the algorithm and pass each caller's existing inputs through unchanged. | Collapse distinct inputs, evaluation order, rounding, or side effects into one caller's version. |
|
|
94
|
+
| Rename code compiled under `#if` or multiple TFMs | Update every source branch and validate each target framework explicitly. | Treat a green default-target build as evidence for unbuilt branches. |
|
|
95
|
+
| Merge near-identical types | Parameterize only the values that differ, migrate every construction site, and preserve each old value exactly. If the old types are internal/unshipped and the request says to merge into one type, delete their declarations. | Retain unnecessary aliases, static holders, factories, or wrapper types that leave the requested merge incomplete; introduce a new hierarchy or behavior. |
|
|
96
|
+
|
|
97
|
+
## Preserve contracts beyond C# call sites
|
|
98
|
+
|
|
99
|
+
Compilation proves binding compatibility, not every external contract. Before renaming or moving a
|
|
100
|
+
type/member, check whether its name or metadata is observed by serialization, reflection, dependency
|
|
101
|
+
injection, configuration binding, source generators, P/Invoke, or `dynamic`.
|
|
102
|
+
|
|
103
|
+
| Boundary | Required decision |
|
|
104
|
+
|---|---|
|
|
105
|
+
| Serialized/configuration name | Preserve the external name with the repository's existing mechanism (for example, `JsonPropertyName`) while migrating C# callers; run a focused round-trip or payload test. |
|
|
106
|
+
| Public nullable annotation | The mandatory classification gate applies: leave it unchanged and hand off as a source-contract change. |
|
|
107
|
+
| Uncovered reflection or runtime lookup | Do not guess that a compile-clean rename is safe. Preserve the observed name or stop and report the unverified runtime boundary. |
|
|
108
|
+
|
|
109
|
+
## Verify proportionally
|
|
110
|
+
|
|
111
|
+
Confirm behavior is preserved after the edit — scaled to blast radius, not a fixed ceremony:
|
|
112
|
+
|
|
113
|
+
- **Local / private** (method-local or `private` member, one file, single target framework, no public
|
|
114
|
+
surface, no `partial`/generated/`#if`): skip a separate baseline unless the tree is already suspect.
|
|
115
|
+
Make the edit, then run the narrowest build and relevant tests once. Let the compiler catch missed
|
|
116
|
+
references.
|
|
117
|
+
- **Cross-boundary** (public/shipped symbol, multi-targeted project, `#if`/platform branches, or
|
|
118
|
+
`partial`/generated code): establish a baseline, then run an explicit build and the relevant tests for
|
|
119
|
+
**each** target framework after the edit (a test command's implicit build is not separate build evidence;
|
|
120
|
+
a green default build can hide a break on another TFM), and run the hazards check below.
|
|
121
|
+
|
|
122
|
+
Use the repo's own build/test workflow when it documents one (`README`/`CONTRIBUTING`, `build.*`, `eng/`,
|
|
123
|
+
`global.json`, `.github/workflows`); its instructions win over any generic command.
|
|
124
|
+
|
|
125
|
+
### Typical workflow (one operation)
|
|
126
|
+
1. Choose one named refactoring operation and keep the step focused on that operation only.
|
|
127
|
+
2. Find true binding references (`findReferences`/`goToDefinition`/rename) and include all `partial` declarations.
|
|
128
|
+
3. Establish a baseline first only for a cross-boundary change or a tree not already known green.
|
|
129
|
+
4. Apply the change via the most semantics-aware tool available; avoid blind find/replace when possible.
|
|
130
|
+
5. Rebuild and run the relevant tests. If the gate goes red, report the failure and repair or reassess only
|
|
131
|
+
your edit; never discard unrelated worktree changes.
|
|
132
|
+
|
|
133
|
+
Otherwise:
|
|
134
|
+
```bash
|
|
135
|
+
dotnet build # 0 errors
|
|
136
|
+
dotnet test # stays green; same pass count as before
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
One operation per step; never mix a refactor and a behavior change in the same step. On red, stop and report the failure; repair only your edit without discarding unrelated worktree changes.
|
|
140
|
+
|
|
141
|
+
## Final response contract
|
|
142
|
+
|
|
143
|
+
Keep the handoff concise and evidence-based:
|
|
144
|
+
|
|
145
|
+
- **Refactor:** name the structural operation and the symbols/files changed.
|
|
146
|
+
- **Preserved:** name the behavior or compatibility boundary and the mechanism that preserved it.
|
|
147
|
+
- **Validation:** report the exact commands and observed result; never claim success after a failed restore,
|
|
148
|
+
build, target framework, or test run.
|
|
149
|
+
- **Deferred:** for a mixed request, name the behavior/contract change intentionally left undone and its
|
|
150
|
+
correct next workflow. Omit this line when nothing was deferred.
|
|
151
|
+
|
|
152
|
+
## Cross-boundary hazards (only when it touches a boundary)
|
|
153
|
+
|
|
154
|
+
If — and only if — the change touches a **public** symbol, a **multi-targeted** project, or
|
|
155
|
+
`partial`/generated code, some breaks won't show up as a failing test. Search the repo for the surface
|
|
156
|
+
that governs the symbol (don't assume): the public-API gate (`PublicAPI.Shipped/Unshipped.txt` for
|
|
157
|
+
PublicApiAnalyzers, and/or `ApiCompat`/`<EnablePackageValidation>` — not interchangeable),
|
|
158
|
+
`<TargetFrameworks>`/`#if` branches, and `InternalsVisibleTo`. Moving a public type to another assembly
|
|
159
|
+
needs `[TypeForwardedTo]` in the original assembly; a move within one assembly does not. A public
|
|
160
|
+
*rename* needs an `[Obsolete]` shim, not a forwarder. For a provably local/private change, skip these
|
|
161
|
+
checks.
|
|
162
|
+
|
|
163
|
+
## Stop an in-scope refactor when
|
|
164
|
+
|
|
165
|
+
- The baseline is already red (you can't prove you preserved behavior).
|
|
166
|
+
- The requested structural change would alter a public/shipped API and no compatibility shim or forwarder
|
|
167
|
+
can preserve it. Report the boundary. Use the gate's handoff format when no structural work was completed;
|
|
168
|
+
after separable work, put the incompatible operation on the `Deferred:` line instead. Do not ask to make
|
|
169
|
+
the breaking change.
|
|
170
|
+
- Equivalence depends on runtime behavior tests don't cover (reflection, DI, serialization, `dynamic`,
|
|
171
|
+
P/Invoke) — report the unverified boundary instead of claiming behavior was preserved.
|
|
172
|
+
|
|
173
|
+
## Contracts the compiler cannot see in Cratis code
|
|
174
|
+
|
|
175
|
+
Preserve `[EventType]` identifiers and type names of persisted events, generated TypeScript proxies of Arc commands/queries, `[Alias]`/serializer ids in Orleans, and public API of framework packages (semver).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# C# refactoring operation catalog (detail)
|
|
2
|
+
|
|
3
|
+
Load this when you need the full operation taxonomy or the Roslyn provider each maps to.
|
|
4
|
+
The core SKILL.md keeps only the short operation list; this file is the depth.
|
|
5
|
+
|
|
6
|
+
## Contents
|
|
7
|
+
|
|
8
|
+
- Operation catalog (provider, recurrence, representative PR)
|
|
9
|
+
- "Modernize" is defined by the repo's analyzer config
|
|
10
|
+
|
|
11
|
+
## Operation catalog
|
|
12
|
+
|
|
13
|
+
Canonical operations, aligned with Roslyn's own IDE refactoring providers
|
|
14
|
+
(`src/Features/CSharp/Portable/CodeRefactorings`). The provider column is informational — a
|
|
15
|
+
headless CLI agent usually cannot invoke these IDE code actions directly, so apply them via the fallback
|
|
16
|
+
ladder in SKILL.md.
|
|
17
|
+
|
|
18
|
+
| Operation | Roslyn provider / tool | Recurrence | Representative real PR |
|
|
19
|
+
|-----------|------------------------|-----------:|------------------------|
|
|
20
|
+
| **Rename** symbol / type / file | rename engine (`Renamer`) | high | _runtime_ "Rename `DISABLE_CROSSGEN`"; _sdk_ "Rename `dnup` to `dotnetup`" |
|
|
21
|
+
| **Move** type / member / file | `MoveType`, `MoveStaticMembers` | high | _runtime_ "Move DSA tests into System.Security.Cryptography"; _sdk_ "Move SDK task unit test projects from src/ to test/" |
|
|
22
|
+
| **Consolidate / de-duplicate** | analyzer-assisted | high | _runtime_ "Consolidate ComWrappers implementation across platforms" |
|
|
23
|
+
| **Modernize / simplify** idioms | `UseExplicitOrImplicitType`, `UseRecursivePatterns`, `ConvertLocalFunctionToMethod`, `AddAwait` | high | _roslyn_ "Simplify lots of redundant code in code fix providers" |
|
|
24
|
+
| **Split** large class / file / assembly | extract + move | medium | _roslyn_ "Split `FeatureSwitchManager`"; _runtime_ "Move RPC contracts to a separate assembly" |
|
|
25
|
+
| **Extract** method / class / interface | `ExtractClass`, extract-method, extract-interface | medium | _runtime_ "Extract `ManifestBuilder` and `EventListener`" |
|
|
26
|
+
| **Inline** method / local / constant | `InlineMethod`, `InlineTemporary` | lower | _runtime_ "Refactor `UInt128` division" |
|
|
27
|
+
| **Pull up / push down** member | `PullMemberUp` | tail | move members between a type and its base/interface |
|
|
28
|
+
| **Sync namespace** to folder | `SyncNamespace` | tail | align `namespace` with folder layout after a move |
|
|
29
|
+
|
|
30
|
+
## "Modernize" is defined by the repo's analyzer config, not personal taste
|
|
31
|
+
|
|
32
|
+
These repos drive idiom rules through `.editorconfig` + `EnforceOnBuild` (which enforces
|
|
33
|
+
code-style analyzers during build). Apply the fixes the repo's own analyzers request
|
|
34
|
+
(IDE00xx / CAxxxx) via `dotnet format` / code-fixes; don't impose a style it hasn't opted into, and don't
|
|
35
|
+
blanket-suppress diagnostics to make an edit "pass." For _adopting_ nullable annotations specifically, see
|
|
36
|
+
the repository's nullable migration workflow; enabling nullable across a project or changing public API
|
|
37
|
+
annotations is a migration or contract change, not a canonical behavior-preserving refactoring operation.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) .NET Foundation and Contributors
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Organizing Build Infrastructure with Directory.Build Files
|
|
2
|
+
Copyright (c) .NET Foundation and Contributors
|
|
3
|
+
Licensed under the MIT License. See LICENSE.
|
|
4
|
+
|
|
5
|
+
Upstream source: https://github.com/dotnet/skills/blob/a6bf43ab61967c30919334986515163ab24d7635/plugins/dotnet-msbuild/skills/directory-build-organization/SKILL.md
|
|
6
|
+
|
|
7
|
+
Changes made by Cratis:
|
|
8
|
+
|
|
9
|
+
LICENSE:
|
|
10
|
+
- Copy upstream MIT license and copyright verbatim.
|
|
11
|
+
|
|
12
|
+
SKILL.md:
|
|
13
|
+
- Lead the description trigger with an explicit "Use when" clause.
|
|
14
|
+
- Normalize frontmatter serialization, add MIT license where absent; preserve name and description.
|
|
15
|
+
- Add marked modification/source comment and applicability/Cratis precedence line.
|
|
16
|
+
- Rewrite the description to the Cratis shape (what it does, Use when, Not for) and drop references to skills that are not part of this corpus.
|
|
17
|
+
|
|
18
|
+
references/multi-level-examples.md:
|
|
19
|
+
- Add or normalize the top Contents list from existing headings; preserve section content.
|
|
20
|
+
|
|
21
|
+
NOTICE: Add this attribution, change list, and any download/execution disclosure.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: directory-build-organization
|
|
3
|
+
description: 'Organizes shared MSBuild policy across Directory.Build.props, Directory.Build.targets, Directory.Build.rsp, and Directory.Packages.props: centralizing repeated properties, targets, and package versions, hierarchy and import structure, props-versus-targets placement, and folder or project exceptions. Use when two or more projects repeat MSBuild policy, or an existing Directory.Build hierarchy has an import, placement, or layering defect, even if only one project is affected. Not for a one-project repo without a Directory.Build file, property value or condition semantics, legacy-to-SDK migration, or non-MSBuild systems.'
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- Modified by Cratis from dotnet's original (MIT): frontmatter, applicability, navigation and the changes listed in NOTICE. Upstream: https://github.com/dotnet/skills (plugins/dotnet-msbuild/skills/directory-build-organization/SKILL.md; see NOTICE) -->
|
|
8
|
+
|
|
9
|
+
# Organizing Build Infrastructure with Directory.Build Files
|
|
10
|
+
|
|
11
|
+
Cratis rules in `.cratis/ai/rules/` (including `csharp.md`, `specs.csharp.md`, and `orleans.md`) and the `cratis-*` skills win where they differ.
|
|
12
|
+
|
|
13
|
+
## Intent control
|
|
14
|
+
|
|
15
|
+
- For "should we", "how should we organize", "recommend", "advise", or review
|
|
16
|
+
requests, inspect the actual project files and return a proposed layout only.
|
|
17
|
+
Do not create or edit files unless the user explicitly asks to apply, move,
|
|
18
|
+
centralize, or clean up the configuration.
|
|
19
|
+
- Before summarizing, verify which project retains each project-specific
|
|
20
|
+
property, item, or target. Name the actual file; do not infer it from sibling
|
|
21
|
+
names.
|
|
22
|
+
- Recommend a verification command only after discovering a real `.sln`,
|
|
23
|
+
`.slnx`, `.proj`, or project file at that path. If no repo-root entry point
|
|
24
|
+
exists, give commands for the discovered projects or state that the entry
|
|
25
|
+
point was not found.
|
|
26
|
+
- Every advice response must explain that `Microsoft.Common.props` searches
|
|
27
|
+
upward from each project and automatically imports the nearest
|
|
28
|
+
`Directory.Build.props` early; project values can then override shared
|
|
29
|
+
defaults. Explain the equivalent late `Microsoft.Common.targets` import when
|
|
30
|
+
recommending `Directory.Build.targets`.
|
|
31
|
+
|
|
32
|
+
## Directory.Build.props vs Directory.Build.targets
|
|
33
|
+
|
|
34
|
+
Understanding which file to use is critical. They differ in **when** they are imported during evaluation:
|
|
35
|
+
|
|
36
|
+
**Evaluation order:**
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Microsoft.Common.props imports Directory.Build.props early
|
|
40
|
+
→ project body and package/project imports evaluate
|
|
41
|
+
→ Microsoft.Common.targets imports Directory.Build.targets late
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Use `.props` for | Use `.targets` for |
|
|
45
|
+
|---|---|
|
|
46
|
+
| Setting property defaults | Custom build targets |
|
|
47
|
+
| Common item definitions | Late-bound property overrides |
|
|
48
|
+
| Properties projects can override | Post-build steps |
|
|
49
|
+
| Assembly/package metadata | Conditional logic on final values |
|
|
50
|
+
| Analyzer PackageReferences | Targets that depend on SDK-defined properties |
|
|
51
|
+
|
|
52
|
+
**Rule of thumb:** Properties and items go in `.props`. Custom targets and late-bound logic go in `.targets`.
|
|
53
|
+
|
|
54
|
+
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.
|
|
55
|
+
|
|
56
|
+
### ⚠️ Critical: TargetFramework Availability in .props vs .targets
|
|
57
|
+
|
|
58
|
+
**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.
|
|
59
|
+
|
|
60
|
+
See [targetframework-props-pitfall.md](references/targetframework-props-pitfall.md) for the full explanation.
|
|
61
|
+
|
|
62
|
+
## Directory.Build.props
|
|
63
|
+
|
|
64
|
+
Good candidates: language settings, assembly/package metadata, build warnings, code analysis, common analyzers.
|
|
65
|
+
|
|
66
|
+
```xml
|
|
67
|
+
<Project>
|
|
68
|
+
<PropertyGroup>
|
|
69
|
+
<Nullable>enable</Nullable>
|
|
70
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
71
|
+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
|
72
|
+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
|
73
|
+
<Company>Contoso</Company>
|
|
74
|
+
<Authors>Contoso Engineering</Authors>
|
|
75
|
+
</PropertyGroup>
|
|
76
|
+
</Project>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**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).
|
|
80
|
+
|
|
81
|
+
## Directory.Build.targets
|
|
82
|
+
|
|
83
|
+
Good candidates: custom build targets, late-bound property overrides (values depending on SDK properties), post-build validation.
|
|
84
|
+
|
|
85
|
+
```xml
|
|
86
|
+
<Project>
|
|
87
|
+
<Target Name="ValidateProjectSettings" BeforeTargets="Build">
|
|
88
|
+
<Error Text="All libraries must target netstandard2.0 or higher"
|
|
89
|
+
Condition="'$(OutputType)' == 'Library' AND '$(TargetFramework)' == 'net472'" />
|
|
90
|
+
</Target>
|
|
91
|
+
|
|
92
|
+
<PropertyGroup>
|
|
93
|
+
<!-- DocumentationFile depends on OutputPath, which is set by the SDK -->
|
|
94
|
+
<DocumentationFile Condition="'$(IsPackable)' == 'true'">$(OutputPath)$(AssemblyName).xml</DocumentationFile>
|
|
95
|
+
</PropertyGroup>
|
|
96
|
+
</Project>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Directory.Packages.props (Central Package Management)
|
|
100
|
+
|
|
101
|
+
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](https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management) for details.
|
|
102
|
+
|
|
103
|
+
**Enable CPM in `Directory.Packages.props` at the repo root:**
|
|
104
|
+
|
|
105
|
+
```xml
|
|
106
|
+
<Project>
|
|
107
|
+
<PropertyGroup>
|
|
108
|
+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
|
109
|
+
</PropertyGroup>
|
|
110
|
+
|
|
111
|
+
<ItemGroup>
|
|
112
|
+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
|
113
|
+
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
|
|
114
|
+
<PackageVersion Include="xunit" Version="2.9.0" />
|
|
115
|
+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
|
|
116
|
+
</ItemGroup>
|
|
117
|
+
|
|
118
|
+
<ItemGroup>
|
|
119
|
+
<!-- GlobalPackageReference applies to ALL projects — great for analyzers -->
|
|
120
|
+
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
|
|
121
|
+
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
|
|
122
|
+
</ItemGroup>
|
|
123
|
+
</Project>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Directory.Build.rsp
|
|
127
|
+
|
|
128
|
+
Contains default MSBuild CLI arguments applied to all builds under the directory tree.
|
|
129
|
+
|
|
130
|
+
**Example `Directory.Build.rsp`:**
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
/maxcpucount
|
|
134
|
+
/nodeReuse:false
|
|
135
|
+
/consoleLoggerParameters:Summary;ForceNoAlign
|
|
136
|
+
/warnAsMessage:MSB3277
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- Works with both `msbuild` and `dotnet` CLI in modern .NET versions
|
|
140
|
+
- Great for enforcing consistent CI and local build flags
|
|
141
|
+
- Each argument goes on its own line
|
|
142
|
+
|
|
143
|
+
## Multi-level Directory.Build Files
|
|
144
|
+
|
|
145
|
+
MSBuild only auto-imports the **first** `Directory.Build.props` (or `.targets`) it finds walking up from the project directory. To chain multiple levels, explicitly import the parent at the **top** of the inner file. See [multi-level-examples](references/multi-level-examples.md) for full file examples.
|
|
146
|
+
|
|
147
|
+
```xml
|
|
148
|
+
<Project>
|
|
149
|
+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"
|
|
150
|
+
Condition="Exists('$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))')" />
|
|
151
|
+
|
|
152
|
+
<!-- Inner-level overrides go here -->
|
|
153
|
+
</Project>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Example layout:**
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
repo/
|
|
160
|
+
Directory.Build.props ← repo-wide (lang version, company info, analyzers)
|
|
161
|
+
Directory.Build.targets ← repo-wide targets
|
|
162
|
+
Directory.Packages.props ← central package versions
|
|
163
|
+
src/
|
|
164
|
+
Directory.Build.props ← src-specific (imports repo-level, sets IsPackable=true)
|
|
165
|
+
test/
|
|
166
|
+
Directory.Build.props ← test-specific (imports repo-level, sets IsPackable=false, adds test packages)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Artifact Output Layout (.NET 8+)
|
|
170
|
+
|
|
171
|
+
Set `<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>` in `Directory.Build.props` to automatically produce project-name-separated `bin/`, `obj/`, and `publish/` directories under a single `artifacts/` folder, avoiding bin/obj clashes by default. See [common-patterns](references/common-patterns.md) for the directory layout and additional patterns (conditional settings by project type, post-pack validation).
|
|
172
|
+
|
|
173
|
+
## Workflow: Organizing Build Infrastructure
|
|
174
|
+
|
|
175
|
+
1. **Audit all `.csproj` files** — Catalog every `<PropertyGroup>`, `<ItemGroup>`, and custom `<Target>` across the solution. Note which settings repeat and which are project-specific.
|
|
176
|
+
2. **Create root `Directory.Build.props`** — Move shared property defaults (LangVersion, Nullable, TreatWarningsAsErrors, metadata) here. These are imported before the project file so projects can override them.
|
|
177
|
+
3. **Create root `Directory.Build.targets`** — Move custom build targets, post-build validation, and any properties that depend on SDK-defined values (e.g., `OutputPath`, `TargetFramework` for single-targeting projects) here. These are imported after the SDK so all properties are available.
|
|
178
|
+
4. **Create `Directory.Packages.props`** — Enable Central Package Management (`ManagePackageVersionsCentrally`), list all `PackageVersion` entries, and remove `Version=` from `PackageReference` items in `.csproj` files.
|
|
179
|
+
5. **Set up multi-level hierarchy** — Create inner `Directory.Build.props` files for `src/` and `test/` folders with distinct settings. Use `GetPathOfFileAbove` to chain to the parent.
|
|
180
|
+
6. **Simplify `.csproj` files** — Remove all centralized properties, version attributes, and duplicated targets. Each project should only contain what is unique to it.
|
|
181
|
+
7. **Validate** — Run restore/build against the discovered `.sln`, `.slnx`,
|
|
182
|
+
`.proj`, or project path, for example
|
|
183
|
+
`dotnet restore <entrypoint> && dotnet build <entrypoint>`. If no root
|
|
184
|
+
entrypoint exists, validate each discovered project explicitly instead of
|
|
185
|
+
claiming a repo-root build. Use
|
|
186
|
+
`dotnet msbuild <project> -pp:output.xml` to inspect the final merged view.
|
|
187
|
+
|
|
188
|
+
## Troubleshooting
|
|
189
|
+
|
|
190
|
+
| Problem | Cause | Fix |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| `Directory.Build.props` isn't picked up | File name casing wrong (exact match required on Linux/macOS) | Verify exact casing: `Directory.Build.props` (capital D, B) |
|
|
193
|
+
| Properties from `.props` are ignored by projects | Project sets the same property after the import | Move the property to `Directory.Build.targets` to set it after the project |
|
|
194
|
+
| Multi-level import doesn't work | Missing `GetPathOfFileAbove` import in inner file | Add the `<Import>` element at the top of the inner file (see Multi-level section) |
|
|
195
|
+
| Properties using SDK values are empty in `.props` | SDK properties aren't defined yet during `.props` evaluation | Move to `.targets` which is imported after the SDK |
|
|
196
|
+
| `Directory.Packages.props` not found | File not at repo root or not named exactly | Must be named `Directory.Packages.props` and at or above the project directory |
|
|
197
|
+
| Property condition on `$(TargetFramework)` doesn't match in `.props` | `TargetFramework` isn't set yet for single-targeting projects during `.props` evaluation | Move property to `.targets`, or use ItemGroup/Target conditions instead (which evaluate late) |
|
|
198
|
+
|
|
199
|
+
**Diagnosis:** Use the preprocessed project output to see all imports and final property values:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
dotnet msbuild -pp:output.xml MyProject.csproj
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
This expands all imports inline so you can see exactly where each property is set and what the final evaluated value is.
|