1

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

bitbonk
  • 48,890
  • 37
  • 186
  • 278
  • Did you build the project successfully on VS2019 enterprise? And please let us know it is the issue of build tool itself or the project itself. – Mr Qian Nov 30 '20 at 05:47
  • I can build the csprojs themself using VS. But I cannot build the docs for them using docfx. Docfx can’t find msbuild. – bitbonk Nov 30 '20 at 05:55

2 Answers2

2

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.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • 1
    I will try that. What is surprising to me is that it tries to use the build tools of VS 2017. I think it should chose and look for the build tools of VS 2019. – bitbonk Nov 30 '20 at 06:21
  • Also, if your project is target `net framework`, when you delete bin and obj folder, please run `nuget restore xxx/xxx.sln` first to restore the files. – Mr Qian Nov 30 '20 at 06:23
  • 1
    All project are netcoreapp3.1 – bitbonk Nov 30 '20 at 06:23
  • 1
    Thanks for your feedback, so you should use `msbuild -t:restore,build`. – Mr Qian Nov 30 '20 at 06:24
  • 2
    Click `Lanuch` from the `vs_installer`,and it will use the related tool. If you start CMD to use msbuild on this way, you should check your environment variable `PATH` and check whether you have configured the msbuild.exe of `VS2017` on it. Instead, you could add `C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe` – Mr Qian Nov 30 '20 at 06:33
  • VS0217 does not support `net core 3.1`. It supports <=`net core 2.1`. So maybe you should make a choice. I have updated my answer. Also, developer command prompt for VS2019 is also what you want. You can search it from start menu. [https://i.stack.imgur.com/7oOBz.png](https://i.stack.imgur.com/7oOBz.png). – Mr Qian Nov 30 '20 at 06:45
  • I have updated my question too. After uninstalling VS2017 and repairing VS2019 it can't find msbuild *at all* anymore. – bitbonk Nov 30 '20 at 06:47
  • How did you invoke msbuild, click Launch button under Build Tool of VS2017 from the vs_installer UI and then type msbuild? And if you use CMD, you should reconfigure the full msbuild.exe path into `PATH`. – Mr Qian Nov 30 '20 at 06:51
  • I don't have VS2017 at all anymore now. I invoked msbuild using a new instance of a regular cmd.exe. Using the *"x86_x64 Cross Tools Command Prompt for VS 2019"* I can sucessfully invoke the `msbuild -t:restore,build` command. But running docfx in that command prompt sill gives me the error *"The SDK 'Microsoft.NET.Sdk' specified could not be found."*. – bitbonk Nov 30 '20 at 06:55
  • Also, please check whether you have a system environment variable called `MSBuildSDKsPath ` and check the value of it is right on your current PC. And make sure that the sdk version exists on your PC. – Mr Qian Nov 30 '20 at 07:57
  • The thing that eventually fixed it was [reinstalling docfx](https://stackoverflow.com/a/65069800/4227) but who knows, the things from this answer might have helped too. So I am accepting this as the answer. – bitbonk Nov 30 '20 at 07:59
  • Oh, this is my guess. When you build your project in VS IDE(already install this nuget package docfx.console which contains the right `docfx.exe`), it has a custom script that uses the `docfx.exe` under the nuget package so that it works well. And your local `docfx.exe` is installed by choco command and the local `docfx.exe` might have some errors due to some issues. So, when you directly call `docfx.exe` on command line, it actually executes the local `docfx.exe` rather than the nuget package. Sorry for did not notice that you have also install a local tool on your PC at the beginning. – Mr Qian Nov 30 '20 at 08:38
  • I always thought you used `C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe` directly on the command line. And that is called by VS IDE. Anyway, thanks for your solution and have a nice day :)) – Mr Qian Nov 30 '20 at 08:39
  • If you did not install that `docfx.console` nuget package on your project, actually regardless of the use of this package on your project, when you directly use `docfx.exe` from the command line,checking the local docfx.exe might be a good choice. And I will update the answer to add them. – Mr Qian Nov 30 '20 at 08:50
  • With latest `Visual Studio Installer version 3.4.2246.31370` there is not any `.NET Core Build Tools` checkbox available, you must install corresponding `.NET SDKs for Visual Studio` manually and then build tools will be added to Visual Studio automatically – Seyed Hossein Mirheydari Jan 13 '23 at 08:12
1

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.

bitbonk
  • 48,890
  • 37
  • 186
  • 278