1
+ param (
2
+ [string ] $configuration = " Release" ,
3
+ [switch ] $raw = $false ,
4
+ [switch ] $prod = $false
5
+ )
6
+
7
+ # ###############################################################################################
8
+ # Usage:
9
+ # Run build.ps1
10
+ # [-configuration Configuration]: Default to be Release
11
+ # [-raw]: If it's set, the build process will skip updating template
12
+ # [-prod]: If it's set, the build process will update version
13
+ # ###############################################################################################
14
+
15
+ $ErrorActionPreference = ' Stop'
16
+ $scriptPath = $MyInvocation.MyCommand.Path
17
+ $scriptHome = Split-Path $scriptPath
18
+
19
+ Push-Location $scriptHome
20
+
21
+ # Check if dotnet cli exists globally
22
+ if ((Get-Command " dotnet" - ErrorAction SilentlyContinue) -eq $null )
23
+ {
24
+ Write-Host " dotnet CLI is not successfully configured."
25
+ Write-Host " Please follow https://www.microsoft.com/net/core to install .NET Core."
26
+ Exit 1
27
+ }
28
+
29
+ # Check if nuget.exe exists
30
+ $nuget = " $env: APPDATA \Nuget\Nuget.exe"
31
+ if (-not (Test-Path $nuget ))
32
+ {
33
+ Write-Host " Downloading NuGet.exe..."
34
+ $ProgressPreference = ' SilentlyContinue'
35
+ [Net.WebRequest ]::DefaultWebProxy.Credentials = [Net.CredentialCache ]::DefaultCredentials
36
+ Invoke-WebRequest ' https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' - OutFile $nuget
37
+ }
38
+
39
+ if ($raw -eq $false )
40
+ {
41
+ & " .\UpdateTemplate.cmd"
42
+ if ($lastexitcode -ne 0 ) { Write-Error " Update templte error, exit code: $lastexitcode " ; Pop-Location }
43
+ }
44
+ else
45
+ {
46
+ Write-Host " Skip updating template"
47
+ }
48
+
49
+ if ($prod -eq $true )
50
+ {
51
+ & " .\UpdateVersion.cmd"
52
+ if ($lastexitcode -ne 0 ) { Write-Error " Update version error, exit code: $lastexitcode " ; Pop-Location }
53
+ }
54
+
55
+ # Restore package
56
+ Write-Host " Start to restore package"
57
+ foreach ($folder in @ (" src" , " test" , " tools" ))
58
+ {
59
+ Push-Location $folder
60
+ & dotnet restore
61
+ if ($lastexitcode -ne 0 ) { Write-Error " dotnet restore $folder error, exit code: $lastexitcode " ; Pop-Location }
62
+ Pop-Location
63
+ }
64
+
65
+ # Build project
66
+ Write-Host " Start to build project"
67
+ foreach ($folder in (dir " src" ))
68
+ {
69
+ if (Test-Path (Join-Path $folder.FullName " project.json" )) {
70
+ & dotnet publish $folder.FullName - o target\$configuration \$folder
71
+ if ($lastexitcode -ne 0 ) { Write-Error " dotnet build $folder error, exit code: $lastexitcode " ; Pop-Location }
72
+ }
73
+ }
74
+
75
+ # Run unit test cases
76
+ Write-Host " Start to run unit test"
77
+ foreach ($folder in (dir " test" ))
78
+ {
79
+ if ((Test-Path (Join-Path $folder.FullName " project.json" )) -and ($folder.Name -ne " Shared" ) -and ($folder.Name -ne " docfx.E2E.Tests" ))
80
+ {
81
+ & dotnet test test\$folder
82
+ if ($lastexitcode -ne 0 ) { Write-Error " dotnet test $folder error, exit code: $lastexitcode " ; Pop-Location }
83
+ }
84
+ }
85
+
86
+ # Build tools
87
+ Write-Host " Build tools"
88
+ foreach ($folder in (dir " tools" ))
89
+ {
90
+ if (Test-Path (Join-Path $folder.FullName " project.json" ))
91
+ {
92
+ & dotnet publish $folder.FullName - o target\$configuration \$folder
93
+ if ($lastexitcode -ne 0 ) { Write-Error " dotnet build $folder error, exit code: $lastexitcode " ; Pop-Location }
94
+ }
95
+ }
96
+
97
+ # Pack artifacts
98
+ Write-Host " Publish artifacts"
99
+ foreach ($folder in (dir " src" ))
100
+ {
101
+ if (Test-Path (Join-Path $folder.FullName " project.json" ))
102
+ {
103
+ & dotnet pack $folder.FullName - c $configuration - o artifacts\$configuration
104
+ if ($lastexitcode -ne 0 ) { Write-Error " dotnet pack $folder error, exit code: $lastexitcode " ; Pop-Location }
105
+ }
106
+ }
107
+
108
+ # Pack docfx.console
109
+ Copy-Item - Path " target\$configuration \docfx\*.dll" - Destination " src\nuspec\docfx.console\tools\"
110
+ Copy-Item - Path " target\$configuration \docfx\*.exe" - Destination " src\nuspec\docfx.console\tools\"
111
+ Copy-Item - Path " target\$configuration \docfx\*.exe.config" - Destination " src\nuspec\docfx.console\tools\"
112
+
113
+ $version = 1.0 .0
114
+ if (Test-Path " TEMP/version.txt" )
115
+ {
116
+ $version = cat " TEMP/version.txt"
117
+ $version = $version.Substring (1 )
118
+ }
119
+ & $nuget pack " src\nuspec\docfx.console\docfx.console.nuspec" - Version $version - OutputDirectory artifacts\$configuration
120
+ if ($lastexitcode -ne 0 ) { Write-Error " nuget pack docfx.console error, exit code: $lastexitcode " ; Pop-Location ; Pop-Location }
121
+
122
+ Write-Host " Complete."
123
+ Pop-Location
0 commit comments