How to build DocFx site via Visual Studio/Azure DevOps/TFS #8605
lanthonyneville
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Awesome work, very cleanly documented - thanks! I came here from #9225, looking for a way to keep msbuild rather than the command line to compile the site. This solution works flawlessly, and it's even an improvement over what docfx.console nuget package used to be, because with the .NET tool the build output is displayed. My only small issue was, in DocFxBuild.targets I had to to move the PropertyGroup into Target block UploadDocFxSiteToServer, otherwise the properties were not picked up. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After the docfx console was retired (DocFx 2.60.0) it took me a while to work out how to build a DocFx site via an automated Azure DevOps/TFS build. Here is how I do it. This would also work if building manually in Visual Studio.
(thanks to @KalleOlaviNiemitalo in #8412 and #8415 for tips)
Step 1: Create Visual Studio solution, containing 1 project per DocFx site
Note: the below describes manually generated Markdown-based content, but the same setup ought to work for automatically generated content describing .NET APIs.
Step 2: Add a build script (.targets file) to run DocFx and publish site
Note: in #8412 two approaches are described for running DocFx: (i) via code using Microsoft.DocAsCode.App package, and (ii) via the docfx .NET tool. The below uses the docfx .NET tool approach.
Create a text file called DocFxBuild.targets in the root of the project (sample content and explanation below)
Create a text file called dotnet-tools.json in the root of the project (sample content and explanation below)
Edit the project file (i.e. .csproj) and add the following lines above the closing
</Project>
tag<Import Project="$(MSBuildProjectDirectory)\DocFxBuild.targets" />
I also recommend adding this section, which avoids all the files generated during the build process from appearing like they belong to the project (i.e. the project only appears to contain the Markdown source etc)
Step 3: Build solution
The DocFxBuild.targets file (build script)
This controls the execution of DocFx, and (optionally) publishing the resulting content. The script is triggered by building the project (due to the 1st edit to the .csproj file, above).
In this example, the site content is zipped and published to a network share. Other commands that can be used are described here.
Note how the Condition=... arguments are used to only run these steps when building in Release mode.
The dotnet-tools.json file
This controls the automatic installation of DocFx as a local .NET tool (you do not have to install DocFx manually on the machine running the build). The DocFx version to use is specified in the file, so if you want to use a later version you have to edit the file.
Note: some articles say this file has to be in a subfolder called .config, but it seems to work when in the project root folder also.
Beta Was this translation helpful? Give feedback.
All reactions