Skip to content

Declare the Sdk element in Microsoft.Build.Core.xsd - #14637

Merged
ViktorHofer merged 3 commits into
mainfrom
copilot/fix-sdk-element-omission
Aug 4, 2026
Merged

Declare the Sdk element in Microsoft.Build.Core.xsd#14637
ViktorHofer merged 3 commits into
mainfrom
copilot/fix-sdk-element-omission

Conversation

Copilot AI commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Context

Microsoft.Build.Core.xsd declares an Sdk attribute on Project and Import, but never declares the Sdk element. Visual Studio therefore offers no IntelliSense for <Sdk /> or its Name/Version/MinimumVersion attributes, even though MSBuild fully supports the element and translates it into implicit imports.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Sdk Name="Microsoft.NET.Sdk" />   <!-- no completion, no attribute hints -->
</Project>

Changes Made

  • New SdkType complex typeName (required, non_empty_string), Version and MinimumVersion (optional), mirroring ProjectSdkElement and ProjectRootElement.GetImplicitImportNodes.
  • Referenced Sdk from TargetOrImportType and ProjectLevelTagType — the Project content model requires at least one Target/Import, so membership in TargetOrImportType is what makes a project whose only child is <Sdk /> valid. Consistent with <Sdk> lowering to implicit imports.
  • Deliberately not added to ProjectLevelTagExceptTargetOrImportType — the Project model is A* B C*; putting Sdk in both A and B makes it non-deterministic and the schema fails to compile (UPA violation).

Testing

Two tests in ProjectSchemaValidationHandler_Tests.cs: a project using Sdk elements (with all attributes, multiple elements, interleaved with Target) validates; an Sdk element missing Name is rejected.

Those tests are gated on FEATURE_XML_SCHEMA_VALIDATION (net472/Windows), so the schema was additionally exercised on Linux via a standalone XmlSchemaSet harness: the schema set compiles without UPA errors, the cases above behave as expected, and existing shapes (Target-only, Sdk attribute on Project) still validate.

Notes

Schema changes here need to be mirrored into the internal VS repo — see src/MSBuild/Update-MSBuildXsds.ps1 and documentation/wiki/Interactions-with-the-internal-repository.md.

_locID_text comments follow the existing localization convention in the file.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hello @copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

Copilot AI linked an issue Aug 4, 2026 that may be closed by this pull request
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Microsoft.Build.Core.xsd to include Sdk element Declare the Sdk element in Microsoft.Build.Core.xsd Aug 4, 2026
Copilot AI requested a review from ViktorHofer August 4, 2026 13:11
@ViktorHofer
ViktorHofer marked this pull request as ready for review August 4, 2026 13:34
Copilot AI review requested due to automatic review settings August 4, 2026 13:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds explicit <Sdk /> element support to the MSBuild core XSD so editors (notably Visual Studio) can provide IntelliSense for SDK-style projects, aligning the schema with MSBuild’s existing behavior of lowering <Sdk /> to implicit imports.

Changes:

  • Extends Microsoft.Build.Core.xsd to declare an Sdk element and a corresponding SdkType (with Name, Version, MinimumVersion attributes).
  • Updates the schema’s project-level content model groups so <Sdk /> is allowed (including as the required “at least one …” member via TargetOrImportType).
  • Adds unit tests validating that projects with <Sdk /> elements validate, and that missing required Name is rejected.
Show a summary per file
File Description
src/MSBuild/MSBuild/Microsoft.Build.Core.xsd Declares SdkType and allows <Sdk /> in the relevant project-level schema groups.
src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs Adds schema-validation tests for valid/invalid <Sdk /> element usage.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs
Removed the Build target from the test project schema.
@ViktorHofer
ViktorHofer requested a review from AR-May August 4, 2026 14:30
@ViktorHofer
ViktorHofer merged commit 17a094d into main Aug 4, 2026
12 checks passed
@ViktorHofer
ViktorHofer deleted the copilot/fix-sdk-element-omission branch August 4, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft.Build.Core.xsd omits Sdk element

4 participants