Skip to content

Commit dcbb113

Browse files
committed
add module base bundling readme
1 parent 2523385 commit dcbb113

1 file changed

Lines changed: 102 additions & 1 deletion

File tree

ModuleBase/README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,105 @@ public class ExampleDesktopModule : DesktopModuleBase
3030

3131

3232

33-
Or see the example module on how to use it.
33+
Or see the example module on how to use it.
34+
35+
## Module Packaging (`.module.zip`)
36+
37+
Starting with `OpenShock.Desktop.ModuleBase` 1.1.3, the NuGet package ships MSBuild
38+
targets that automatically produce a ready-to-install `*.module.zip` bundle when you
39+
publish your module. Adding the package reference is enough — no extra tooling, no
40+
custom scripts.
41+
42+
### How it works
43+
44+
On `dotnet publish`, the `PackOpenShockModule` target runs after `Publish` and writes
45+
`<AssemblyName>.module.zip` into the publish directory with this layout:
46+
47+
```
48+
<AssemblyName>.dll # your module entry point (+ .pdb if present)
49+
libs/
50+
*.dll # third-party deps the host does NOT already provide
51+
<rid>/… # native + RID-specific files copied from runtimes/
52+
```
53+
54+
Assemblies the host already ships (MudBlazor, Serilog, the MAUI/Blazor stack,
55+
OpenShock SDKs, `Microsoft.Extensions.*`, etc.) are **excluded automatically** so
56+
your ZIP stays small and you don't risk loading a second copy at runtime. The
57+
authoritative list lives in
58+
[`OpenShock.Desktop.ModuleBase.targets`](build/OpenShock.Desktop.ModuleBase.targets)
59+
as `OpenShockHostAssembly` items.
60+
61+
### Opting in / out
62+
63+
Packaging is on by default once you reference the NuGet package. To disable it for
64+
a specific project, set:
65+
66+
```xml
67+
<PropertyGroup>
68+
<OpenShockPackModule>false</OpenShockPackModule>
69+
</PropertyGroup>
70+
```
71+
72+
You can also customize:
73+
74+
| Property | Default | Purpose |
75+
| --- | --- | --- |
76+
| `OpenShockModuleId` | `$(AssemblyName)` | Stable module identifier used by the host. Set this to a reverse-DNS id like `openshock.desktop.modules.mymodule`. |
77+
| `OpenShockModuleOutputDir` | `$(PublishDir)` | Where to drop the `.module.zip`. |
78+
79+
### Overriding a host-provided dependency
80+
81+
If your module genuinely needs a different version of something the host provides,
82+
force it to be bundled:
83+
84+
```xml
85+
<ItemGroup>
86+
<OpenShockBundleOverride Include="Newtonsoft.Json" />
87+
</ItemGroup>
88+
```
89+
90+
The override will be copied into `libs/` alongside your other dependencies. Use this
91+
sparingly — the host may still reject your module if the mismatch affects a type it
92+
hands you across the API boundary.
93+
94+
### Shipping extra files (native sidecars, assets)
95+
96+
If your publish output contains directories you need at runtime (e.g. `x64/` with
97+
native DLLs), list them with `OpenShockExtraDir`:
98+
99+
```xml
100+
<ItemGroup>
101+
<OpenShockExtraDir Include="x64" />
102+
</ItemGroup>
103+
```
104+
105+
Each listed directory is copied under `libs/<name>/…` in the final ZIP.
106+
107+
### Version-mismatch diagnostics (`OSMOD001`)
108+
109+
After publish, the target scans your `deps.json` and compares dependency versions
110+
against the host's declared versions. A **major-version mismatch** emits MSBuild
111+
warning `OSMOD001` at build time, e.g.:
112+
113+
```
114+
warning OSMOD001: Module references MudBlazor 8.0.0 but host provides 9.3.0.
115+
Major version mismatch may cause runtime errors.
116+
```
117+
118+
Treat these as real — major bumps across the host/module boundary almost always
119+
break at load time. Either align to the host version or force-bundle via
120+
`OpenShockBundleOverride` (and accept the duplication).
121+
122+
### `ProjectReference` consumers
123+
124+
If you reference `ModuleBase` as a `ProjectReference` instead of a `PackageReference`
125+
(as the in-repo `ExampleModule` does), MSBuild does not auto-import the NuGet `build/`
126+
assets. Add the imports manually at the top and bottom of the csproj:
127+
128+
```xml
129+
<Import Project="../ModuleBase/build/OpenShock.Desktop.ModuleBase.props" />
130+
<!-- ... PropertyGroup / ItemGroup ... -->
131+
<Import Project="../ModuleBase/build/OpenShock.Desktop.ModuleBase.targets" />
132+
```
133+
134+
NuGet consumers get both imports for free.

0 commit comments

Comments
 (0)