Datei: Concepts/BuildProcess.md

Last Commit (e2d950d)
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
New Commit (6e13ce2)
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 **Package projects use PackageReferences. ** A package project references
71 another NDO package only through a `PackageReference`, never through a
72 `ProjectReference`. Each package is built against a released version of its
73 dependencies, which `Make/build.cs` produced before and collected in
74 `BuiltPackages`. These references form the core graph:
75
76 ```
77 NDOInterfaces
78 ├── NDO.Mapping ── NDO.SchemaGenerator ─┐
79 ├── NDO.ProviderFactory ────────────────┤
80 ├───────────────────────────────────────┴── NDO. dll ── NDO. JsonFormatter
81 ├── ndo.<provider> (6x)
82 └── NDOEnhancer ( also Mapping, ProviderFactory, SchemaGenerator) ── NDO. Build
83 ```
84
85 Projects that are no packages themselves (e.g. `NDOEnhancer/Ecma335`) are still
86 referenced with a `ProjectReference`. NDOEnhancer counts as a package project,
87 because its output is packed into NDO.Build.
88
89 Because the version is written in the `PackageReference`, the script must
90 patch these references whenever a dependency gets a new version ( 5. 3, step 5) .
91 The dependent package also needs its own version bump, because its nuspec
92 then points to a different dependency version.
93
94 **Test projects and tools use ProjectReferences where possible. ** The tests
95 in `NDODLL. Tests` and `IntegrationTests` ( with PureBusinessClasses) reference
96 NDO. dll, NDO. JsonFormatter and the providers through `ProjectReference`s, so
97 changes to that source take effect without a package build. Some test projects
98 and tools (2.2) and the provider UISupport projects still use PackageReferences. Package ids are spelled with inconsistent casing
99 (`ndo.dll`, `NDO.dll`, `NDO.mapping`), so all matching is case-insensitive.
100
101 **Mixing both kinds of references.** A test project with a `ProjectReference`
102 to NDO.dll gets the dependencies of NDO.dll (NDOInterfaces, NDO.Mapping, …)
103 transitively as *packages* from `BuiltPackages`. If the test project
104 also references the project of such a dependency (directly or through another
105 project), NuGet resolves that id to the **project** and ignores the package
106 with the same id. Two consequences:
107
108 - A source change in NDOInterfaces reaches a test only if the test (directly or
109 ··transitively) has a `ProjectReference` to `NDOInterfaces.csproj`. Otherwise the
110 ··test sees the package version until the script has built a new package.
111 - NDO.dll itself is always compiled against the *package* of NDOInterfaces.
112 ··A change in NDO.dll that needs a new API of NDOInterfaces can only be compiled
113 ··after NDOInterfaces was built as a package (`dotnet run Make/build.cs`).
114 ··The project version and the version in the `PackageReference` must be equal
115 ··(the script guarantees this); otherwise NuGet reports a downgrade (NU1605).
116
117 ### 2.4 Problems with the old build
118
119 - **The patch step was broken.** `Make/NDO.proj` called `PatchNdoVersion -i` on
120 ··projects that no longer have an `NDOInterfaces` PackageReference.
121 - **PatchNdoVersion was limited:** it only searched the first `ItemGroup` with a
122 ··`PackageReference`, reformatted the file through `XDocument.Save`, and
123 ··couldn't bump a project's own version.
124 - **Copying to `BuiltPackages` was Windows-only and incomplete.** Per-project
125 ··`PostBuild` targets used `cmd copy`. The providers and NDO.JsonFormatter
126 ··didn't copy at all, and NDO.dll copied no `.snupkg`.
127 - **Some projects can't be built with `dotnet build`:** `NDOPackage` (VSIX),
128 ··`NDOEnhancer.BuildTask` (old-style, GAC references to
129 ··`Microsoft.Build.Utilities.v4.0`) and `UISupport/NDO.UISupport` (old-style).
130 - **The NuGet package source pointed to the wrong place.** The user-level source
131 ··`NDO` is `C:\Projekte\NDO\BuiltPackages`, but the repository lives on `D:`.
132 ··That folder exists and contains stale packages, which could be restored
133 ··instead of fresh builds. The repository had no `nuget.config`.
134
135 ## 3. Requirements
136
137 1. **One place to enter versions.** The developer enters the new version of a
138 ·· package in one single file.
139 2. **Producer patching.** The script sets `Version`, `AssemblyVersion` and
140 ·· `FileVersion` in that package's csproj, or the version in its nuspec.
141 3. **Consumer patching.** Every `PackageReference` to an NDO package is set to
142 ·· the version being built, in all csproj files: in package projects (like
143 ·· NDO.JsonFormatter), test projects and tools.
144 4. **Propagation.** Every package that depends on a changed package, directly
145 ·· or transitively, automatically gets a new version. Then steps 2 and 3 apply
146 ·· to it as well.
147 5. **Building packages.** Package projects are built with `dotnet build <csproj>`,
148 ·· in dependency order.
149 6. **Collection.** All resulting `.nupkg` / `.snupkg` files end up in `BuiltPackages`.
150 7. **Building and testing consumers.** After the packages, the test projects
151 ·· that depend on a rebuilt package are built against the new packages.
152 ·· On request they are also run with `dotnet test`.
153
154 ## 4. Choice of Tool
155
156 ### 4.1 Is MSBuild the right tool?
157
158 **No, not for orchestration.** MSBuild is a declarative item/target engine. It
159 is excellent for describing *how to build one project*. It is a poor fit for
160 what this script must do:
161
162 - **Graph logic.** The script must read all project files, build a dependency
163 ··graph, compute a transitive closure and sort it topologically. In MSBuild
164 ··this means inline tasks or a custom task assembly, which is effectively C#
165 ··anyway, just harder to debug.
166 - **Conditional state changes.** Rules like "bump the patch version of X only if
167 ··X itself was not bumped manually" lead to deeply nested conditions.
168 - **Editing XML in place.** `XmlPoke` rewrites the file and can't easily target
169 ··attributes on specific items without reformatting.
170 - **Diagnostics.** It's hard to produce a readable dry-run report.
171
172 MSBuild stays the right tool *inside* each csproj. It is no longer the orchestrator.
173
174 ### 4.2 Alternatives
175
176 | Option | Pros | Cons |
177 |---|---|---|
178 | **MSBuild orchestration file** (old state) | No new runtime | Weak at graph and conditional logic; painful XML patching; hard to debug |
179 | **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 |
180 | **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) |
181 | **Cake / NUKE** | Mature build DSLs in C# | Extra dependency and learning curve; heavyweight for one repository |
182 | **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 |
183
184 ### 4.3 Decision
185
186 A **C# file-based app**: `Make/build.cs`, run with `dotnet run Make/build.cs`.
187
188 - It is the same language as the code base and replaces PatchNdoVersion and `NDO.proj`.
189 - It needs no build project, bootstrapper or package reference. Since
190 ··pre-release versions are not supported, a small `major.minor.patch` type is
191 ··enough; `NuGet.Versioning` is not needed.
192 - It has a `--dry-run` mode with a clear report.
193
194 ## 5. Design
195
196 ### 5.1 Version manifest – the single source of truth
197
198 `Make/packages.json` lists every package that the build produces and every
199 consumer the build compiles. It is the **only** file the developer edits to
200 release a new version. Paths are relative to the repository root, except
201 `packageSource`, which is relative to the manifest.
202
203 ```json
204 {
205 ··"packageSource": "../BuiltPackages",
206 ··"configuration": "Release",
207 ··"propagation": "patch",
208 ··"exclude": [ "Tutorial", "ClassGenerator", "UnitTests" ],
209 ··"pinned": [ "NDOEnhancer/PersistentEnhancerTestClasses/PersistentEnhancerTestClasses.csproj" ],
210 ··"packages": [
211 ····{ "id": "NDOInterfaces", "project": "NDOInterfaces/NDOInterfaces.csproj", "version": "6.0.0" },
212 ····{ "id": "NDO.dll",······ "project": "NDODLL/NDO.csproj",··················"version": "6.0.0" },
213 ····…
214 ····{ "id": "NDO.Build", "project": "nuget/NDO.Build.nuspec", "builder": "nuget", "version": "6.0.1",
215 ······"versionFollowers": [ "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj" ],
216 ······"buildFirst": [
217 ········{ "project": "Tools/MakeEnhancerDate/MakeEnhancerDate.csproj", "configuration": "Release" },
218 ········{ "project": "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj", "configuration": "Release" },
219 ········{ "project": "NDOEnhancer.BuildTask/NDOEnhancer.BuildTask/NDOEnhancer.BuildTask.csproj",
220 ··········"builder": "msbuild", "configuration": "Release" } ] }
221 ··],
222 ··"enhancer": "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj",
223 ··"consumersBuildFirst": [
224 ····{ "project": "Tools/MakeEnhancerDate/MakeEnhancerDate.csproj", "configuration": "Release" },
225 ····{ "project": "NDOEnhancer/NDOEnhancer/NDOEnhancer.csproj", "configuration": "Debug" }
226 ··],
227 ··"consumers": [
228 ····{ "project": "IntegrationTests/IntegrationTests/IntegrationTests.csproj", "test": true },
229 ····{ "project": "SimpleMappingTool/Mapping.csproj" },
230 ····…
231 ··]
232 }
233 ```
234
235 - **`packages`** – the producers. Dependencies are **not** listed. They are
236 ··derived from the project files, so they can never get out of sync.
237 ··- `builder`: `dotnet` (default), `nuget` (nuspec packed with `nuget/NuGet.exe`)
238 ····or `msbuild` (Visual Studio's MSBuild, found via `vswhere`).
239 ··- `versionFollowers`: projects that get the same version but are not packed
240 ····themselves, like NDOEnhancer.
241 ··- `buildFirst`: projects built before the package. Their dependencies count
242 ····as dependencies of the package, so NDO.Build is bumped whenever a package
243 ····bundled with the enhancer changes.
244 ··- `configuration` (in `buildFirst` entries and consumers): overrides the global configuration.
245 - **`consumers`** – the test projects and tools the build compiles.
246 ··`"test": true` marks projects that `--test` runs with `dotnet test`.
247 ··Only top-level projects are listed; libraries like PureBusinessClasses are
248 ··built through their ProjectReferences.
249 - **`enhancer`** – the NDOEnhancer project. Its framework and every path to its
250 ··output are kept up to date (5.5).
251 - **`consumersBuildFirst`** – projects built once before the first consumer.
252 ··The test projects run the enhancer from its Debug output, so the enhancer is
253 ··built here in Debug, while NDO.Build packs its Release output.
254 - **`exclude`** – folders (relative to the root) that are not scanned. They
255 ··contain legacy projects with NDO 1.x–4.x GAC or HintPath references.
256 - **`pinned`** – projects whose PackageReferences are never changed and that
257 ··don't take part in propagation. Used for projects that intentionally stay on
258 ··an old NDO version, like PersistentEnhancerTestClasses (net6.0/netstandard).
259
260 ### 5.2 Dependency graph
261
262 The script scans every `*.csproj` under the repository root, skipping `bin`,
263 `obj`, `packages`, `.vs` and the `exclude` folders.
264
265 - An **edge** "B depends on A" is created when:
266 ··- project B contains `<PackageReference Include="id">`, where `id` matches a
267 ····manifest id case-insensitively. A is that package's project; or
268 ··- project B contains a `<ProjectReference>` that resolves to project A.
269 - Dependencies are followed transitively, also through projects that are no
270 ··packages (e.g. NDOEnhancer → Ecma335).
271 - A package's dependencies are the packages reachable from its project, its
272 ··`buildFirst` projects and its `versionFollowers`.
273 - A consumer's dependencies are the packages reachable from its project.
274
275 The package graph is checked for cycles and sorted topologically.
276
277 ### 5.3 Algorithm
278
279 ```
280 1. Load manifest; scan projects; build graph (5.2).
281
282 2. Detect changes
283 ·· current(p) = version in p's project file / nuspec
284 ·· changed····= { p | manifest.version(p) != current(p) }········(manual)
285
286 3. Propagate
287 ·· for p in topological order:
288 ······ if p not in changed and a dependency of p is in changed:
289 ·········· p.version = bump(current(p), policy)·················· // 5.1.0 -> 5.1.1
290 ·········· changed += p·········································· (propagated)
291 ·· Write the propagated versions back into packages.json.
292
293 4. Patch producers (every package)
294 ·· csproj:··<Version>x.y.z</Version>
295 ············<AssemblyVersion>x.y.z.0</AssemblyVersion>
296 ············<FileVersion>x.y.z.0</FileVersion>
297 ·· nuspec:··<version>x.y.z</version>
298 ·· versionFollowers: same three properties.
299 ·· For unchanged packages this only normalizes the format (e.g. NDO.Mapping's
300 ·· 3-part AssemblyVersion, NDO.Build's 4-part version).
301
302 5. Patch consumers (every scanned project except pinned ones)
303 ·· for each <PackageReference Include=id Version=v> with id in the manifest:
304 ······ if v != manifest version: set Version to the manifest version
305 This includes all package projects, because they reference other NDO
306 packages only through PackageReferences ( 2. 3) , e. g. NDO. dll → NDOInterfaces.
307 Every consumer always references the version that is being built.
308 ProjectReferences of the test projects are left untouched; they always build
309 ·· against the current source.
310
311 5b. Patch the enhancer (5.5)
312 ·· tfm = highest netX.Y in the TargetFramework(s) of all package projects
313 ·· enhancer csproj:··<TargetFramework>tfm</TargetFramework>··(single framework)
314 ·· every scanned csproj and every package nuspec:
315 ······ NDOEnhancer\bin\<Debug|Release>\<any netX.Y>\…··->··…\<tfm>\…
316
317 6. Print a report – stop here with --dry-run or --no-build.
318
319 7. Build packages in topological order (5.4).
320 ·· toBuild = changed
321 ·········· ∪ { p | step 5 updated a PackageReference in p's project }
322 ·········· ∪ { p | <packageSource>/<id>.<version>.nupkg does not exist }
323 ·········· ∪ --rebuild ids······················ (--all: every package; --only: just these)
324
325 8. Build consumers that depend on a package in toBuild (--all: every consumer).
326 ·· Before the first consumer, build consumersBuildFirst (enhancer in Debug).
327 ·· With --test, run `dotnet test` on those marked "test".
328 ```
329
330 The "nupkg does not exist" rule makes the script restartable: if a build fails
331 after the files were patched, the next run detects no version change, but it
332 still builds every package that hasn't reached `BuiltPackages` yet.
333
334 Rules for patching:
335 - **Keep formatting.** The text is edited in place with regular expressions
336 ··limited to the found element. Encoding, BOM and line endings are preserved.
337 ··The diff of a project file shows only the changed version lines.
338 - **Only properties are patched.** `<Version>` is only replaced inside a
339 ··`PropertyGroup`, never the `<Version>` child element of a `PackageReference`.
340 ··All occurrences are patched (also in conditional `PropertyGroup`s). Missing
341 ··`AssemblyVersion`/`FileVersion` properties are not added; the SDK derives them.
342 - **Report unknown references.** If a reference uses a version range or a
343 ··property (`Version="$(...)"`), the script reports it instead of guessing.
344
345 ### 5.4 Building
346
347 **Packages** are built in topological order:
348
349 ```
350 dotnet restore <csproj> --force
351 dotnet build·· <csproj> -c Release --no-restore
352 ```
353
354 `GeneratePackageOnBuild=true` is set in all package projects, so the build also
355 produces the `.nupkg` / `.snupkg`. The script then copies
356 `bin/<Configuration>/<id>.<version>.nupkg` and `.snupkg` to `BuiltPackages`.
357 The `cmd copy` `PostBuild` targets have been removed from the project files.
358
359 **Restore.** The repository's `nuget.config` adds `BuiltPackages` as a package
360 source. Because producers are built and collected first ( topological order) ,
361 the packages are available when a dependent package or a consumer restores:
362 NDOInterfaces is in `BuiltPackages` before NDO. Mapping restores, NDO. Mapping
363 before NDO.SchemaGenerator, and so on. `--force` makes restore re-evaluate
364 even if the version in the project file didn't change.
365
366 **Fresh clone.** `BuiltPackages` is not under version control. In a fresh
367 clone, a package project like NDO.dll can't be restored until its dependencies
368 have been built. Run `dotnet run Make/build.cs` once (or
369 `dotnet run Make/build.cs --all --no-consumers`) before building a solution in
370 Visual Studio.
371
372 **NuGet cache.** Before a package is built, its entry
373 `~/.nuget/packages/<id>/<version>` (or `%NUGET_PACKAGES%`) is deleted.
374 Otherwise consumers would keep the old content if a package is rebuilt without
375 a version change.
376
377 **Consumers** are built after all packages. First the `consumersBuildFirst`
378 projects are built once (MakeEnhancerDate in Release, NDOEnhancer in Debug),
379 then every consumer with
380
381 ```
382 dotnet restore <csproj> --force
383 dotnet build·· <csproj> -c <configuration> --no-restore
384 dotnet test····<csproj> -c <configuration> --no-build······(only with --test)
385 ```
386
387 A failing package build stops the script, because its dependents can't be built.
388 A failing consumer is reported, the remaining consumers are still built, and the
389 exit code is non-zero.
390
391 **Exceptions that can't use `dotnet build`:**
392
393 | Project | Handling |
394 |---|---|
395 | `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` |
396 | `NDO.Build` (nuspec) | `"builder": "nuget"`: first the `buildFirst` projects, then `nuget/NuGet.exe pack NDO.Build.nuspec -Version <version> -OutputDirectory <packageSource>` |
397 | `Tools/MakeEnhancerDate` | Prerequisite of NDOEnhancer, listed in `buildFirst` of NDO.Build |
398
399 ### 5.5 Enhancer
400
401 Test projects enhance their persistent classes with an `<Exec>` task that calls
402 the enhancer directly from its build output, e.g. in PureBusinessClasses:
403
404 ```xml
405 <Exec WorkingDirectory="bin\Debug\net8.0"
406 ······Command="..\..\..\..\..\NDOEnhancer\NDOEnhancer\bin\debug\net11.0\NDOEnhancer ..\..\..\PureBusinessClasses.ndoproj $(TargetFramework)" />
407 ```
408
409 Rules:
410 - **Only the highest .NET version.** The enhancer targets exclusively the highest
411 ··`netX.Y` that any package project targets (currently net11.0). The script sets
412 ··`<TargetFramework>` in the enhancer project accordingly; a `TargetFrameworks`
413 ··list is replaced by that single framework.
414 - **Paths follow the framework.** In every scanned csproj and every package
415 ··nuspec, the framework folder in a path `NDOEnhancer\bin\<Debug|Release>\<netX.Y>\`
416 ··is set to that version. This covers the `<Exec>` tasks of the test projects and
417 ··the `<file src=…>` of `NDO.Build.nuspec`.
418 - **Release for the package, Debug for the tests.** NDO.Build builds the enhancer
419 ··in Release (`buildFirst`). Before the first consumer, the enhancer is built in
420 ··Debug (`consumersBuildFirst`), so the `<Exec>` tasks find a current Debug build.
421
422 When a package project gets a new framework (e.g. net12.0), the next run moves
423 the enhancer and all paths to it without further manual edits.
424
425 **Assembly resolution.** When the enhancer reflects the assembly of a test
426 project, it resolves referenced assemblies (NDO.dll, …) first in the bin
427 directory of that assembly, then in the NuGet package folder (via
428 `project.assets.json`). The bin directory covers ProjectReferences, the package
429 folder covers PackageReferences.
430
431 ### 5.6 Command line
432
433 ```
434 dotnet run Make/build.cs [options]
435
436 ··--dry-run············Show detected changes, propagated bumps, all file edits
437 ······················ and the build plan; change nothing.
438 ··--no-build·········· Patch versions and references only.
439 ··--all················Build all packages and all consumers.
440 ··--only <id>··········Build only this package (repeatable); consumers that
441 ······················ depend on it are built as well.
442 ··--rebuild <id>······ Rebuild a package without a version change (repeatable).
443 ··--no-consumers······ Don't build consumers.
444 ··--test·············· Run `dotnet test` on the built test projects.
445 ··--bump patch|minor·· Propagation policy (default: "propagation" in the manifest).
446 ··-c <config>··········Configuration of packages (default: manifest).
447 ```
448
449 Example session:
450
451 ```
452 > # edit Make/packages.json: NDOInterfaces 6.0.0 -> 6.0.1
453 > dotnet run Make/build.cs --dry-run
454 Version changes:
455 ··NDOInterfaces········6.0.0 -> 6.0.1·· (manual)
456 ··NDO.Mapping··········6.0.0 -> 6.0.1·· (propagated)
457 ··NDO.ProviderFactory··6.0.0 -> 6.0.1·· (propagated)
458 ··ndo.sqlserver········5.1.0 -> 5.1.1·· (propagated)·· … other providers
459 ··NDO.dll··············6.0.0 -> 6.0.1·· (propagated)
460 ··NDO.JsonFormatter····5.1.1 -> 5.1.2·· (propagated)
461 ··NDO.Build············6.0.1 -> 6.0.2·· (propagated)
462 File edits:
463 ··NDOInterfaces/NDOInterfaces.csproj·· Version 6.0.0 -> 6.0.1 …
464 ··SimpleMappingTool/Mapping.csproj···· PackageReference NDO.mapping 5.1.1 -> 6.0.1
465 ··…
466 Packages to build:··NDOInterfaces, NDO.Mapping, …
467 Consumers to build: IntegrationTests/IntegrationTests/IntegrationTests.csproj, …
468 > dotnet run Make/build.cs --test
469 ```
470
471 ### 5.7 Propagation policy
472
473 By default a dependent package gets a **patch** bump. If the developer has
474 already raised a dependent's version in the manifest, for example to a new
475 minor version for an API change, that manual version wins and the package is
476 not bumped again.
477
478 This applies to **all** dependents, including the **providers**: they depend on
479 NDOInterfaces through a PackageReference, so a change of NDOInterfaces bumps
480 every provider.
481
482 The dependency in the produced nuspec is a *minimum* version ( `>= x`) .
483 Bumping the dependent is still necessary. It guarantees that
484 the published dependent package is a new artifact that points to the new
485 dependency, and that old consumers don't receive a changed package under an
486 unchanged version.
487
488 ## 6. Migration Steps
489
490 1. **Create the manifest** `Make/packages.json` from the current project versions (2.1, 2.2). ✔
491 2. **Implement the script** `Make/build.cs`. A first `--dry-run` without
492 ·· manual changes reports no version changes, only format normalizations. ✔
493 3. **Unify version formats.** 4-part Assembly/FileVersion, 3-part Version;
494 ·· done automatically on the first patch run. ✔
495 4. **Remove the copy targets.** The `cmd copy` `PostBuild` targets are gone;
496 ·· the script collects the packages. ✔
497 5. **Add a `nuget.config`** at the repository root with `BuiltPackages` as a
498 relative package source. The stale user-level source `NDO` has been removed
499 ·· from the user's `NuGet.Config`. ✔
500 6. **Retire the old build.** `Make/NDO.proj` and `Tools/PatchNdoVersion` are deleted. ✔
501 6b. **PackageReferences between package projects.** The ProjectReferences
502 ·· between the package projects (and from NDOEnhancer to the core packages) are
503 ·· replaced by PackageReferences (2.3). ✔
504 7. **Optional: Central Package Management.** Introduce `Directory.Packages.props`
505 ·· for the NDO package versions used by consumers.
506 8. **Optional: modernize legacy projects.** Convert `NDOEnhancer.BuildTask` to
507 ·· SDK-style so that the build needs no Visual Studio installation.
508
509 ## 7. Decisions
510
511 - **Package projects reference each other through PackageReferences, test
512 ··projects preferably through ProjectReferences** (2.3). A package is built
513 ··against released versions of its dependencies; tests see source changes
514 ··immediately where they reference the projects.
515 - **Consumers always reference the version being built.** This applies to test
516 ··projects, tools and package projects that consume other NDO packages (e.g.
517 NDO. dll → NDOInterfaces, NDO. JsonFormatter → ndo. dll, and therefore
518 ··FormatterUnitTests). Their
519 ··PackageReferences are set to the manifest version on every run. A package
520 ··whose references were updated is rebuilt. Existing ProjectReferences, as in
521 ··the NDODLL tests, stay; they always build against the current source. After
522 ··the packages, the build compiles the affected test projects and, with
523 ··`--test`, runs them. Projects that must stay on an old version are `pinned`.
524 - **Provider propagation** takes place. Providers are bumped when NDOInterfaces changes (5.7).
525 - **VSIX** is not part of the build (1).
526 - **Pre-release versions** are not supported (1).
527
528 ## 8. Known Issues
529
530 These consumers fail for reasons outside the build script:
531
532 - `NDOEnhancer/PersistentEnhancerTestClasses` is multi-targeted. Its `<Exec>`
533 ··task runs `AfterTargets="Build"` in the outer build, where `$(TargetFramework)`
534 ··is empty, and the enhancer exits with code 3.
535 - `UnitTestGenerator/UnitTests` uses the `NDO.Build` package. Its
536 ··`NDOEnhancer.BuildTask.dll` references `Microsoft.Build.Utilities.v4.0`, which
537 ··can't be loaded by `dotnet build` (.NET MSBuild). Projects using NDO.Build can
538 ··currently only be built with Visual Studio. Converting `NDOEnhancer.BuildTask`
539 ··to an SDK-style project with `Microsoft.Build.Utilities.Core` (migration step 8)
540 ··solves this for package consumers as well.
541 - `IntegrationTests/IntegrationTests` calls `Logger.ClearTestLogs()`, which the
542 ··only published version of `Formfakten.TestLogger` (1.0.0) doesn't contain.
543 ··A newer TestLogger version is needed.
544