Datei: Concepts/BuildProcess.md
Last Commit (74c26c3)
| 1 | # NDO Build Process – Concept for Independent Package Versioning |
| 2 | |
| 3 | ## 1. Context |
| 4 | |
| 5 | NDO ships as a set of NuGet packages. Other projects inside and outside this |
| 6 | repository consume them. A complete build is currently described by the MSBuild |
| 7 | script `Make/NDO.proj`. The resulting packages land in `BuiltPackages`. |
| 8 | |
| 9 | The packages evolve independently. When one package changes: |
| 10 | |
| 11 | 1. It needs a new version. That means `Version`, `AssemblyVersion` and `FileVersion` in its csproj. |
| 12 | 2. Every project that depends on it must reference the new version. |
| 13 | 3. Every dependent *package* must get a new version of its own. |
| 14 | 4. Steps 2 and 3 repeat for the dependents' dependents. |
| 15 | |
| 16 | The current tool, `Tools/PatchNdoVersion`, can't do this. It assumes one version |
| 17 | for all packages NDO. dll depends on ( `-i`, `-n`, `-m`, `-e` switches) . It also |
| 18 | only patches `PackageReference` versions; it never touches the package's own version. |
| 19 | |
| 20 | ## 2. Current State |
| 21 | |
| 22 | ### 2. 1 Packages produced by the build |
| 23 | |
| 24 | | Package id | Project | Version | Assembly/FileVersion | |
| 25 | |---|---|---|---| |
| 26 | | NDOInterfaces | `NDOInterfaces/NDOInterfaces.csproj` | 6.0.0 | 6.0.0.0 | |
| 27 | | NDO.Mapping | `NDO.Mapping/NDO.Mapping/NDO.Mapping.csproj` | 6.0.0 | **6.0.0** (3 parts) | |
| 28 | | NDO.ProviderFactory | `NDO.ProviderFactory/NDO.ProviderFactory/NDO.ProviderFactory.csproj` | 6.0.0 | 6.0.0.0 | |
| 29 | | NDO.SchemaGenerator | `NDO.SchemaGenerator/NDO.SchemaGenerator/NDO.SchemaGenerator.csproj` | 6.0.0 | 6.0.0.0 | |
| 30 | | NDO.dll | `NDODLL/NDO.csproj` | 6.0.0 | 6.0.0.0 | |
| 31 | | NDO.JsonFormatter | `NdoJsonFormatter/NdoJsonFormatter/NDO.JsonFormatter.csproj` | 5.1.1 | 5.1.1.0 | |
| 32 | | ndo.mysql, ndo.mysqlconnector, ndo.oracle, ndo.postgre, ndo.sqlite, ndo.sqlserver | `Provider/*/NDO.*/NDO.*.csproj` | 5.1.0 | 5.1.0.0 | |
| 33 | | NDO. Build | `nuget/NDO. Build. nuspec` ( packed with `nuget. exe`) | 6. 0. 1. 0 | – | |
| 34 | |
| 35 | Notes: |
| 36 | - **Versions are scattered. ** There is no `Directory. Build. props` or |
| 37 | ··`Directory.Packages.props`. Every version is hard-coded in its project file. |
| 38 | - **NDO.Build and NDOEnhancer are coupled.** NDO.Build packages the binaries of |
| 39 | ··`NDOEnhancer/NDOEnhancer` (Version 6.0.1.0) and `NDOEnhancer.BuildTask`. The |
| 40 | NDOEnhancer version should equal the NDO. Build version. |
| 41 | |
| 42 | ### 2. 2 How dependencies are expressed |
| 43 | |
| 44 | There are two different mechanisms. |
| 45 | |
| 46 | **ProjectReference (inside the core).** These references form the core graph: |
| 47 | |
| 48 | ``` |
| 49 | NDOInterfaces |
| 50 | ├── NDO.Mapping ── NDO.SchemaGenerator ─┐ |
| 51 | ├── NDO.ProviderFactory ────────────────┤ |
| 52 | ├───────────────────────────────────────┴── NDO.dll |
| 53 | ├── ndo.<provider> (6x) |
| 54 | └── NDOEnhancer ( also Mapping, ProviderFactory, SchemaGenerator, Ecma335) |
| 55 | ``` |
| 56 | |
| 57 | `dotnet pack` turns a ProjectReference into a package dependency `>= <Version of |
| 58 | the referenced project>`. So **no reference needs to be edited** here. The |
| 59 | dependent package only needs its own version bump, because its nuspec now |
| 60 | points to a different dependency version. |
| 61 | |
| 62 | **PackageReference ( outside the core) . ** |
| 63 | |
| 64 | | Consumer | References | |
| 65 | |---|---| |
| 66 | | NDO.JsonFormatter | `ndo.dll` 5.1.1 | |
| 67 | | SimpleMappingTool (`Mapping.csproj`) | `NDO.mapping` 5.1.1 | |
| 68 | | Provider UISupport projects (5x) | `NDOInterfaces` 5.1.0 | |
| 69 | | IntegrationTests | `NDO.JsonFormatter` 5.1.0 | |
| 70 | | PureBusinessClasses | `ndo.dll` 5.1.1 | |
| 71 | | FormatterUnitTests | `ndo.dll` 5.1.1, `ndo.sqlserver` 5.1.0 | |
| 72 | | PersistentEnhancerTestClasses | `ndo.dll` 5.0.0 | |
| 73 | | UnitTestGenerator/* | `NDO.dll`, `NDO.Build`, `NDO.SqlServer`, `NDO.Mapping`, `NDO.ProviderFactory`, `NDOInterfaces` 5.0.0 | |
| 74 | |
| 75 | Package ids are spelled with inconsistent casing ( `ndo. dll`, `NDO. dll`, |
| 76 | `NDO. mapping`) , so all matching must be case-insensitive. |
| 77 | |
| 78 | ### 2. 3 Problems with the current build |
| 79 | |
| 80 | - **The patch step is broken. ** `Make/NDO. proj` calls `PatchNdoVersion -i` on |
| 81 | NDO. Mapping, NDO. ProviderFactory, the providers and NDOEnhancer. These projects |
| 82 | no longer have an `NDOInterfaces` PackageReference, so these steps fail. |
| 83 | - **PatchNdoVersion is limited:** |
| 84 | - it only searches the first `ItemGroup` that contains a `PackageReference`; |
| 85 | - it reformats the file through `XDocument. Save`; |
| 86 | - it can't bump a project's own version. |
| 87 | - **Copying to `BuiltPackages` is Windows-only and incomplete. ** It is done by |
| 88 | per-project `PostBuild` targets using `cmd copy`. The providers and |
| 89 | NDO. JsonFormatter don't copy at all, and NDO. dll copies no `. snupkg`. |
| 90 | - **Some projects can't be built with `dotnet build`:** |
| 91 | ··- `NDOPackage` is a VSIX project and needs the VSSDK targets of Visual Studio's MSBuild. |
| 92 | ··- `NDOEnhancer.BuildTask` is an old-style project with GAC references to |
| 93 | ····`Microsoft.Build.Utilities.v4.0`. |
| 94 | ··- `UISupport/NDO.UISupport` is old-style, and its HintPath points to a |
| 95 | ····`netstandard2.0` folder that no longer exists. |
| 96 | - **The NuGet package source points to the wrong drive.** The user-level source |
| 97 | ··named `NDO` is `C:\Projekte\NDO\BuiltPackages`, but the repository lives on `D:`. |
| 98 | ··The repository has no `nuget.config` of its own. |
| 99 | - **`Make/DebugBuild.cmd` is broken.** It references a `test.proj` and a |
| 100 | ··`nuget.config` that don't exist. |
| 101 | |
| 102 | ## 3. Requirements |
| 103 | |
| 104 | 1. **One place to enter versions.** The developer enters the new version of a |
| 105 | ·· package in one single file. |
| 106 | 2. **Producer patching.** The script sets `Version`, `AssemblyVersion` and |
| 107 | ·· `FileVersion` in that package's csproj, or the version in its nuspec. |
| 108 | 3. **Consumer patching. ** Every `PackageReference` to a changed package is |
| 109 | updated in all csproj files. |
| 110 | 4. **Propagation.** Every package that depends on a changed package, directly |
| 111 | ·· or transitively, automatically gets a new version. Then steps 2 and 3 apply |
| 112 | ·· to it as well. |
| 113 | 5. **Building. ** Compilation uses `dotnet build <csproj>`, in dependency order. |
| 114 | 6. **Collection.** All resulting `.nupkg` / `.snupkg` files end up in `BuiltPackages`. |
| 115 | |
| 116 | ## 4. Choice of Tool |
| 117 | |
| 118 | ### 4.1 Is MSBuild the right tool? |
| 119 | |
| 120 | **No, not for orchestration.** MSBuild is a declarative item/target engine. It |
| 121 | is excellent for describing *how to build one project*. It is a poor fit for |
| 122 | what this script must do: |
| 123 | |
| 124 | - **Graph logic.** The script must read all project files, build a dependency |
| 125 | ··graph, compute a transitive closure and sort it topologically. In MSBuild |
| 126 | ··this means inline tasks or a custom task assembly, which is effectively C# |
| 127 | ··anyway, just harder to debug. |
| 128 | - **Conditional state changes.** Rules like "bump the patch version of X only if |
| 129 | X itself was not bumped manually" lead to deeply nested conditions and |
| 130 | ··property functions. |
| 131 | - **Editing XML in place.** `XmlPoke` rewrites the file and can't easily target |
| 132 | ··attributes on specific items without reformatting. |
| 133 | - **Diagnostics.** It's hard to produce a readable dry-run report. |
| 134 | |
| 135 | MSBuild stays the right tool *inside* each csproj: pack settings, copying, |
| 136 | enhancer integration. It should no longer be the orchestrator. |
| 137 | |
| 138 | ### 4.2 Alternatives |
| 139 | |
| 140 | | Option | Pros | Cons | |
| 141 | |---|---|---| |
| 142 | | **MSBuild orchestration file** ( status quo) | Already present; no new runtime | Weak at graph and conditional logic; painful XML patching; hard to debug | |
| 143 | | **PowerShell 7 script** | Ubiquitous on Windows; good XML support via `[xml]`; easy process calls | Different language from the rest of the code base; no typed version handling; `[xml]` also reformats unless handled carefully; PS 5. 1 vs. 7 differences | |
| 144 | | **C# file-based app** ( `dotnet run build. cs`, . NET 10+) | Same language as NDO and the existing tools; `XDocument`, `NuGet. Versioning`, `System. Text. Json` available; no `. csproj` needed ( `#:package` directives) ; debuggable in VS/VS Code; cross-platform | Requires the . NET 10 SDK ( already required by the net10. 0/net11. 0 targets) | |
| 145 | | **Cake / NUKE** | Mature build DSLs in C#; built-in tasks for `dotnet build/pack`, NuGet, MSBuild via vswhere | Extra dependency and learning curve; NUKE adds a build project and bootstrap scripts; heavyweight for one repository | |
| 146 | | **Central Package Management** ( `Directory. Packages. props`) | All `PackageReference` versions in one file; consumer patching becomes a single-file edit | Only covers consumers, not the producers' own versions or propagation. It **complements** a script and doesn't replace it | |
| 147 | |
| 148 | ### 4. 3 Recommendation |
| 149 | |
| 150 | Use a **C# file-based app**: `Make/build. cs`, run with `dotnet run Make/build. cs`. |
| 151 | It is the smallest step that covers every requirement: |
| 152 | |
| 153 | - It is the same language as the code base and the existing tools |
| 154 | ( PatchNdoVersion, MakeEnhancerDate, AddMappingToVsix) , which it can replace. |
| 155 | - It has typed version handling through `NuGet. Versioning`. |
| 156 | - It needs no build project or bootstrapper. A single file is executed directly |
| 157 | by the SDK. |
| 158 | - It is easy to provide a `--dry-run` mode with a clear report. |
| 159 | |
| 160 | Optional second step: introduce `Directory. Packages. props` for the |
| 161 | *PackageReference* versions of NDO packages. Then the script only has to update |
| 162 | that one file for the consumers. |
| 163 | |
| 164 | ## 5. Recommended Design |
| 165 | |
| 166 | ### 5.1 Version manifest – the single source of truth |
| 167 | |
| 168 | `Make/packages. json` lists every package that the build produces. It is the |
| 169 | **only** file the developer edits to release a new version. |
| 170 | |
| 171 | ```json |
| 172 | { |
| 173 | ··"packageSource": "../BuiltPackages", |
| 174 | ··"configuration": "Release", |
| 175 | ··"propagation": "patch", |
| 176 | ··"packages": [ |
| 177 | { "id": "NDOInterfaces", "project": "NDOInterfaces/NDOInterfaces. csproj", "version": "6. 0. 0" } , |
| 178 | { "id": "NDO. Mapping", "project": "NDO. Mapping/NDO. Mapping/NDO. Mapping. csproj", "version": "6. 0. 0" } , |
| 179 | { "id": "NDO. ProviderFactory", "project": "NDO. ProviderFactory/NDO. ProviderFactory/NDO. ProviderFactory. csproj", "version": "6. 0. 0" } , |
| 180 | { "id": "NDO. SchemaGenerator", "project": "NDO. SchemaGenerator/NDO. SchemaGenerator/NDO. SchemaGenerator. csproj", "version": "6. 0. 0" } , |
| 181 | ····{ "id": "NDO.dll",············ "project": "NDODLL/NDO.csproj",·················································· "version": "6.0.0" }, |
| 182 | ····{ "id": "NDO.JsonFormatter",·· "project": "NdoJsonFormatter/NdoJsonFormatter/NDO.JsonFormatter.csproj",··········"version": "5.1.1" }, |
| 183 | ····{ "id": "ndo.sqlserver",······ "project": "Provider/SqlServerProvider/NDO.SqlServer/NDO.SqlServer.csproj",······ "version": "5.1.0" }, |
| 184 | ····{ "id": "NDO.Build",·········· "project": "nuget/NDO.Build.nuspec", "builder": "nuget", |
| 185 | ······"versionFollowers": [ "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj" ], |
| 186 | "buildFirst": [ "NDOEnhancer/NDOEnhancer/NDOEnhancer. csproj", |
| 187 | { "project": "NDOEnhancer. BuildTask/NDOEnhancer. BuildTask/NDOEnhancer. BuildTask. csproj", "builder": "msbuild" } ], |
| 188 | "version": "6. 0. 1" } |
| 189 | ··] |
| 190 | } |
| 191 | ``` |
| 192 | |
| 193 | The other providers are listed in the same way. Dependencies are **not** listed |
| 194 | in the manifest. They are derived from the project files, so they can never get |
| 195 | out of sync with the real references. |
| 196 | |
| 197 | `versionFollowers` names projects that get the same version but are not packed |
| 198 | themselves, like NDOEnhancer. |
| 199 | |
| 200 | ### 5.2 Dependency graph |
| 201 | |
| 202 | The script scans every `*. csproj` under the repository root and builds the graph: |
| 203 | |
| 204 | - It skips `bin/`, `obj/`, `packages/` and an exclude list of legacy folders |
| 205 | such as `Tutorial`, `UnitTests` and `ClassGenerator`. These still use NDO 1. x–4. x |
| 206 | GAC or HintPath references. |
| 207 | - A **producer** is a project listed in the manifest. |
| 208 | - An **edge** `A → B` ( "B depends on A") is created when: |
| 209 | - project B contains `<PackageReference Include="A">`, matched case-insensitively |
| 210 | against the manifest ids; or |
| 211 | - project B contains a `<ProjectReference>` whose resolved full path is the |
| 212 | producer project of A. |
| 213 | - **Consumers** are all projects with an edge, whether or not they are packages |
| 214 | ··themselves. Tests and tools are consumers but not producers. |
| 215 | |
| 216 | The graph is checked for cycles and sorted topologically. |
| 217 | |
| 218 | ### 5.3 Algorithm |
| 219 | |
| 220 | ``` |
| 221 | 1. Load manifest; load graph ( 5. 2) . |
| 222 | |
| 223 | 2. Detect changes |
| 224 | changed = { p | manifest. version( p) != version in p's project file } |
| 225 | |
| 226 | 3. Propagate |
| 227 | ·· for p in topological order: |
| 228 | if p not in changed and any dependency of p is in changed: |
| 229 | p. version = bump( current version of p, policy) // e. g. 5. 1. 0 -> 5. 1. 1 |
| 230 | changed += p |
| 231 | Write the propagated versions back into packages. json |
| 232 | ·· (so the manifest is again the single source of truth). |
| 233 | |
| 234 | 4. Patch producers ( for each p in changed) |
| 235 | ·· csproj:··<Version>x.y.z</Version> |
| 236 | ············<AssemblyVersion>x.y.z.0</AssemblyVersion> |
| 237 | ············<FileVersion>x.y.z.0</FileVersion> |
| 238 | ·· nuspec:··<version>x.y.z</version> |
| 239 | ·· versionFollowers: same three properties. |
| 240 | |
| 241 | 5. Patch consumers ( for each project in the repository) |
| 242 | for each <PackageReference Include=id Version=v> with id in changed: |
| 243 | set Version to the new version |
| 244 | ·· ProjectReferences are left untouched (the version flows in at pack time). |
| 245 | |
| 246 | 6. Print a report ( always) – stop here with --dry-run or --no-build. |
| 247 | |
| 248 | 7. Build changed packages in topological order ( see 5. 4) . |
| 249 | |
| 250 | 8. Collect *. nupkg / *. snupkg into packageSource. |
| 251 | ``` |
| 252 | |
| 253 | Rules for patching: |
| 254 | - **Keep formatting. ** Edit the text in place with a regex limited to the found |
| 255 | element, or use `XDocument` with `LoadOptions. PreserveWhitespace` and save |
| 256 | without reformatting and with the original encoding/BOM. The diff of a project |
| 257 | file must show only the changed version lines. |
| 258 | - **Normalize version formats. ** Assembly and file versions always use 4 parts. |
| 259 | This also fixes the 3-part format in NDO. Mapping. |
| 260 | - **Patch every occurrence. ** If a property or reference appears in several |
| 261 | ··conditional `PropertyGroup`s or `ItemGroup`s, all occurrences are patched. |
| 262 | - **Report unknown references.** If a reference uses a version range or a |
| 263 | ··property (`Version="$(...)"`), the script reports it instead of guessing. |
| 264 | |
| 265 | ### 5.4 Building |
| 266 | |
| 267 | Each changed package is built as follows, in topological order: |
| 268 | |
| 269 | ``` |
| 270 | dotnet build <csproj> -c Release |
| 271 | ``` |
| 272 | |
| 273 | `GeneratePackageOnBuild=true` is already set in all package projects, so |
| 274 | `dotnet build` also produces the `. nupkg` / `. snupkg`. Consumers that are not |
| 275 | packages, like tests, are only patched and not built. An optional `--all` switch |
| 276 | builds them too. |
| 277 | |
| 278 | **Restore. ** `dotnet build` restores implicitly. The packages that the |
| 279 | consumers need must be in a configured package source before their restore. |
| 280 | That works because the topological order guarantees producers are built and |
| 281 | collected first. |
| 282 | |
| 283 | **NuGet cache. ** If a package is rebuilt *without* a version change, the stale |
| 284 | copy in `~/. nuget/packages/<id>/<version>` must be deleted first. Otherwise |
| 285 | consumers keep restoring the old content. This replaces the `DeletePackages` |
| 286 | target of `NDO. proj`. |
| 287 | |
| 288 | **Collecting packages. ** The script copies `bin/<Configuration>/<id>. <version>. nupkg` |
| 289 | and `. snupkg` to `BuiltPackages`. The alternative is to set `PackageOutputPath` |
| 290 | centrally in a `Directory. Build. props`. Either way, the `cmd copy` `PostBuild` |
| 291 | targets can be removed from the project files. |
| 292 | |
| 293 | **Exceptions that can't use `dotnet build`:** |
| 294 | |
| 295 | | Project | Reason | Handling | |
| 296 | |---|---|---| |
| 297 | | `NDOPackage/NDOPackage. csproj` ( VSIX) | Needs the VSSDK targets of Visual Studio | Build with Visual Studio's `MSBuild. exe`, found via `vswhere -latest -find MSBuild\**\Bin\MSBuild. exe`. Not part of the package build; only built with `--vsix` | |
| 298 | | `NDOEnhancer. BuildTask` | Old-style project, GAC references to Microsoft. Build | Short term: MSBuild via vswhere ( `"builder": "msbuild"`) . Long term: convert it to an SDK-style project using `Microsoft. Build. Utilities. Core`, then use `dotnet build` | |
| 299 | | `NDO. Build` ( nuspec) | Not a project | First build NDOEnhancer and NDOEnhancer. BuildTask ( `buildFirst`) , then run `nuget/NuGet. exe pack NDO. Build. nuspec -Version <version> -OutputDirectory <packageSource>`. Long term: a pack-only SDK project ( `NoBuild`, `IncludeBuildOutput=false`) so that `dotnet pack` is enough | |
| 300 | | Tools ( `MakeEnhancerDate`, `AddMappingToVsix`) | Prerequisites of NDOEnhancer and NDOPackage | Built with `dotnet build -c Release` before the first project that needs them | |
| 301 | |
| 302 | ### 5. 5 Command line |
| 303 | |
| 304 | ``` |
| 305 | dotnet run Make/build.cs [options] |
| 306 | |
| 307 | --dry-run Show detected changes, propagated bumps and all file |
| 308 | edits; change nothing. |
| 309 | --no-build Patch versions and references only. |
| 310 | --only <id> Build only this package ( and nothing that depends on it) . |
| 311 | --rebuild <id> Rebuild a package without a version change |
| 312 | ( clears its NuGet cache entry) . |
| 313 | --all Also build consumers that are not packages ( tests, tools) . |
| 314 | --bump patch|minor Propagation policy for dependent packages ( default: patch) . |
| 315 | -c <config> Configuration ( default: Release) . |
| 316 | ``` |
| 317 | |
| 318 | Example session: |
| 319 | |
| 320 | ``` |
| 321 | > # edit Make/packages.json: NDOInterfaces 6.0.0 -> 6.0.1 |
| 322 | > dotnet run Make/build.cs --dry-run |
| 323 | Changed ( manual) : NDOInterfaces 6. 0. 0 -> 6. 0. 1 |
| 324 | Changed ( propagated) : NDO. Mapping 6. 0. 0 -> 6. 0. 1 |
| 325 | NDO. ProviderFactory 6. 0. 0 -> 6. 0. 1 |
| 326 | NDO. SchemaGenerator 6. 0. 0 -> 6. 0. 1 |
| 327 | NDO. dll 6. 0. 0 -> 6. 0. 1 |
| 328 | ndo. sqlserver 5. 1. 0 -> 5. 1. 1 ( … other providers) |
| 329 | NDO. JsonFormatter 5. 1. 1 -> 5. 1. 2 |
| 330 | Reference updates: SimpleMappingTool/Mapping. csproj NDO. mapping 5. 1. 1 -> 6. 0. 1 |
| 331 | Provider/. . . /SqlServerUISupport. csproj NDOInterfaces 5. 1. 0 -> 6. 0. 1 |
| 332 | ······················ … |
| 333 | Build order: NDOInterfaces, NDO. Mapping, NDO. ProviderFactory, … |
| 334 | > dotnet run Make/build. cs |
| 335 | ``` |
| 336 | |
| 337 | ### 5. 6 Propagation policy |
| 338 | |
| 339 | By default a dependent package gets a **patch** bump. If the developer has |
| 340 | already raised a dependent's version in the manifest, for example to a new |
| 341 | minor version for an API change, that manual version wins and the package is |
| 342 | not bumped again. |
| 343 | |
| 344 | Note: with ProjectReferences, the dependency in the produced nuspec is a |
| 345 | *minimum* version ( `>= x`) . Bumping the dependent is still necessary. It |
| 346 | guarantees that the published dependent package is a new artifact that points |
| 347 | to the new dependency, and that old consumers don't receive a changed package |
| 348 | under an unchanged version. |
| 349 | |
| 350 | ## 6. Migration Steps |
| 351 | |
| 352 | 1. **Create the manifest. ** Write `Make/packages. json` from the current project |
| 353 | versions ( table 2. 1) . |
| 354 | 2. **Implement the script. ** Write `Make/build. cs` with `--dry-run` first, and |
| 355 | verify the report against the current repository. A first run without manual |
| 356 | changes must report "nothing changed". |
| 357 | 3. **Unify version formats. ** Use 4-part Assembly/FileVersion everywhere; this |
| 358 | is done automatically on the first patch. |
| 359 | 4. **Replace the copy targets.** Remove the `cmd copy` `PostBuild` targets, or |
| 360 | ·· replace them with a central `PackageOutputPath`. |
| 361 | 5. **Add a `nuget.config`** at the repository root with `BuiltPackages` as a |
| 362 | relative package source. This removes the dependency on the user-level |
| 363 | source ( currently pointing to `C:\Projekte\NDO\BuiltPackages`) . |
| 364 | 6. **Retire the old patch step. ** Remove the `PatchNdoVersion` target and the |
| 365 | ·· tool from `Make/NDO.proj`. Then keep `NDO.proj` only as a thin wrapper for |
| 366 | ·· the VSIX build, or delete it. |
| 367 | 7. **Clean up legacy scripts.** Delete or fix `Make/DebugBuild.cmd`. |
| 368 | 8. **Optional: Central Package Management.** Introduce `Directory.Packages.props` |
| 369 | ·· for the NDO package versions used by consumers. |
| 370 | 9. **Optional: modernize the remaining legacy projects. ** Convert |
| 371 | `NDOEnhancer. BuildTask` and `UISupport/NDO. UISupport` to SDK-style so that |
| 372 | only the VSIX still needs Visual Studio's MSBuild. |
| 373 | |
| 374 | ## 7. Open Questions |
| 375 | |
| 376 | - **Test projects. ** Should test projects ( IntegrationTests, FormatterUnitTests, |
| 377 | PureBusinessClasses, UnitTestGenerator/*) always follow the newest package |
| 378 | versions, or keep pinned versions? Alternatively, should they switch to |
| 379 | ProjectReferences, as the NDODLL tests already do? |
| 380 | - **Provider propagation. ** Should providers be bumped when NDOInterfaces |
| 381 | changes? They depend on it through a ProjectReference, so the default policy |
| 382 | says yes. |
| 383 | - **VSIX version. ** Should the VSIX ( `NDOPackage/source. extension. vsixmanifest`, |
| 384 | currently 5. 0. 0) be part of the manifest and follow NDO. dll or NDO. Build? |
| 385 | - **Pre-release versions.** Is a pre-release suffix (`6.1.0-beta1`) needed? |
| 386 | ··`NuGet.Versioning` supports it, but Assembly/FileVersion then have to drop the suffix. |
| 387 | |
| 388 | Resume this session with: |
| 389 | claude --resume f5170928-a07b-4b74-8448-44f4716daaa0 |
New Commit (37abc99)
| 1 | # NDO Build Process – Concept for Independent Package Versioning |
| 2 | |
| 3 | ## 1. Context |
| 4 | |
| 5 | NDO ships as a set of NuGet packages. Other projects inside and outside this |
| 6 | repository consume them. The packages evolve independently. When one package changes: |
| 7 | |
| 8 | 1. It needs a new version. That means `Version`, `AssemblyVersion` and `FileVersion` in its csproj. |
| 9 | 2. Every project that depends on it must reference the new version. |
| 10 | 3. Every dependent *package* must get a new version of its own. |
| 11 | 4. Steps 2 and 3 repeat for the dependents' dependents. |
| 12 | |
| 13 | The repository contains two kinds of projects, and the build handles both: |
| 14 | |
| 15 | 1. **Package projects (producers).** They produce the NDO packages |
| 16 | ·· (NDOInterfaces, NDO.dll, the providers, NDO.Build, …). |
| 17 | 2. **Test projects (consumers).** They only consume the packages, through |
| 18 | ·· `PackageReference` or `ProjectReference`. They are never packed. Tools that |
| 19 | ·· consume packages (TestGenerator, SimpleMappingTool) are treated the same way. |
| 20 | |
| 21 | Until now, a complete build was described by the MSBuild script `Make/NDO. proj`, |
| 22 | and versions were patched by `Tools/PatchNdoVersion`. That tool assumed one |
| 23 | version for all packages NDO. dll depends on and never touched a package's own |
| 24 | version. Both are replaced by the script described here. |
| 25 | |
| 26 | Out of scope: |
| 27 | - **The VSIX** (`NDOPackage`) and the projects only it needs |
| 28 | ··(`UISupport/NDO.UISupport`, the provider `*UISupport` projects) are not built. |
| 29 | ··Their `PackageReference`s are still kept up to date. |
| 30 | - **Pre-release versions** (`6.1.0-beta1`) are not supported. All versions are |
| 31 | ··`major.minor.patch`. |
| 32 | |
| 33 | ## 2. Current State |
| 34 | |
| 35 | ### 2. 1 Package projects |
| 36 | |
| 37 | | Package id | Project | Version | Assembly/FileVersion | |
| 38 | |---|---|---|---| |
| 39 | | NDOInterfaces | `NDOInterfaces/NDOInterfaces.csproj` | 6.0.0 | 6.0.0.0 | |
| 40 | | NDO.Mapping | `NDO.Mapping/NDO.Mapping/NDO.Mapping.csproj` | 6.0.0 | **6.0.0** (3 parts) | |
| 41 | | NDO.ProviderFactory | `NDO.ProviderFactory/NDO.ProviderFactory/NDO.ProviderFactory.csproj` | 6.0.0 | 6.0.0.0 | |
| 42 | | NDO.SchemaGenerator | `NDO.SchemaGenerator/NDO.SchemaGenerator/NDO.SchemaGenerator.csproj` | 6.0.0 | 6.0.0.0 | |
| 43 | | NDO.dll | `NDODLL/NDO.csproj` | 6.0.0 | 6.0.0.0 | |
| 44 | | NDO.JsonFormatter | `NdoJsonFormatter/NdoJsonFormatter/NDO.JsonFormatter.csproj` | 5.1.1 | 5.1.1.0 | |
| 45 | | ndo.mysql, ndo.mysqlconnector, ndo.oracle, ndo.postgre, ndo.sqlite, ndo.sqlserver | `Provider/*/NDO.*/NDO.*.csproj` | 5.1.0 | 5.1.0.0 | |
| 46 | | NDO. Build | `nuget/NDO. Build. nuspec` ( packed with `nuget. exe`) | **6. 0. 1. 0** ( 4 parts) | – | |
| 47 | |
| 48 | Notes: |
| 49 | - **Versions are scattered. ** Every version is hard-coded in its project file. |
| 50 | - **NDO.Build and NDOEnhancer are coupled.** NDO.Build packages the binaries of |
| 51 | ··`NDOEnhancer/NDOEnhancer` (Version 6.0.1.0) and `NDOEnhancer.BuildTask`. The |
| 52 | NDOEnhancer version must equal the NDO. Build version. |
| 53 | |
| 54 | ### 2.2 Test projects |
| 55 | |
| 56 | | Project | Kind | NDO references | |
| 57 | |---|---|---| |
| 58 | | `IntegrationTests/IntegrationTests` | test | Package: `NDO.JsonFormatter` 5.1.0 · Project: NDO.dll, ndo.sqlserver, PureBusinessClasses | |
| 59 | | `IntegrationTests/PureBusinessClasses` | library of IntegrationTests | Package: `ndo.dll` 5.1.1 | |
| 60 | | `NdoJsonFormatter/FormatterUnitTests` | test | Package: `ndo.dll` 5.1.1, `ndo.sqlserver` 5.1.0 · Project: NDO.JsonFormatter | |
| 61 | | `NDODLL.Tests/NdoDllUnitTests`, `QueryTests`, `AsyncTests` | test | Project: NDO.dll and providers | |
| 62 | | `NDOEnhancer/Ecma335Tests` | test | Project: Ecma335 (no package) | |
| 63 | | `UnitTestGenerator/UnitTests` (+ `PersistentClasses`) | test | Package: `NDO.dll`, `NDOInterfaces`, `NDO.SqlServer`, `NDO.Build` 5.0.0 | |
| 64 | | `UnitTestGenerator/TestGenerator` | tool | Package: `NDO.Mapping`, `NDO.ProviderFactory` 5.0.0 | |
| 65 | | `SimpleMappingTool/Mapping.csproj` | tool | Package: `NDO.mapping` 5.1.1 | |
| 66 | | `NDOEnhancer/PersistentEnhancerTestClasses` | test classes | Package: `ndo.dll` 5.0.0 – targets net6.0/netstandard2.x, which NDO 6 no longer supports | |
| 67 | |
| 68 | ### 2. 3 How dependencies are expressed |
| 69 | |
| 70 | **ProjectReference (inside the core).** These references form the core graph: |
| 71 | |
| 72 | ``` |
| 73 | NDOInterfaces |
| 74 | ├── NDO.Mapping ── NDO.SchemaGenerator ─┐ |
| 75 | ├── NDO.ProviderFactory ────────────────┤ |
| 76 | ├───────────────────────────────────────┴── NDO.dll |
| 77 | ├── ndo.<provider> (6x) |
| 78 | └── NDOEnhancer ( also Mapping, ProviderFactory, SchemaGenerator, Ecma335) ── NDO. Build |
| 79 | ``` |
| 80 | |
| 81 | `dotnet pack` turns a ProjectReference into a package dependency `>= <Version of |
| 82 | the referenced project>`. So **no reference needs to be edited** here. The |
| 83 | dependent package only needs its own version bump, because its nuspec now |
| 84 | points to a different dependency version. |
| 85 | |
| 86 | **PackageReference ( outside the core) . ** NDO. JsonFormatter, the test projects |
| 87 | and tools of 2.2 and the provider UISupport projects (`NDOInterfaces` 5.1.0) |
| 88 | use PackageReferences. Package ids are spelled with inconsistent casing |
| 89 | (`ndo.dll`, `NDO.dll`, `NDO.mapping`), so all matching is case-insensitive. |
| 90 | |
| 91 | ### 2. 4 Problems with the old build |
| 92 | |
| 93 | - **The patch step was broken. ** `Make/NDO. proj` called `PatchNdoVersion -i` on |
| 94 | projects that no longer have an `NDOInterfaces` PackageReference. |
| 95 | - **PatchNdoVersion was limited:** it only searched the first `ItemGroup` with a |
| 96 | `PackageReference`, reformatted the file through `XDocument. Save`, and |
| 97 | couldn't bump a project's own version. |
| 98 | - **Copying to `BuiltPackages` was Windows-only and incomplete. ** Per-project |
| 99 | `PostBuild` targets used `cmd copy`. The providers and NDO. JsonFormatter |
| 100 | didn't copy at all, and NDO. dll copied no `. snupkg`. |
| 101 | - **Some projects can't be built with `dotnet build`:** `NDOPackage` ( VSIX) , |
| 102 | `NDOEnhancer. BuildTask` ( old-style, GAC references to |
| 103 | `Microsoft. Build. Utilities. v4. 0`) and `UISupport/NDO. UISupport` ( old-style) . |
| 104 | - **The NuGet package source pointed to the wrong place. ** The user-level source |
| 105 | `NDO` is `C:\Projekte\NDO\BuiltPackages`, but the repository lives on `D:`. |
| 106 | That folder exists and contains stale packages, which could be restored |
| 107 | instead of fresh builds. The repository had no `nuget. config`. |
| 108 | |
| 109 | ## 3. Requirements |
| 110 | |
| 111 | 1. **One place to enter versions.** The developer enters the new version of a |
| 112 | ·· package in one single file. |
| 113 | 2. **Producer patching.** The script sets `Version`, `AssemblyVersion` and |
| 114 | ·· `FileVersion` in that package's csproj, or the version in its nuspec. |
| 115 | 3. **Consumer patching. ** Every `PackageReference` to an NDO package is set to |
| 116 | the version being built, in all csproj files: in package projects ( like |
| 117 | ·· NDO.JsonFormatter), test projects and tools. |
| 118 | 4. **Propagation.** Every package that depends on a changed package, directly |
| 119 | ·· or transitively, automatically gets a new version. Then steps 2 and 3 apply |
| 120 | ·· to it as well. |
| 121 | 5. **Building packages. ** Package projects are built with `dotnet build <csproj>`, |
| 122 | ·· in dependency order. |
| 123 | 6. **Collection.** All resulting `.nupkg` / `.snupkg` files end up in `BuiltPackages`. |
| 124 | 7. **Building and testing consumers.** After the packages, the test projects |
| 125 | ·· that depend on a rebuilt package are built against the new packages. |
| 126 | ·· On request they are also run with `dotnet test`. |
| 127 | |
| 128 | ## 4. Choice of Tool |
| 129 | |
| 130 | ### 4.1 Is MSBuild the right tool? |
| 131 | |
| 132 | **No, not for orchestration.** MSBuild is a declarative item/target engine. It |
| 133 | is excellent for describing *how to build one project*. It is a poor fit for |
| 134 | what this script must do: |
| 135 | |
| 136 | - **Graph logic.** The script must read all project files, build a dependency |
| 137 | ··graph, compute a transitive closure and sort it topologically. In MSBuild |
| 138 | ··this means inline tasks or a custom task assembly, which is effectively C# |
| 139 | ··anyway, just harder to debug. |
| 140 | - **Conditional state changes.** Rules like "bump the patch version of X only if |
| 141 | X itself was not bumped manually" lead to deeply nested conditions. |
| 142 | - **Editing XML in place.** `XmlPoke` rewrites the file and can't easily target |
| 143 | ··attributes on specific items without reformatting. |
| 144 | - **Diagnostics.** It's hard to produce a readable dry-run report. |
| 145 | |
| 146 | MSBuild stays the right tool *inside* each csproj. It is no longer the orchestrator. |
| 147 | |
| 148 | ### 4.2 Alternatives |
| 149 | |
| 150 | | Option | Pros | Cons | |
| 151 | |---|---|---| |
| 152 | | **MSBuild orchestration file** ( old state) | No new runtime | Weak at graph and conditional logic; painful XML patching; hard to debug | |
| 153 | | **PowerShell 7 script** | Good XML support; easy process calls | Different language from the code base; `[xml]` reformats unless handled carefully; PS 5. 1 vs. 7 differences | |
| 154 | | **C# file-based app** ( `dotnet run build. cs`, . NET 10+) | Same language as NDO; `XDocument`, `System. Text. Json` available; no `. csproj` needed; debuggable; cross-platform | Requires the . NET 10 SDK ( already required by the net10. 0/net11. 0 targets) | |
| 155 | | **Cake / NUKE** | Mature build DSLs in C# | Extra dependency and learning curve; heavyweight for one repository | |
| 156 | | **Central Package Management** ( `Directory. Packages. props`) | All `PackageReference` versions in one file | Only covers consumers, not the producers' own versions or propagation. It **complements** a script and doesn't replace it | |
| 157 | |
| 158 | ### 4. 3 Decision |
| 159 | |
| 160 | A **C# file-based app**: `Make/build. cs`, run with `dotnet run Make/build. cs`. |
| 161 | |
| 162 | - It is the same language as the code base and replaces PatchNdoVersion and `NDO. proj`. |
| 163 | - It needs no build project, bootstrapper or package reference. Since |
| 164 | pre-release versions are not supported, a small `major. minor. patch` type is |
| 165 | enough; `NuGet. Versioning` is not needed. |
| 166 | - It has a `--dry-run` mode with a clear report. |
| 167 | |
| 168 | ## 5. Design |
| 169 | |
| 170 | ### 5.1 Version manifest – the single source of truth |
| 171 | |
| 172 | `Make/packages. json` lists every package that the build produces and every |
| 173 | consumer the build compiles. It is the **only** file the developer edits to |
| 174 | release a new version. Paths are relative to the repository root, except |
| 175 | `packageSource`, which is relative to the manifest. |
| 176 | |
| 177 | ```json |
| 178 | { |
| 179 | ··"packageSource": "../BuiltPackages", |
| 180 | ··"configuration": "Release", |
| 181 | ··"propagation": "patch", |
| 182 | ··"exclude": [ "Tutorial", "ClassGenerator", "UnitTests" ], |
| 183 | ··"pinned": [ "NDOEnhancer/PersistentEnhancerTestClasses/PersistentEnhancerTestClasses.csproj" ], |
| 184 | ··"packages": [ |
| 185 | { "id": "NDOInterfaces", "project": "NDOInterfaces/NDOInterfaces. csproj", "version": "6. 0. 0" } , |
| 186 | { "id": "NDO. dll", "project": "NDODLL/NDO. csproj", "version": "6. 0. 0" } , |
| 187 | … |
| 188 | { "id": "NDO. Build", "project": "nuget/NDO. Build. nuspec", "builder": "nuget", "version": "6. 0. 1", |
| 189 | ······"versionFollowers": [ "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj" ], |
| 190 | "buildFirst": [ |
| 191 | { "project": "Tools/MakeEnhancerDate/MakeEnhancerDate. csproj", "configuration": "Release" } , |
| 192 | { "project": "NDOEnhancer/NDOEnhancer/NDOEnhancer. csproj", "configuration": "Release" } , |
| 193 | ········{ "project": "NDOEnhancer.BuildTask/NDOEnhancer.BuildTask/NDOEnhancer.BuildTask.csproj", |
| 194 | ··········"builder": "msbuild", "configuration": "Release" } ] } |
| 195 | ··], |
| 196 | ··"enhancer": "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj", |
| 197 | ··"consumersBuildFirst": [ |
| 198 | ····{ "project": "Tools/MakeEnhancerDate/MakeEnhancerDate.csproj", "configuration": "Release" }, |
| 199 | ····{ "project": "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj", "configuration": "Debug" } |
| 200 | ··], |
| 201 | ··"consumers": [ |
| 202 | ····{ "project": "IntegrationTests/IntegrationTests/IntegrationTests.csproj", "test": true }, |
| 203 | ····{ "project": "SimpleMappingTool/Mapping.csproj" }, |
| 204 | ····… |
| 205 | ··] |
| 206 | } |
| 207 | ``` |
| 208 | |
| 209 | - **`packages`** – the producers. Dependencies are **not** listed. They are |
| 210 | derived from the project files, so they can never get out of sync. |
| 211 | - `builder`: `dotnet` ( default) , `nuget` ( nuspec packed with `nuget/NuGet. exe`) |
| 212 | or `msbuild` ( Visual Studio's MSBuild, found via `vswhere`) . |
| 213 | - `versionFollowers`: projects that get the same version but are not packed |
| 214 | ····themselves, like NDOEnhancer. |
| 215 | ··- `buildFirst`: projects built before the package. Their dependencies count |
| 216 | ····as dependencies of the package, so NDO.Build is bumped whenever a package |
| 217 | ····bundled with the enhancer changes. |
| 218 | ··- `configuration` (in `buildFirst` entries and consumers): overrides the global configuration. |
| 219 | - **`consumers`** – the test projects and tools the build compiles. |
| 220 | ··`"test": true` marks projects that `--test` runs with `dotnet test`. |
| 221 | ··Only top-level projects are listed; libraries like PureBusinessClasses are |
| 222 | ··built through their ProjectReferences. |
| 223 | - **`enhancer`** – the NDOEnhancer project. Its framework and every path to its |
| 224 | ··output are kept up to date (5.5). |
| 225 | - **`consumersBuildFirst`** – projects built once before the first consumer. |
| 226 | ··The test projects run the enhancer from its Debug output, so the enhancer is |
| 227 | ··built here in Debug, while NDO.Build packs its Release output. |
| 228 | - **`exclude`** – folders (relative to the root) that are not scanned. They |
| 229 | ··contain legacy projects with NDO 1.x–4.x GAC or HintPath references. |
| 230 | - **`pinned`** – projects whose PackageReferences are never changed and that |
| 231 | ··don't take part in propagation. Used for projects that intentionally stay on |
| 232 | ··an old NDO version, like PersistentEnhancerTestClasses (net6.0/netstandard). |
| 233 | |
| 234 | ### 5.2 Dependency graph |
| 235 | |
| 236 | The script scans every `*. csproj` under the repository root, skipping `bin`, |
| 237 | `obj`, `packages`, `.vs` and the `exclude` folders. |
| 238 | |
| 239 | - An **edge** "B depends on A" is created when: |
| 240 | - project B contains `<PackageReference Include="id">`, where `id` matches a |
| 241 | manifest id case-insensitively. A is that package's project; or |
| 242 | - project B contains a `<ProjectReference>` that resolves to project A. |
| 243 | - Dependencies are followed transitively, also through projects that are no |
| 244 | packages ( e. g. NDOEnhancer → Ecma335) . |
| 245 | - A package's dependencies are the packages reachable from its project, its |
| 246 | `buildFirst` projects and its `versionFollowers`. |
| 247 | - A consumer's dependencies are the packages reachable from its project. |
| 248 | |
| 249 | The package graph is checked for cycles and sorted topologically. |
| 250 | |
| 251 | ### 5.3 Algorithm |
| 252 | |
| 253 | ``` |
| 254 | 1. Load manifest; scan projects; build graph ( 5. 2) . |
| 255 | |
| 256 | 2. Detect changes |
| 257 | current( p) = version in p's project file / nuspec |
| 258 | ·· changed····= { p | manifest.version(p) != current(p) }········(manual) |
| 259 | |
| 260 | 3. Propagate |
| 261 | ·· for p in topological order: |
| 262 | if p not in changed and a dependency of p is in changed: |
| 263 | p. version = bump( current( p) , policy) // 5. 1. 0 -> 5. 1. 1 |
| 264 | changed += p ( propagated) |
| 265 | Write the propagated versions back into packages. json. |
| 266 | |
| 267 | 4. Patch producers ( every package) |
| 268 | ·· csproj:··<Version>x.y.z</Version> |
| 269 | ············<AssemblyVersion>x.y.z.0</AssemblyVersion> |
| 270 | ············<FileVersion>x.y.z.0</FileVersion> |
| 271 | ·· nuspec:··<version>x.y.z</version> |
| 272 | ·· versionFollowers: same three properties. |
| 273 | ·· For unchanged packages this only normalizes the format (e.g. NDO.Mapping's |
| 274 | ·· 3-part AssemblyVersion, NDO.Build's 4-part version). |
| 275 | |
| 276 | 5. Patch consumers ( every scanned project except pinned ones) |
| 277 | for each <PackageReference Include=id Version=v> with id in the manifest: |
| 278 | if v != manifest version: set Version to the manifest version |
| 279 | ·· This includes package projects that consume other NDO packages, like |
| 280 | ·· NDO.JsonFormatter (ndo.dll). Every consumer always references the version |
| 281 | ·· that is being built. |
| 282 | ·· ProjectReferences are left untouched (the version flows in at pack time). |
| 283 | |
| 284 | 5b. Patch the enhancer ( 5. 5) |
| 285 | ·· tfm = highest netX.Y in the TargetFramework(s) of all package projects |
| 286 | ·· enhancer csproj:··<TargetFramework>tfm</TargetFramework>··(single framework) |
| 287 | ·· every scanned csproj and every package nuspec: |
| 288 | ······ NDOEnhancer\bin\<Debug|Release>\<any netX.Y>\…··->··…\<tfm>\… |
| 289 | |
| 290 | 6. Print a report – stop here with --dry-run or --no-build. |
| 291 | |
| 292 | 7. Build packages in topological order ( 5. 4) . |
| 293 | ·· toBuild = changed |
| 294 | ·········· ∪ { p | step 5 updated a PackageReference in p's project } |
| 295 | ·········· ∪ { p | <packageSource>/<id>.<version>.nupkg does not exist } |
| 296 | ·········· ∪ --rebuild ids······················ (--all: every package; --only: just these) |
| 297 | |
| 298 | 8. Build consumers that depend on a package in toBuild ( --all: every consumer) . |
| 299 | ·· Before the first consumer, build consumersBuildFirst (enhancer in Debug). |
| 300 | ·· With --test, run `dotnet test` on those marked "test". |
| 301 | ``` |
| 302 | |
| 303 | The "nupkg does not exist" rule makes the script restartable: if a build fails |
| 304 | after the files were patched, the next run detects no version change, but it |
| 305 | still builds every package that hasn't reached `BuiltPackages` yet. |
| 306 | |
| 307 | Rules for patching: |
| 308 | - **Keep formatting. ** The text is edited in place with regular expressions |
| 309 | limited to the found element. Encoding, BOM and line endings are preserved. |
| 310 | The diff of a project file shows only the changed version lines. |
| 311 | - **Only properties are patched. ** `<Version>` is only replaced inside a |
| 312 | `PropertyGroup`, never the `<Version>` child element of a `PackageReference`. |
| 313 | All occurrences are patched ( also in conditional `PropertyGroup`s) . Missing |
| 314 | `AssemblyVersion`/`FileVersion` properties are not added; the SDK derives them. |
| 315 | - **Report unknown references.** If a reference uses a version range or a |
| 316 | ··property (`Version="$(...)"`), the script reports it instead of guessing. |
| 317 | |
| 318 | ### 5.4 Building |
| 319 | |
| 320 | **Packages** are built in topological order: |
| 321 | |
| 322 | ``` |
| 323 | dotnet restore <csproj> --force |
| 324 | dotnet build·· <csproj> -c Release --no-restore |
| 325 | ``` |
| 326 | |
| 327 | `GeneratePackageOnBuild=true` is set in all package projects, so the build also |
| 328 | produces the `.nupkg` / `.snupkg`. The script then copies |
| 329 | `bin/<Configuration>/<id>.<version>.nupkg` and `.snupkg` to `BuiltPackages`. |
| 330 | The `cmd copy` `PostBuild` targets have been removed from the project files. |
| 331 | |
| 332 | **Restore. ** The repository's `nuget. config` adds `BuiltPackages` as a package |
| 333 | source and disables the stale user-level source `NDO`. Because producers are |
| 334 | built and collected first ( topological order) , the packages are available when |
| 335 | a dependent package or a consumer restores. `--force` makes restore re-evaluate |
| 336 | even if the version in the project file didn't change. |
| 337 | |
| 338 | **NuGet cache.** Before a package is built, its entry |
| 339 | `~/.nuget/packages/<id>/<version>` (or `%NUGET_PACKAGES%`) is deleted. |
| 340 | Otherwise consumers would keep the old content if a package is rebuilt without |
| 341 | a version change. |
| 342 | |
| 343 | **Consumers** are built after all packages. First the `consumersBuildFirst` |
| 344 | projects are built once ( MakeEnhancerDate in Release, NDOEnhancer in Debug) , |
| 345 | then every consumer with |
| 346 | |
| 347 | ``` |
| 348 | dotnet restore <csproj> --force |
| 349 | dotnet build <csproj> -c <configuration> --no-restore |
| 350 | dotnet test <csproj> -c <configuration> --no-build ( only with --test) |
| 351 | ``` |
| 352 | |
| 353 | A failing package build stops the script, because its dependents can't be built. |
| 354 | A failing consumer is reported, the remaining consumers are still built, and the |
| 355 | exit code is non-zero. |
| 356 | |
| 357 | **Exceptions that can't use `dotnet build`:** |
| 358 | |
| 359 | | Project | Handling | |
| 360 | |---|---| |
| 361 | | `NDOEnhancer.BuildTask` | `"builder": "msbuild"`: Visual Studio's `MSBuild.exe`, found via `vswhere -latest -find MSBuild\**\Bin\MSBuild.exe`. Long term: convert it to an SDK-style project with `Microsoft.Build.Utilities.Core` | |
| 362 | | `NDO.Build` (nuspec) | `"builder": "nuget"`: first the `buildFirst` projects, then `nuget/NuGet.exe pack NDO.Build.nuspec -Version <version> -OutputDirectory <packageSource>` | |
| 363 | | `Tools/MakeEnhancerDate` | Prerequisite of NDOEnhancer, listed in `buildFirst` of NDO.Build | |
| 364 | |
| 365 | ### 5. 5 Enhancer |
| 366 | |
| 367 | Test projects enhance their persistent classes with an `<Exec>` task that calls |
| 368 | the enhancer directly from its build output, e. g. in PureBusinessClasses: |
| 369 | |
| 370 | ```xml |
| 371 | <Exec WorkingDirectory="bin\Debug\net8.0" |
| 372 | ······Command="..\..\..\..\..\NDOEnhancer\NDOEnhancer\bin\debug\net11.0\NDOEnhancer ..\..\..\PureBusinessClasses.ndoproj $(TargetFramework)" /> |
| 373 | ``` |
| 374 | |
| 375 | Rules: |
| 376 | - **Only the highest .NET version.** The enhancer targets exclusively the highest |
| 377 | ··`netX.Y` that any package project targets (currently net11.0). The script sets |
| 378 | ··`<TargetFramework>` in the enhancer project accordingly; a `TargetFrameworks` |
| 379 | ··list is replaced by that single framework. |
| 380 | - **Paths follow the framework.** In every scanned csproj and every package |
| 381 | ··nuspec, the framework folder in a path `NDOEnhancer\bin\<Debug|Release>\<netX.Y>\` |
| 382 | ··is set to that version. This covers the `<Exec>` tasks of the test projects and |
| 383 | ··the `<file src=…>` of `NDO.Build.nuspec`. |
| 384 | - **Release for the package, Debug for the tests.** NDO.Build builds the enhancer |
| 385 | ··in Release (`buildFirst`). Before the first consumer, the enhancer is built in |
| 386 | ··Debug (`consumersBuildFirst`), so the `<Exec>` tasks find a current Debug build. |
| 387 | |
| 388 | When a package project gets a new framework (e.g. net12.0), the next run moves |
| 389 | the enhancer and all paths to it without further manual edits. |
| 390 | |
| 391 | ### 5. 6 Command line |
| 392 | |
| 393 | ``` |
| 394 | dotnet run Make/build.cs [options] |
| 395 | |
| 396 | --dry-run Show detected changes, propagated bumps, all file edits |
| 397 | and the build plan; change nothing. |
| 398 | --no-build Patch versions and references only. |
| 399 | --all Build all packages and all consumers. |
| 400 | --only <id> Build only this package ( repeatable) ; consumers that |
| 401 | depend on it are built as well. |
| 402 | --rebuild <id> Rebuild a package without a version change ( repeatable) . |
| 403 | --no-consumers Don't build consumers. |
| 404 | --test Run `dotnet test` on the built test projects. |
| 405 | ··--bump patch|minor·· Propagation policy (default: "propagation" in the manifest). |
| 406 | ··-c <config>··········Configuration of packages (default: manifest). |
| 407 | ``` |
| 408 | |
| 409 | Example session: |
| 410 | |
| 411 | ``` |
| 412 | > # edit Make/packages.json: NDOInterfaces 6.0.0 -> 6.0.1 |
| 413 | > dotnet run Make/build.cs --dry-run |
| 414 | Version changes: |
| 415 | NDOInterfaces 6. 0. 0 -> 6. 0. 1 ( manual) |
| 416 | NDO. Mapping 6. 0. 0 -> 6. 0. 1 ( propagated) |
| 417 | NDO. ProviderFactory 6. 0. 0 -> 6. 0. 1 ( propagated) |
| 418 | ndo. sqlserver 5. 1. 0 -> 5. 1. 1 ( propagated) … other providers |
| 419 | NDO. dll 6. 0. 0 -> 6. 0. 1 ( propagated) |
| 420 | NDO. JsonFormatter 5. 1. 1 -> 5. 1. 2 ( propagated) |
| 421 | NDO. Build 6. 0. 1 -> 6. 0. 2 ( propagated) |
| 422 | File edits: |
| 423 | ··NDOInterfaces/NDOInterfaces.csproj·· Version 6.0.0 -> 6.0.1 … |
| 424 | ··SimpleMappingTool/Mapping.csproj···· PackageReference NDO.mapping 5.1.1 -> 6.0.1 |
| 425 | ··… |
| 426 | Packages to build: NDOInterfaces, NDO. Mapping, … |
| 427 | Consumers to build: IntegrationTests/IntegrationTests/IntegrationTests. csproj, … |
| 428 | > dotnet run Make/build.cs --test |
| 429 | ``` |
| 430 | |
| 431 | ### 5. 7 Propagation policy |
| 432 | |
| 433 | By default a dependent package gets a **patch** bump. If the developer has |
| 434 | already raised a dependent's version in the manifest, for example to a new |
| 435 | minor version for an API change, that manual version wins and the package is |
| 436 | not bumped again. |
| 437 | |
| 438 | This applies to **all** dependents, including the **providers**: they depend on |
| 439 | NDOInterfaces through a ProjectReference, so a change of NDOInterfaces bumps |
| 440 | every provider. |
| 441 | |
| 442 | With ProjectReferences, the dependency in the produced nuspec is a *minimum* |
| 443 | version ( `>= x`) . Bumping the dependent is still necessary. It guarantees that |
| 444 | the published dependent package is a new artifact that points to the new |
| 445 | dependency, and that old consumers don't receive a changed package under an |
| 446 | unchanged version. |
| 447 | |
| 448 | ## 6. Migration Steps |
| 449 | |
| 450 | 1. **Create the manifest** `Make/packages. json` from the current project versions ( 2. 1, 2. 2) . ✔ |
| 451 | 2. **Implement the script** `Make/build. cs`. A first `--dry-run` without |
| 452 | manual changes reports no version changes, only format normalizations. ✔ |
| 453 | 3. **Unify version formats. ** 4-part Assembly/FileVersion, 3-part Version; |
| 454 | done automatically on the first patch run. ✔ |
| 455 | 4. **Remove the copy targets. ** The `cmd copy` `PostBuild` targets are gone; |
| 456 | the script collects the packages. ✔ |
| 457 | 5. **Add a `nuget.config`** at the repository root with `BuiltPackages` as a |
| 458 | relative package source and the user-level source `NDO` disabled. ✔ |
| 459 | 6. **Retire the old build. ** `Make/NDO. proj` and `Tools/PatchNdoVersion` are deleted. ✔ |
| 460 | 7. **Optional: Central Package Management. ** Introduce `Directory. Packages. props` |
| 461 | ·· for the NDO package versions used by consumers. |
| 462 | 8. **Optional: modernize legacy projects. ** Convert `NDOEnhancer. BuildTask` to |
| 463 | SDK-style so that the build needs no Visual Studio installation. |
| 464 | |
| 465 | ## 7. Decisions |
| 466 | |
| 467 | - **Consumers always reference the version being built.** This applies to test |
| 468 | ··projects, tools and package projects that consume other NDO packages (e.g. |
| 469 | ··NDO.JsonFormatter → ndo.dll, and therefore FormatterUnitTests). Their |
| 470 | ··PackageReferences are set to the manifest version on every run. A package |
| 471 | ··whose references were updated is rebuilt. Existing ProjectReferences, as in |
| 472 | ··the NDODLL tests, stay; they always build against the current source. After |
| 473 | ··the packages, the build compiles the affected test projects and, with |
| 474 | ··`--test`, runs them. Projects that must stay on an old version are `pinned`. |
| 475 | - **Provider propagation** takes place. Providers are bumped when NDOInterfaces changes (5.7). |
| 476 | - **VSIX** is not part of the build (1). |
| 477 | - **Pre-release versions** are not supported (1). |
| 478 | |
| 479 | ## 8. Known Issues |
| 480 | |
| 481 | These consumers fail for reasons outside the build script: |
| 482 | |
| 483 | - `NDOEnhancer/PersistentEnhancerTestClasses` is multi-targeted. Its `<Exec>` |
| 484 | task runs `AfterTargets="Build"` in the outer build, where `$( TargetFramework) ` |
| 485 | is empty, and the enhancer exits with code 3. |
| 486 | - `UnitTestGenerator/UnitTests` uses the `NDO. Build` package. Its |
| 487 | `NDOEnhancer. BuildTask. dll` references `Microsoft. Build. Utilities. v4. 0`, which |
| 488 | can't be loaded by `dotnet build` ( . NET MSBuild) . Projects using NDO. Build can |
| 489 | currently only be built with Visual Studio. Converting `NDOEnhancer. BuildTask` |
| 490 | to an SDK-style project with `Microsoft. Build. Utilities. Core` ( migration step 8) |
| 491 | solves this for package consumers as well. |
| 492 | |