-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add documentation for enabling binlog collection via env var #12805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YuliiaKovalova
wants to merge
7
commits into
main
Choose a base branch
from
dev/ykovalova/binlog_env_var_spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f96d76
Add documentation for enabling binlog collection via env var
YuliiaKovalova e77a44d
Merge branch 'main' into dev/ykovalova/binlog_env_var_spec
YuliiaKovalova 30fb3e8
Merge branch 'main' into dev/ykovalova/binlog_env_var_spec
YuliiaKovalova e7a7da1
fix review comments
YuliiaKovalova 3ed3407
more cleanup
YuliiaKovalova 7758473
fix comments
YuliiaKovalova aa0328a
add more info
YuliiaKovalova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
documentation/specs/enable-binlog-collection-by-env-var.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| # Enable Binary Log Collection via Environment Variable | ||
|
|
||
| ## Purpose | ||
|
|
||
| Enable binary logging in CI/CD pipelines without modifying artifacts on disk. | ||
|
|
||
| **Proposed solution:** An environment variable that enables diagnostic logging without touching any files on disk-no response file creation, no project file modifications, no build script changes. | ||
|
|
||
| **Important for company-wide deployment:** When enabling this feature organization-wide (e.g., via CI/CD pipeline configuration), the team setting the environment variable may not be the team that owns individual codebases. Ensure stakeholders understand that builds with `/warnaserror` may be affected and be ready to mitigate this. | ||
|
|
||
| ### Demoting Warnings to Messages | ||
|
|
||
| For scenarios where warnings would break builds (e.g., `/warnaserror` is enabled), set: | ||
|
|
||
| ```bash | ||
| set MSBUILD_LOGGING_ARGS_LEVEL=message | ||
| ``` | ||
|
|
||
| | Value | Behavior | | ||
| |-------|----------| | ||
| | `warning` (default) | Issues logged as warnings; may fail `/warnaserror` builds | | ||
| | `message` | Issues logged as low-importance messages; never fails builds | | ||
|
|
||
| **Problem scenarios addressed:** | ||
|
|
||
| - `-noAutoResponse` blocks response files entirely | ||
| - Creating `Directory.Build.rsp` requires writing new files to the source tree | ||
| - Modifying existing RSP files risks merge conflicts or unintended side effects | ||
| - Some build environments restrict write access to source directories | ||
|
|
||
| ### Why Not MSBUILDDEBUGENGINE? | ||
|
|
||
| The existing `MSBUILDDEBUGENGINE=1` + `MSBUILDDEBUGPATH` mechanism works but has limitations for the desired CI/CD scenarios: | ||
|
|
||
| - **Excessive logging:** Captures *all* MSBuild invocations including design-time builds, generating many files | ||
| - **No filename control:** Auto-generates filenames; cannot specify output path with `{}` placeholder for unique names | ||
| - **Debug overhead:** Enables additional debugging infrastructure beyond just binary logging | ||
|
|
||
| ## Supported Arguments | ||
|
|
||
| - `-bl` / `/bl` / `-binarylogger` / `/binarylogger` (with optional parameters) | ||
| - `-check` / `/check` (with optional parameters) | ||
|
|
||
| > **Note:** The `deferred` mode for `-check` is not currently supported. Enabling this feature requires changes to the MSBuild codebase. See section "Build Check (-check) Handling" below. | ||
|
|
||
| > **Recommendation:** For CI/CD use, specify an **absolute path** with the `{}` placeholder (e.g., `-bl:C:\BuildLogs\build{}.binlog` or `-bl:/var/log/builds/build{}.binlog`) to generate unique filenames in a known location, avoiding CWD-relative paths that vary by build. | ||
|
|
||
| **All other switches are blocked** to maintain diagnosability. | ||
|
|
||
| ### Rationale | ||
|
|
||
| Environment variables that unexpectedly affect build behavior are notoriously difficult to diagnose (e.g., `Platform` is a known source of build issues). By restricting this environment variable to logging/diagnostic switches only, we ensure it cannot accidentally change build outcomes-only what gets recorded about the build. | ||
|
|
||
| ## Argument Processing Order | ||
|
|
||
| 1. **MSBuild.rsp** (next to MSBuild.exe) - skipped if `-noAutoResponse` present | ||
| 2. **Directory.Build.rsp** (next to project) - skipped if `-noAutoResponse` present | ||
| 3. **MSBUILD_LOGGING_ARGS** - always processed, regardless of `-noAutoResponse` | ||
| 4. **Command-line arguments** | ||
|
|
||
| ### Why Precedence Doesn't Matter Here | ||
|
|
||
| Since `MSBUILD_LOGGING_ARGS` only allows logging switches (`-bl` and `-check`), traditional precedence concerns don't apply: | ||
|
|
||
| - **`-bl` is additive:** Each `-bl` argument creates a separate binlog file (requires [#12706](https://github.com/dotnet/msbuild/pull/12706)). Multiple sources specifying `-bl` simply result in multiple binlog files-there's no conflict to resolve. | ||
|
|
||
| ## Implementation Flow | ||
|
|
||
| 1. `MSBuildApp.Execute()` called | ||
| 2. Check for `-noAutoResponse` in command line | ||
| 3. Process response files (if no `-noAutoResponse`) | ||
| 4. Read `MSBUILD_LOGGING_ARGS` environment variable | ||
| 5. Validate and filter arguments | ||
| 6. Prepend valid arguments to command line | ||
| 7. Parse combined command line (merging happens here) | ||
| 8. Execute build | ||
|
|
||
| ## Scope and Limitations | ||
|
|
||
| ### Supported Entry Points | ||
|
|
||
| This environment variable only affects builds that go through MSBuild's `Main()` entry point: | ||
|
|
||
| | Entry Point | Supported | Notes | | ||
| |-------------|-----------|-------| | ||
| | `MSBuild.exe` | ✅ Yes | | | ||
| | `dotnet build` | ✅ Yes | | | ||
| | `dotnet msbuild` | ✅ Yes | | | ||
| | Visual Studio (IDE builds) | ❌ No | Uses MSBuild API directly | | ||
| | `devenv.exe /build` | ❌ No | Uses MSBuild API directly | | ||
| | MSBuildWorkspace (Roslyn) | ❌ No | Uses MSBuild API directly | | ||
| | Custom build drivers via API | ❌ No | Any direct `Microsoft.Build` API usage | | ||
|
|
||
| ### API-Driven Builds | ||
|
|
||
| For builds that use the MSBuild API directly (including Visual Studio and `devenv.exe /build`), this environment variable has no effect. | ||
|
|
||
| **Alternative:** Use `MSBUILDDEBUGENGINE` to inject binlog collection into API-driven builds. This existing mechanism is already used for debugging Visual Studio builds and works across all MSBuild entry points. | ||
| ```bash | ||
| # For API-driven builds (VS, devenv.exe /build, etc.) | ||
| set MSBUILDDEBUGENGINE=1 | ||
|
|
||
| # For command-line builds (MSBuild.exe, dotnet build) | ||
| set MSBUILD_LOGGING_ARGS=-bl:build{}.binlog | ||
| ``` | ||
|
|
||
| ## Warning Messages | ||
|
|
||
| Issues are logged as **warnings** by default. Note that users with `/warnaserror` enabled will see these as errors-by opting into this environment variable, users also opt into these diagnostics. | ||
|
|
||
| ### Messages | ||
|
|
||
| - **Informational:** "Using arguments from MSBUILD_LOGGING_ARGS environment variable: {0}" - build continues with arguments applied | ||
| - **Unsupported argument:** "MSBUILD_LOGGING_ARGS: Ignoring unsupported argument '{0}'. Only -bl and -check arguments are allowed." - the specific invalid argument is skipped, other valid arguments in the same env var are still processed (e.g., `-bl:a.binlog -maxcpucount:4` → `-bl:a.binlog` is applied, `-maxcpucount:4` is ignored with warning) | ||
| - **Malformed input:** "Error processing MSBUILD_LOGGING_ARGS environment variable: {0}" - the entire environment variable is skipped to avoid partial/unpredictable behavior, build proceeds as if the env var was not set | ||
|
|
||
| ## Build Check (-check) Handling | ||
|
|
||
| ### Deferred Analysis Mode | ||
|
|
||
| `-check:deferred` enables binlog replay analysis with reduced build-time overhead: | ||
|
|
||
| - **During build:** Flag recorded in binlog along with additional data needed for checks; BuildCheck NOT activated | ||
| - **During replay:** Binlog reader activates BuildCheck for analysis | ||
|
|
||
| **Rationale:** BuildCheck analysis can be expensive and checks can fail the build. The environment variable is for diagnostics that can be analyzed later, allowing teams to record data with minimal impact to the build itself. | ||
|
|
||
| ### Example Workflow | ||
| ```bash | ||
| # 1. Configure environment | ||
| set MSBUILD_LOGGING_ARGS=-bl:build{}.binlog -check:deferred | ||
|
|
||
| # 2. Run build (reduced overhead, no BuildCheck analysis during build) | ||
| msbuild solution.sln | ||
|
|
||
| # 3. Later: Replay binlog (BuildCheck analyzes recorded events) | ||
| msbuild build{}.binlog | ||
| ``` | ||
|
|
||
| ## CI/CD Integration | ||
|
|
||
|
|
||
| ### Environment Variable | ||
|
|
||
| - Set `MSBUILD_LOGGING_ARGS=-bl:build{}.binlog` | ||
| - No file creation needed | ||
| - The `{}` placeholder generates unique filenames for each build invocation | ||
|
|
||
| ### Combining Both Approaches | ||
| ```bash | ||
| # Environment provides base logging | ||
| set MSBUILD_LOGGING_ARGS=-bl:base{}.binlog -check:deferred | ||
|
|
||
| # Command line adds specific logging | ||
| msbuild solution.sln -bl:detailed.binlog | ||
|
|
||
| # Result: Two binlog files created (base{...}.binlog + detailed.binlog) | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.