diff --git a/src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs b/src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs
index 82fa56a588c..371d94533e4 100644
--- a/src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs
+++ b/src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs
@@ -11,6 +11,7 @@
using Microsoft.Build.CommandLine;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
+using Shouldly;
using Xunit;
#nullable disable
@@ -275,6 +276,63 @@ public void VerifyInvalidImportNotCaughtBySchema()
}
}
+ ///
+ /// The Sdk element is a valid child of Project (it is translated into implicit imports),
+ /// so a project consisting of nothing but an Sdk element must validate against the schema.
+ ///
+ [Fact]
+ public void VerifyValidSdkElementSchema()
+ {
+ string[] msbuildTempXsdFilenames = Array.Empty();
+ string projectFilename = CreateTempFileOnDisk(@"
+
+
+
+
+ ");
+
+ try
+ {
+ // Create schema files in the temp folder
+ msbuildTempXsdFilenames = PrepareSchemaFiles();
+
+ Should.NotThrow(() => ProjectSchemaValidationHandler.VerifyProjectSchema(projectFilename, msbuildTempXsdFilenames[0], Path.GetTempPath()));
+ }
+ finally
+ {
+ File.Delete(projectFilename);
+ CleanupSchemaFiles(msbuildTempXsdFilenames);
+ }
+ }
+
+ ///
+ /// The Name attribute is required on the Sdk element, so omitting it must be
+ /// caught by the schema.
+ ///
+ [Fact]
+ public void VerifyInvalidSdkElementSchema()
+ {
+ string[] msbuildTempXsdFilenames = Array.Empty();
+ string projectFilename = CreateTempFileOnDisk(@"
+
+
+
+ ");
+
+ try
+ {
+ // Create schema files in the temp folder
+ msbuildTempXsdFilenames = PrepareSchemaFiles();
+
+ Should.Throw(() => ProjectSchemaValidationHandler.VerifyProjectSchema(projectFilename, msbuildTempXsdFilenames[0], Path.GetTempPath()));
+ }
+ finally
+ {
+ File.Delete(projectFilename);
+ CleanupSchemaFiles(msbuildTempXsdFilenames);
+ }
+ }
+
#pragma warning disable format // region formatting is different in net7.0 and net472, and cannot be fixed for both
#region Helper Functions
diff --git a/src/MSBuild/MSBuild/Microsoft.Build.Core.xsd b/src/MSBuild/MSBuild/Microsoft.Build.Core.xsd
index 28a5a819acc..eae2b9b1ca1 100644
--- a/src/MSBuild/MSBuild/Microsoft.Build.Core.xsd
+++ b/src/MSBuild/MSBuild/Microsoft.Build.Core.xsd
@@ -56,6 +56,7 @@
+
@@ -65,6 +66,7 @@
+
@@ -404,6 +406,27 @@
+
+
+ Declares that the project should be built with the specified MSBuild SDK, by implicitly importing its Sdk.props at the top and its Sdk.targets at the bottom of the project
+
+
+
+ Name of the SDK this project should be built with
+
+
+
+
+ Optional expression used to specify the version of the SDK referenced by this element
+
+
+
+
+ Optional expression used to specify the minimum SDK version required by this element
+
+
+
+
Optional section used by MSBuild hosts, that may contain arbitrary XML content that is ignored by MSBuild itself