Datei: nuget/Concept.md

Last Commit (f9304e5)
1 -- File didn't exist --
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
New Commit (7d77e26)
1 # Packing NDO.Build with `dotnet pack` instead of NuGet.exe
2
3 ## Problem
4
5 `Make/build.cs` (`BuildPackage`) creates the NDO.Build package by calling
6 `nuget/NuGet.exe pack NDO.Build.nuspec`. NuGet.exe is a Windows executable and
7 doesn't work on Linux.
8
9 ## Solution
10
11 `dotnet pack` can't process a `.nuspec` file directly; it needs a project.
12 A minimal helper project that doesn't compile anything and just points to the
13 nuspec solves this. This was tested on Linux with the .NET 11 SDK: the
14 resulting `NDO.Build.<version>.nupkg` has the same structure as described in
15 the nuspec (`build/**` with the enhancer output, `build/NDO.Build.targets`,
16 `license/license.txt`, `readme.md`).
17
18 ### Helper project `nuget/NDO.Build.Pack.csproj`
19
20 ```xml
21 <Project Sdk="Microsoft.NET.Sdk">
22 ··<!-- Only used to pack NDO.Build.nuspec with "dotnet pack". -->
23 ··<PropertyGroup>
24 ····<TargetFramework>netstandard2.0</TargetFramework>
25 ····<IncludeBuildOutput>false</IncludeBuildOutput>
26 ····<NoBuild>true</NoBuild>
27 ····<NuspecFile>NDO.Build.nuspec</NuspecFile>
28 ··</PropertyGroup>
29 </Project>
30 ```
31
32 - The project is named after the nuspec (`<nuspec name>.Pack.csproj`), so
33 ··`build.cs` can derive the name from `p.Project` and further nuspec packages
34 ··can be added the same way.
35 - `TargetFramework` is `netstandard2.0`, because nothing is compiled. This way
36 ··the file doesn't need to be touched when the .NET version changes.
37 - csproj and nuspec are in the same directory, so relative paths work and the
38 ··nuspec base path is `nuget/`, as expected by the `src` attributes.
39
40 ### Change in `Make/build.cs` (`BuildPackage`)
41
42 Replace the NuGet.exe call with:
43
44 ```csharp
45 if (p.Builder == "nuget")
46 {
47 ····var dir = Path.GetDirectoryName(p.Project)!;
48 ····var packProject = Path.GetFileNameWithoutExtension(p.Project) + ".Pack.csproj";
49 ····Exec("dotnet", dir, "pack", packProject, "-o", packageSource);
50 ····if (!System.IO.File.Exists(Path.Combine(packageSource, $"{p.Id}.{p.Target}.nupkg")))
51 ········throw new BuildException($"dotnet pack didn't produce {p.Id}.{p.Target}.nupkg.");
52 ····return;
53 }
54 ```
55
56 The version doesn't have to be passed: `PatchProducers` already writes the
57 target version into the nuspec's `<version>` element. (`NuspecProperties`
58 would only replace `$version$` tokens anyway.)
59
60 ### Required fix in `NDO.Build.nuspec`
61
62 Linux file systems are case sensitive. The nuspec references
63 `..\NDOEnhancer\NDOEnhancer\bin\release\net11.0\**`, but the directory is
64 `bin/Release`. Packing fails with:
65
66 ```
67 Could not find a part of the path '.../NDOEnhancer/NDOEnhancer/bin/release/net11.0'
68 ```
69
70 Change the path to `..\NDOEnhancer\NDOEnhancer\bin\Release\net11.0\**`.
71 Backslashes and the leading `/` in `target="/build"` work fine on Linux.
72
73 ## Side effects checked
74
75 - `ScanProjects()` in `build.cs` finds the helper project (it scans all
76 ··`*.csproj`). This is harmless: `PatchConsumers` only touches
77 ··`PackageReference` versions and `PatchEnhancer` only NDOEnhancer paths;
78 ··neither occurs in the helper project.
79 - There are no `Directory.Build.props/targets` in the repository or in parent
80 ··directories, so nothing is imported unintentionally.
81 - `dotnet pack` creates `nuget/obj/`, which is already covered by `.gitignore`.
82
83 ## Optional follow-ups
84
85 - Rename `"builder": "nuget"` in `Make/packages.json` (e.g. to `"nuspec"`),
86 ··since NuGet.exe is no longer used.
87 - Remove `nuget/NuGet.exe` from the repository.
88