You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Always use `pwsh -NoProfile`** to spawn a fresh process. This avoids DLL locking from your current session and ensures a clean module load. Import `dbatools.library`from the local repo FIRST so it satisfies the `RequiredModules` dependency before dbatools loads.
43
+
**Always use `pwsh -NoProfile`** to spawn a fresh process. For the baseline, the installed `dbatools.library`module is fine — a fresh process won't have the DLL locked even if another session does.
45
44
46
45
Record the pass/fail/skip counts. If no test file exists at `c:\github\dbatools-ralph\tests\{CommandName}.Tests.ps1`, note "No Pester tests" and continue — Pester testing steps later will be skipped.
47
46
@@ -141,40 +140,36 @@ if (ShouldProcess(target, String.Format("Removing {0}", name)))
141
140
142
141
### 5. Build and Deploy
143
142
143
+
#### Compile
144
+
144
145
```bash
145
146
dotnet build project/dbatools/dbatools.csproj
146
147
```
147
148
148
149
If it fails, fix errors and rebuild. Do not proceed until the build succeeds.
149
150
150
-
#### Deploy the built DLL for testing
151
+
#### Dev-build a loadable module
151
152
152
-
After a successful build, copy the compiled DLL to the local module staging directory so that Pester tests can load it. The installed module at `C:\Program Files\PowerShell\Modules\dbatools.library\` may be locked by another PowerShell session — **never fight the lock**. Always deploy to the local repo path instead.
153
+
The installed `dbatools.library` at `C:\Program Files\PowerShell\Modules\` may be locked by another session. **Never fight the lock.** Instead, build a complete loadable module into `artifacts/dbatools.library/` using the dev-build script:
153
154
154
155
```bash
155
-
# Create staging dirs if they don't exist
156
-
mkdir -p c:/github/dbatools.library/core/lib
157
-
mkdir -p c:/github/dbatools.library/desktop/lib
158
-
159
-
# Copy net8.0 build output to local staging (for PS Core / PS 7+)
These paths are gitignored (`lib/` is in `.gitignore`). The `dbatools.library.psm1` loads from `$PSScriptRoot/core/lib/` or `$PSScriptRoot/desktop/lib/`, so when importing from the local repo path, it will find the freshly built DLL.
159
+
This runs `dotnet publish` (which includes all ~142 dependency DLLs — SMO, SqlClient, etc.), copies them alongside the freshly built `dbatools.dll`, and adds the module manifest/loader. The output at `artifacts/dbatools.library/` is a fully self-contained, loadable module.
160
+
161
+
The `artifacts/` directory is gitignored.
167
162
168
-
#### Load the local module for Pester testing
163
+
#### Load the dev-built module for Pester testing
169
164
170
-
When running Pester tests, import `dbatools.library` from the local repo FIRST so it takes precedence over the installed version:
165
+
When running Pester tests, **always spawn a fresh `pwsh -NoProfile` process** and import the dev-built library FIRST:
The `-Force` on the library import ensures it replaces any previously loaded version. Doing this BEFORE importing dbatools-ralph satisfies the `RequiredModules` dependency with the local build.
172
+
Loading the dev-built library first satisfies dbatools-ralph's `RequiredModules = 'dbatools.library'` dependency with the freshly built version, so it won't try to load the installed (potentially locked) copy.
**This step is MANDATORY if a Pester test file exists.** Skip only if Step 0 noted "No Pester tests."
375
370
376
-
Spawn a fresh PowerShell process to pick up the C# cmdlet (the PS1 is now archived). Import the local`dbatools.library` first so the freshly built DLL is loaded:
371
+
Spawn a fresh PowerShell process to pick up the C# cmdlet (the PS1 is now archived). Import the **dev-built**`dbatools.library`(from Step 5) first so the freshly built DLL with your new cmdlet is loaded:
**Always use `pwsh -NoProfile`** — never test in the current session where the installed DLL may be locked or a stale module is loaded.
382
+
**Always use `pwsh -NoProfile`** — never test in the current session where the installed DLL may be locked or a stale module is loaded. The dev-built module at `artifacts/dbatools.library/` contains your freshly compiled `dbatools.dll` plus all dependency DLLs.
388
383
389
384
Compare results against the Pester baseline from Step 0:
390
385
-**All tests that passed in the baseline MUST still pass.** A previously-passing test that now fails is a regression in your C# implementation.
0 commit comments