| name | authoring-errors-and-warnings |
| description | Guides authoring of MSBuild errors, warnings, and diagnostic messages. Consult when adding new MSBxxxx codes, writing or modifying user-facing diagnostic text, deciding between error/warning/message severity, working with Strings.resx resource files, formatting paths in error output, or evaluating whether a new warning could break WarnAsError builds. |
| argument-hint | Describe the error/warning being added or modified. |
Error and Warning Authoring in MSBuild
Error messages are MSBuild's primary user interface. They must help developers fix problems without reading source code.
For the mechanics of error code assignment, see assigning-msb-error-code.md.
Error Message Quality Rules
Every error message must answer three questions:
- What happened? ā State the problem clearly
- Why? ā Provide context (file, property, expected value)
- What should the user do? ā Give actionable guidance
<value>MSB4999: Invalid configuration.</value>
<value>MSB4999: The project "{0}" specifies TargetFramework "{1}" which is not installed. Install the SDK for "{1}" or update the TargetFramework in the project file.</value>
Severity Decision Framework
Is the condition always wrong (invalid input, impossible state)?
āāā Yes ā ERROR (build should fail)
āāā No
āāā Could this cause subtle build correctness issues?
ā āāā Yes, likely ā WARNING (but see WarnAsError impact below)
ā āāā Yes, maybe ā MESSAGE at Normal importance
āāā Is this purely informational?
āāā Yes ā MESSAGE at Low importance
The WarnAsError Constraint
New warnings are breaking changes for builds using:
-WarnAsError (CLI)
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> (project)
<WarningsAsErrors>MSBxxxx</WarningsAsErrors> (specific codes)
Before adding a new warning, consider:
- Is the warning important enough to justify breaking WarnAsError builds? If yes, gate behind a ChangeWave (see changewaves skill).
- Could this be a Message instead? Messages never break builds but still appear in binary logs.
- Should this be an error from the start? If the condition is always wrong, skip the warning stage.
MSB Error Code Assignment
Code Ranges
| Range | Area |
|---|
MSB1xxx | Command-line handling |
MSB3xxx | Tasks (Microsoft.Build.Tasks.Core.dll) |
MSB4xxx | Engine (Microsoft.Build.dll) |
MSB5xxx | Shared code across assemblies |
MSB6xxx | Utilities (Microsoft.Build.Utilities) |
Assignment Process
- Open the
Strings.resx file for the appropriate assembly
- Find the "Next message code" comment at the bottom of the file
- Search the repo to confirm the code is not already in use
- Use the code; update the comment to the next available number
See assigning-msb-error-code.md for detailed steps.
Resource String Format
<data name="FeatureArea.DescriptiveName">
<value>MSBxxxx: Clear description with {0} placeholders for runtime values.</value>
<comment>{StrBegin="MSBxxxx: "}{0} is the project file path. {1} is the property name.</comment>
</data>
Rules
- Resource name uses
FeatureArea.DescriptiveName convention
- Value starts with
MSBxxxx: (code, colon, space)
- Comment documents the
{StrBegin} marker and explains each {N} placeholder
- Comments guide translators ā mention untranslatable tokens
Consuming Error Resources in Code
Use the standard formatting method that extracts and applies the error code:
Log.LogErrorWithCodeFromResources("Copy.Error", sourceFile, destFile, ex.Message);
Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.Conflict", assemblyName);
ProjectFileErrorUtilities.ThrowInvalidProjectFile(
elementLocation,
"InvalidProjectFile",
arg1, arg2);
Never construct error messages by string concatenation ā always use resource strings for localization support.
Localization Requirements
- Error codes (
MSBxxxx) are never localized
- Error text is localized into all supported languages
- After adding/modifying resource strings, run a full build to generate
.xlf placeholder translations
- Use
<comment> elements to help translators understand context
- See Localization.md for the full localization process
Path Formatting in Error Messages
- Show paths relative to the project directory when possible
- Use the path exactly as the user specified it (don't normalize slashes)
- Include file and line number via
IElementLocation when available ā this enables IDE click-to-navigate
- For paths that could contain spaces, ensure they're quoted in the message
Checklist for New Errors/Warnings