Commit 9ba8f3e
Log SDK environment variable messages only when values differ (#12918)
### Context
Structured log viewer was cluttered with repeated non-actionable
messages about SDK environment variables (e.g., `DOTNET_HOST_PATH`).
These appeared for every project evaluation, reporting normal SDK
behavior without providing value to users.
### Changes Made
Modified `ProjectInstance.AddSdkResolvedEnvironmentVariable()` to only
log messages when an SDK attempts to set an environment variable to a
**different value** than what's already set:
- **When values match** (common case): No message is logged, eliminating
the clutter shown in the original issue
- **When values differ** (conflict): A low-importance message is logged
showing both the attempted value and the existing value for diagnostic
purposes
- **Code refactoring**: Extracted duplicate value comparison and logging
logic into a helper method `LogIfValueDiffers` to improve code
maintainability
Updated string resources in `Strings.resx` and all 13 localized `.xlf`
files:
- `SdkEnvironmentVariableAlreadySet`: Now includes both attempted and
existing values in the message
- `SdkEnvironmentVariableAlreadySetBySdk`: Now includes both attempted
and existing values in the message
- Removed `SdkEnvironmentVariableSet` (no longer logging successful
sets)
The underlying functionality is unchanged—environment variables are
still tracked and set correctly, and properties remain visible in the
structured log viewer.
### Testing
- Built MSBuild successfully
- Verified messages no longer appear when values are the same (common
case)
- Messages would appear when values differ (preserves diagnostic value
for conflicts)
- Confirmed existing unit tests pass
- Verified sample projects build successfully
- Confirmed properties are still visible in structured log viewer
(DOTNET_HOST_PATH, etc.)
### Notes
This implementation balances two concerns:
1. **Eliminates noise**: Repeated messages about the same value being
set multiple times no longer clutter logs
2. **Preserves diagnostics**: Actual conflicts (different values) are
still logged with full context (both values shown)
The messages log at `MessageImportance.Low` to provide diagnostic
information without being intrusive in normal builds. Code quality was
improved by extracting duplicate logic into a reusable helper method.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Duplicated messages from SDK/environment
resolution</issue_title>
> <issue_description><img width="2860" height="1772" alt="Image"
src="https://github.com/user-attachments/assets/f4d4871f-28e9-4cb5-9f58-42c4a0056979"
/>
>
> There are a ton of these `An SDK attempted to set the environment
variable "DOTNET_HOST_PATH"` messages that aren't particularly helpful,
and they're not attributed to a project so they clutter up the top level
of the viewer tool.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #12915
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: YuliiaKovalova <[email protected]>1 parent 49a6fd4 commit 9ba8f3e
File tree
15 files changed
+81
-125
lines changed- src/Build
- Instance
- Resources
- xlf
15 files changed
+81
-125
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1390 | 1390 | | |
1391 | 1391 | | |
1392 | 1392 | | |
1393 | | - | |
| 1393 | + | |
1394 | 1394 | | |
1395 | 1395 | | |
1396 | 1396 | | |
1397 | 1397 | | |
1398 | 1398 | | |
1399 | | - | |
| 1399 | + | |
1400 | 1400 | | |
1401 | 1401 | | |
1402 | 1402 | | |
| |||
1412 | 1412 | | |
1413 | 1413 | | |
1414 | 1414 | | |
| 1415 | + | |
1415 | 1416 | | |
1416 | | - | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
1417 | 1427 | | |
1418 | 1428 | | |
1419 | 1429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1384 | 1384 | | |
1385 | 1385 | | |
1386 | 1386 | | |
1387 | | - | |
| 1387 | + | |
1388 | 1388 | | |
1389 | 1389 | | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
1393 | | - | |
| 1390 | + | |
1394 | 1391 | | |
| 1392 | + | |
1395 | 1393 | | |
1396 | 1394 | | |
1397 | 1395 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments