Guest User

Untitled

a guest
Mar 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. ASP.NET Core Generate Swagger Json File Helper
  4.  
  5. .DESCRIPTION
  6. ASP.NET Core Webを起動してSwagger Jsonファイルをダウンロードして保存します
  7. #>
  8. # Swagger Json ファイルのパス
  9. $SWAGGER_JSON_PATH = '/swagger/v1/swagger.json'
  10. # Swagger Json 保存先
  11. $SWAGGER_JSON_OUTPATH = '../swagger.json'
  12.  
  13. # launchSettings.jsonから$applicationUrlを取得
  14. $projName = [System.IO.Path]::GetFileNameWithoutExtension((Get-ChildItem *.*proj -Name | Select-Object -First 1))
  15. $launchSettings = Get-Content 'Properties/launchSettings.json' -Encoding UTF8 | ConvertFrom-Json
  16. $applicationUrl = New-Object System.Uri(@($launchSettings.profiles.psobject.properties | Where { $_.Name -eq $projName })[0].Value.applicationUrl)
  17.  
  18. # ASP.NET Core を起動
  19. Split-Path -Parent $MyInvocation.MyCommand.Path | Set-Location
  20. $webProcess = Start-Process 'dotnet' 'run' -PassThru
  21. Start-Sleep -Seconds 10
  22.  
  23. # Swagger Json ファイルダウンロード
  24. $jsonUrl = New-Object System.Uri($applicationUrl, $SWAGGER_JSON_PATH)
  25. Invoke-WebRequest -Uri $jsonUrl -OutFile $SWAGGER_JSON_OUTPATH
  26.  
  27. # ASP.NET Core 停止
  28. TaskKill /PID $webProcess.Id /T /F
Add Comment
Please, Sign In to add comment