Skip to content

Commit

Permalink
Make docfx a local tool instead of global
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Oct 10, 2024
1 parent c4ee56b commit c98281a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"docfx": {
"version": "2.77.0",
"commands": [
"docfx"
],
"rollForward": false
}
}
}
33 changes: 8 additions & 25 deletions websites/apidocs/docs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ param (
[int] $StagingPort = 8080
)
$MinimumSdkVersion = "8.0.100" # Minimum Required .NET SDK (must not be a pre-release)
$DocFxVersion = "2.77.0" # Required DocFx version

$ErrorActionPreference = "Stop"

Expand Down Expand Up @@ -64,26 +63,10 @@ $TocPath2 = Join-Path -Path $ApiDocsFolder -ChildPath "toc\toc.yml"
$BreadcrumbPath = Join-Path -Path $ApiDocsFolder -ChildPath "docfx.global.subsite.json"

# install docfx tool
$InstallDocFx = $false
try {
$InstalledDocFxVersion = (& docfx --version).Trim().Split('+')[0]

if ([version]$InstalledDocFxVersion -lt [version]$DocFxVersion) {
Write-Host "DocFx is installed, but the version is less than $DocFxVersion, will install it."
$InstallDocFx = $true
}
else {
Write-Host "DocFx is installed and the version is $InstalledDocFxVersion."
}
} catch {
Write-Host "DocFx is not installed or not in the PATH, will install it."
$InstallDocFx = $true
}

if ($InstallDocFx -eq $true) {
Write-Host "Installing docfx global tool..."
dotnet tool install -g docfx --version $DocFxVersion
}
$PreviousLocation = Get-Location
Set-Location $RepoRoot
dotnet tool restore
Set-Location $PreviousLocation

# delete anything that already exists
if ($Clean) {
Expand Down Expand Up @@ -165,7 +148,7 @@ if ($? -and $DisableMetaData -eq $false) {

# build the output
Write-Host "Building api metadata for $projFile..."
& docfx metadata $projFile --log "$DocFxLog" --logLevel $LogLevel
& dotnet tool run docfx metadata $projFile --log "$DocFxLog" --logLevel $LogLevel
}
}

Expand Down Expand Up @@ -193,7 +176,7 @@ if ($? -and $DisableBuild -eq $false) {

# build the output
Write-Host "Building site output for $projFile..."
& docfx build $projFile --log "$DocFxLog" --logLevel $LogLevel --debug --maxParallelism 1
& dotnet tool run docfx build $projFile --log "$DocFxLog" --logLevel $LogLevel --debug --maxParallelism 1

# Add the baseUrl to the output xrefmap, see https://github.com/dotnet/docfx/issues/2346#issuecomment-356054027
$projFileJson = Get-Content $projFile | ConvertFrom-Json
Expand All @@ -220,12 +203,12 @@ if ($?) {

# build the output
Write-Host "Building docs..."
& docfx $DocFxJsonSite --log "$DocFxLog" --logLevel $LogLevel --debug
& dotnet tool run docfx $DocFxJsonSite --log "$DocFxLog" --logLevel $LogLevel --debug
}
else {
# build + serve (for testing)
Write-Host "starting website..."
& docfx $DocFxJsonSite --log "$DocFxLog" --logLevel $LogLevel --serve --port $StagingPort --debug
& dotnet tool run docfx $DocFxJsonSite --log "$DocFxLog" --logLevel $LogLevel --serve --port $StagingPort --debug
}
}

Expand Down

0 comments on commit c98281a

Please sign in to comment.