diff --git a/docs/Diagnostics.md b/docs/Diagnostics.md new file mode 100644 index 0000000..55ba66a --- /dev/null +++ b/docs/Diagnostics.md @@ -0,0 +1,51 @@ +# Diagnostics (message IDs) + +Messages emitted by `MSBuild.SDK.SystemWeb` use the `SYSWEB` prefix followed by a number. +This page is the central registry of those messages. + +| ID | Severity | Meaning | +|----|----------|---------| +| `SYSWEB000` | Error | Invalid value for the `MissingWebApplicationsTargetPathAction` property (expected `Ignore`, `Skip`, `Warn` or `Error`). | +| `SYSWEB001` | Error / Warning / message | `Microsoft.WebApplication.targets` could not be resolved at `$(WebApplicationsTargetPath)`. Configurable via the `MissingWebApplicationsTargetPathAction` property — see below. | + +## `MissingWebApplicationsTargetPathAction` + +`Microsoft.WebApplication.targets` ships with Visual Studio / the Visual Studio Build Tools, not with +the .NET SDK. When building with the `dotnet` CLI (Core MSBuild), `$(MSBuildExtensionsPath32)` points at +the .NET SDK rather than a Visual Studio install, so the default `$(WebApplicationsTargetPath)` may not +exist and the build would otherwise fail with a cryptic `MSB4019`. + +The `MissingWebApplicationsTargetPathAction` property controls what happens when that file cannot be found: + +| Value | Behaviour | +|-------|-----------| +| `Ignore` | Do nothing. | +| `Skip` | Emit a high-importance informational message (`SYSWEB001`). | +| `Warn` | Emit a warning (`SYSWEB001`). | +| `Error` | Emit an error and fail the build (`SYSWEB001`). **Default.** | + +> With `Ignore`, `Skip` or `Warn` the build continues **without** importing `Microsoft.WebApplication.targets`. +> For a real web project, later targets that depend on it may still fail. These options are intended for +> scenarios where the web targets are genuinely not needed. + +### How to resolve a missing `Microsoft.WebApplication.targets` + +- Install Visual Studio, or the Visual Studio Build Tools, with the **web development build tools** workload. +- Build from a **Visual Studio Developer command prompt** (which sets the correct environment). +- Set `VSToolsPath` (or `WebApplicationsTargetPath`) explicitly, e.g. computed via + [vswhere](https://github.com/microsoft/vswhere) in a CI pre-build step: + +```xml + + + C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0 + +``` + +To opt out of the failure instead: + +```xml + + Warn + +``` diff --git a/docs/README.md b/docs/README.md index 6916138..a259950 100644 --- a/docs/README.md +++ b/docs/README.md @@ -83,6 +83,9 @@ At evaluation time, MSBuild adds implicit imports at the top and bottom of the p # Useful Information +## Diagnostics +- [Message IDs and the `MissingWebApplicationsTargetPathAction` property](Diagnostics.md) + ## Binding Redirects - [How to show Suggested Binding Redirects](Binding_Redirects/How-to-show-Suggested-Binding-Redirects.md) - [Autogenerating Binding Redirects](Binding_Redirects/Autogenerating-Binding-Redirects.md) diff --git a/src/MSBuild.SDK.SystemWeb/Sdk/Sdk.targets b/src/MSBuild.SDK.SystemWeb/Sdk/Sdk.targets index d7b0dbd..30eaf79 100644 --- a/src/MSBuild.SDK.SystemWeb/Sdk/Sdk.targets +++ b/src/MSBuild.SDK.SystemWeb/Sdk/Sdk.targets @@ -15,6 +15,7 @@ 15.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) $(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets + Error @@ -25,5 +26,26 @@ - + + + + + + + <_SystemWebMissingWebTargetsText>SYSWEB001: 'Microsoft.WebApplication.targets' was not found at '$(WebApplicationsTargetPath)'. Install Visual Studio or the Visual Studio Build Tools with the "web development build tools" workload, build from a Visual Studio Developer command prompt, or set the 'VSToolsPath' (or 'WebApplicationsTargetPath') property to a valid Visual Studio tools path. Use the 'MissingWebApplicationsTargetPathAction' property (Ignore | Skip | Warn | Error) to control this behaviour. + + + + + + + + + +