diff --git a/Directory.Packages.props b/Directory.Packages.props
index 85fe7e401ea..929be817ab8 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -10,14 +10,6 @@
-
-
-
-
-
-
-
-
@@ -31,6 +23,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Docfx.Dotnet/Docfx.Dotnet.csproj b/src/Docfx.Dotnet/Docfx.Dotnet.csproj
index 4ed680f0d49..341c7a84306 100644
--- a/src/Docfx.Dotnet/Docfx.Dotnet.csproj
+++ b/src/Docfx.Dotnet/Docfx.Dotnet.csproj
@@ -28,6 +28,11 @@
+
+
+
+
+
diff --git a/src/Docfx.Dotnet/DotnetApiCatalog.cs b/src/Docfx.Dotnet/DotnetApiCatalog.cs
index cc64c5ed1a8..5b5eaa0e393 100644
--- a/src/Docfx.Dotnet/DotnetApiCatalog.cs
+++ b/src/Docfx.Dotnet/DotnetApiCatalog.cs
@@ -57,6 +57,8 @@ internal static async Task Exec(MetadataJsonConfig config, DotnetApiOptions opti
{
var stopwatch = Stopwatch.StartNew();
+ EnsureMSBuildLocator();
+
try
{
string originalGlobalNamespaceId = VisitorHelper.GlobalNamespaceId;
@@ -122,6 +124,26 @@ void WriteYaml(string outputFolder, string id, Build.ApiPage.ApiPage apiPage)
}
}
+ private static void EnsureMSBuildLocator()
+ {
+#if NET6_0
+ try
+ {
+ if (!Microsoft.Build.Locator.MSBuildLocator.IsRegistered)
+ {
+ var vs = Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults() ?? throw new Docfx.Exceptions.ExtractMetadataException(
+ $"Cannot find a supported .NET Core SDK. Install .NET Core SDK {Environment.Version.Major}.{Environment.Version.Minor}.x to build .NET API docs.");
+
+ Logger.LogInfo($"Using {vs.Name} {vs.Version}");
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Docfx.Exceptions.ExtractMetadataException(e.Message, e);
+ }
+#endif
+ }
+
private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig configModel, string configDirectory, string outputDirectory)
{
var projects = configModel.Src;