docfx icon indicating copy to clipboard operation
docfx copied to clipboard

DocFX can't generate Api docs when VS is not installed

Open sameer-kumar opened this issue 2 years ago • 9 comments

Operating System: Windows

DocFX Version Used: 2.58.9.0

Template used: default

Steps to Reproduce:

  1. I have Build Tools installed on my CI build server (Windows) with no full blown IDE. DocFX can't compile my projects for Api documentation.

Expected Behavior: Generate yml files under api directory.

Actual Behavior: Content documentation is generated but not Api. Here is what I see in logs:

[MetadataCommand.ExtractMetadata]Using msbuild C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin as inner compiler. [MetadataCommand.ExtractMetadata]E:/BuildAgents/2.165.2/1/_work/77/s/Proj.Docs/src/App.Core/src/App.Core.Common.csproj)Workspace failed with: [Failure] Msbuild failed when processing the file 'E:\BuildAgents\2.165.2\1\_work\77\s\Proj.Docs\src\App.Core\src\App.Core.Common.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found. E:\BuildAgents\2.165.2\1\_work\77\s\Proj.Docs\src\App.Core\src\App.Core.Common.csproj

sameer-kumar avatar Mar 16 '22 19:03 sameer-kumar

Without the SDK available, it can't generate the metadata needed, since it won't be able to understand the project or infer the type parameters. Once you have generated the API Yaml, you don't need VS, but you will need it to analyze your code.

dotMorten avatar Apr 06 '22 22:04 dotMorten

@sameer-kumar did you find a workaround for this issue? I'm facing the same issue with older docfx versions, however, if I use the latest I get a StackOverflow exception.

laura-rodriguez avatar May 10 '22 20:05 laura-rodriguez

@laura-rodriguez nope. I gave up. I'm now using build machine with VS installed.

sameer-kumar avatar May 11 '22 14:05 sameer-kumar

I’m assuming this is the metadata step? There’s no way to analyze and generate metadata from a project and source code without having the tools to interpret that.

dotMorten avatar May 11 '22 14:05 dotMorten

I have a little workaround. Instead of VS, you can setup Visual Studio Build Tools.

sakno avatar May 31 '22 21:05 sakno

All you really need are the SDKs that your projects rely on, so they can be understood. (yes build tools also install these if you enable the right workloads)

dotMorten avatar May 31 '22 21:05 dotMorten

Also, in a newer .NET SDKs (starting from .NET 6), special environment variable is required in some cases:

SET MSBuildEnableWorkloadResolver=false

sakno avatar May 31 '22 21:05 sakno

Related #7662

sakno avatar May 31 '22 21:05 sakno

I have 2 VMs with agents - VM1 with full IDE and VM2 with just Build Tools and SDKs. My code projects compiles fine and successfully with VM2. However, I can't get DocFX to generate API docs. But it works fine if I use VM1 and all docs are generated.

sameer-kumar avatar Jun 02 '22 20:06 sameer-kumar

Docfx uses MSBuildWorkspace to analyze projects. There is a good article on how MsBuildWorkspace works and how to prepare an environment:

The recommended way to set up MSBuild is to install Visual Studio 2017 (or newer) or the Build Tools for Visual Studio 2017 (or newer) on the machine that MSBuildWorkspace will run on. The important detail is to ensure that the installation has the necessary workloads and components to support the projects you'll be loading. For example, if C# is not installed, you will not be able to load C# projects. Similarly, if a project targets .NET Framework 4.7.3, that targeting pack must be installed. A good rule of thumb is, if you can build the project with MSBuild at the command-line, MSBuildWorkspace should be able to load it.

For this particular case, the latest version should load Microsoft.NET.Sdk once you have the corresponding .NET SDK installed.

yufeih avatar Feb 01 '23 08:02 yufeih