docfx metadata step fails with error "Could not load SDK Resolver"

2.3k views Asked by At

Whenever I try to build any documentation using docfx, I get the following error in the metadata build step that uses msbuild to analyze the xml comments in the code of the csprojs:

Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'C:\temp\docfxtest\docfx_project\src\src.csproj' with message: Could not load SDK Resolver. A manifest file exists, but the path to the SDK Resolver DLL file could not be found. Manifest file path 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\SdkResolvers\Microsoft.Build.NuGetSdkResolver\Microsoft.Build.NuGetSdkResolver.xml'. SDK resolver path: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll C:\temp\docfxtest\docfx_project\src\src.csproj

It seems that msbuild cannot be correctly resolved by docfx. Any idea how I could fix this?

Im using docfx version 2.56.5.0 on Windows and I also have VS Enterprise 2019 (16.8.2) and VS Build Tools 2017 (15.9.29) installed:

Visual Studio Installer

UPDATE:

I have now uninstalled the VS 2017 build tools completely and repaired the VS 2019 installation using the installer. I now get a different error when I run docfx. It seems that it can't find msbuild at all anymore.

Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'C:\temp\docfxtest\docfx_project\src\src.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found. C:\temp\docfxtest\docfx_project\src\src.csproj

Running msbuild -t:restore,build also shows that it can't find msbuild

'msbuild' is not recognized as an internal or external command

The targets are isntalled:

enter image description here

And so is the .NET Core workload:

enter image description here

2

There are 2 answers

15
Mr Qian On BEST ANSWER

Your Build Tool for VS2017 might have some problems due to some issues. The most issue is this:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll

Either you lost the dll or the dll is damaged.

Update

1) First, you should check whether you have installed NuGet targets and build tasks workload and net core build tools workload. If not, please install it.

enter image description here

enter image description here

2) Second, please delete bin and obj folder of your project and then try again.

You should use msbuild -t:restore,build to build your project.

3) Third, try to Repair from vs_installer for your build tool. It will repair the related dll. And then delete bin and obj folder, use build tool to test your project again.

Important:

VS2017 does not support net core 3.1. You should note that. It supports <=net core 2.1.

So if you still want to use Build Tool of VS2017 for your net core project, you should try the the above three steps and then target your project to net core 2.1.

Besides, if you start msbuild by CMD, I think you should check your environment variable PATH and check whether you have configured the msbuild.exe from Build Tool of VS2017 on it. Instead, you could add C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe. This way is for VS2019.

=================================================

Update 1

The problem is that you have already installed a docfx tool by choco command line.

At the beginning, I always thought that you used docfx.console nuget package on your project and just invoke docfx.exe from C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe under command line.

Regardless of the installation of docfx.console package on your project, if you installed docfx tool by choco command and then just invoke docfx.exe on command line, it used the local docfx.exe under C:\ProgramData\chocolatey\lib\docfx\tools\docfx.exe rather than the nuget package.

So the issue is that your local docfx.exe has some errors due to some issues. You should reinstall the docfx.exe by choco command choco uninstall docfx; choco install docfx.

Actually, directly use docfx.console nuget package on your project might be easier. From this link.

It already contains the generation step of the documentation by docfx.exe(from C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe) and will execute it automatically rather than run docfx.exe again manually.

0
bitbonk On

I have completely uninstalled docfx using chocolatey (choco uninstall docfx) removed every folder named docfxfrom c:\ProgramData\chocolatey\.chocolatey\ and then reinstalled it (choco install docfx). After that, everything worked fine again. The file c:\ProgramData\chocolatey\lib\docfx\tools\docfx.exe.config contains a lot of msbuild related configuration. Maybe something was messed up there.