@@ -66,8 +66,12 @@ $BreadcrumbPath = Join-Path -Path $ApiDocsFolder -ChildPath "docfx.global.subsit
6666Write-Host " Restoring docfx tool..."
6767$PreviousLocation = Get-Location
6868Set-Location $RepoRoot
69- dotnet tool restore
70- Set-Location $PreviousLocation
69+ try {
70+ dotnet tool restore
71+ } finally {
72+ Set-Location $PreviousLocation
73+ }
74+
7175
7276# delete anything that already exists
7377if ($Clean ) {
@@ -155,7 +159,13 @@ if ($? -and $DisableMetaData -eq $false) {
155159
156160 # build the output
157161 Write-Host " Building api metadata for $projFile ..."
158- & dotnet tool run docfx metadata $projFile -- log " $DocFxLog " -- logLevel $LogLevel
162+ $PreviousLocation = Get-Location
163+ Set-Location $RepoRoot
164+ try {
165+ & dotnet tool run docfx metadata $projFile -- log " $DocFxLog " -- logLevel $LogLevel
166+ } finally {
167+ Set-Location $PreviousLocation
168+ }
159169 }
160170}
161171
@@ -183,7 +193,13 @@ if ($? -and $DisableBuild -eq $false) {
183193
184194 # build the output
185195 Write-Host " Building site output for $projFile ..."
186- & dotnet tool run docfx build $projFile -- log " $DocFxLog " -- logLevel $LogLevel -- debug -- maxParallelism 1
196+ $PreviousLocation = Get-Location
197+ Set-Location $RepoRoot
198+ try {
199+ & dotnet tool run docfx build $projFile -- log " $DocFxLog " -- logLevel $LogLevel -- debug -- maxParallelism 1
200+ } finally {
201+ Set-Location $PreviousLocation
202+ }
187203
188204 # Add the baseUrl to the output xrefmap, see https://github.com/dotnet/docfx/issues/2346#issuecomment-356054027
189205 $projFileJson = Get-Content $projFile | ConvertFrom-Json
@@ -201,16 +217,22 @@ if ($? -and $DisableBuild -eq $false) {
201217if ($? ) {
202218 $DocFxLog = Join-Path - Path $ApiDocsFolder " obj\docfx.site.json.log"
203219
204- if ($ServeDocs -eq $false ) {
205-
206- # build the output
207- Write-Host " Building docs..."
208- & dotnet tool run docfx $DocFxJsonSite -- log " $DocFxLog " -- logLevel $LogLevel -- debug -- maxParallelism 1
209- }
210- else {
211- # build + serve (for testing)
212- Write-Host " starting website..."
213- & dotnet tool run docfx $DocFxJsonSite -- log " $DocFxLog " -- logLevel $LogLevel -- serve -- port $StagingPort -- debug -- maxParallelism 1
220+ $PreviousLocation = Get-Location
221+ Set-Location $RepoRoot
222+ try {
223+ if ($ServeDocs -eq $false ) {
224+
225+ # build the output
226+ Write-Host " Building docs..."
227+ & dotnet tool run docfx $DocFxJsonSite -- log " $DocFxLog " -- logLevel $LogLevel -- debug -- maxParallelism 1
228+ }
229+ else {
230+ # build + serve (for testing)
231+ Write-Host " starting website..."
232+ & dotnet tool run docfx $DocFxJsonSite -- log " $DocFxLog " -- logLevel $LogLevel -- serve -- port $StagingPort -- debug -- maxParallelism 1
233+ }
234+ } finally {
235+ Set-Location $PreviousLocation
214236 }
215237}
216238
0 commit comments