5
5
# 4: dotnet / NuGet package restore failure
6
6
7
7
<#
8
- . SYNOPSIS
9
- Writes a build progress message to the host .
8
+ . SYNOPSIS
9
+ Gets the set of directories in which projects are available for compile/processing .
10
10
11
- . PARAMETER Message
12
- The message to write .
11
+ . PARAMETER RootPath
12
+ Path where searching for project directories should begin .
13
13
#>
14
- function Write-Message
15
- {
16
- [CmdletBinding ()]
17
- Param (
18
- [Parameter (Mandatory = $True , ValueFromPipeline = $False , ValueFromPipelineByPropertyName = $False )]
19
- [ValidateNotNullOrEmpty ()]
20
- [string ]
21
- $Message
22
- )
23
-
24
- Write-Host " [BUILD] $Message " - ForegroundColor Cyan
14
+ function Get-DotNetProjectDirectory {
15
+ [CmdletBinding ()]
16
+ Param (
17
+ [Parameter (Mandatory = $True , ValueFromPipeline = $False , ValueFromPipelineByPropertyName = $False )]
18
+ [ValidateNotNullOrEmpty ()]
19
+ [string ]
20
+ $RootPath
21
+ )
22
+
23
+ Get-ChildItem - Path $RootPath - Recurse - Include " *.csproj" | Select-Object @ { Name = " ParentFolder" ; Expression = { $_.Directory.FullName.TrimEnd (" \" ) } } | Select-Object - ExpandProperty ParentFolder
25
24
}
26
25
27
26
<#
28
- . SYNOPSIS
29
- Gets the set of directories in which projects are available for compile/processing.
30
-
31
- . PARAMETER RootPath
32
- Path where searching for project directories should begin.
27
+ . SYNOPSIS
28
+ Runs the dotnet CLI install script from GitHub to install a project-local
29
+ copy of the CLI.
33
30
#>
34
- function Get-DotNetProjectDirectory
35
- {
36
- [CmdletBinding ()]
37
- Param (
38
- [Parameter (Mandatory = $True , ValueFromPipeline = $False , ValueFromPipelineByPropertyName = $False )]
39
- [ValidateNotNullOrEmpty ()]
40
- [string ]
41
- $RootPath
42
- )
43
-
44
- Get-ChildItem - Path $RootPath - Recurse - Include " *.csproj" | Select-Object @ { Name = " ParentFolder" ; Expression = { $_.Directory.FullName.TrimEnd (" \" ) } } | Select-Object - ExpandProperty ParentFolder
45
- }
31
+ function Install-DotNetCli {
32
+ [CmdletBinding ()]
33
+ Param (
34
+ [string ]
35
+ $Version = " Latest"
36
+ )
37
+
38
+ if ($null -ne (Get-Command " dotnet" - ErrorAction SilentlyContinue)) {
39
+ $installedVersion = dotnet -- version
40
+ if ($installedVersion -eq $Version ) {
41
+ Write-Message " .NET Core SDK version $Version is already installed"
42
+ return ;
43
+ }
44
+ }
46
45
47
- <#
48
- . SYNOPSIS
49
- Runs the dotnet CLI install script from GitHub to install a project-local
50
- copy of the CLI.
51
- #>
52
- function Install-DotNetCli
53
- {
54
- [CmdletBinding ()]
55
- Param (
56
- [string ]
57
- $Version = " Latest"
58
- )
59
-
60
- if ((Get-Command " dotnet.exe" - ErrorAction SilentlyContinue) -ne $null )
61
- {
62
- $installedVersion = dotnet -- version
63
- if ($installedVersion -eq $Version )
64
- {
65
- Write-Message " .NET Core SDK version $Version is already installed"
66
- return ;
46
+ $callerPath = Split-Path $MyInvocation.PSCommandPath
47
+ $installDir = Join-Path - Path $callerPath - ChildPath " .dotnet/cli"
48
+ if (! (Test-Path $installDir )) {
49
+ New-Item - ItemType Directory - Path " $installDir " | Out-Null
50
+ }
51
+
52
+ # Download the dotnet CLI install script
53
+ if ($IsWindows ) {
54
+ if (! (Test-Path ./ .dotnet/ dotnet- install.ps1)) {
55
+ Invoke-WebRequest " https://dot.net/v1/dotnet-install.ps1" - OutFile " ./.dotnet/dotnet-install.ps1"
56
+ }
57
+
58
+ & ./ .dotnet/ dotnet- install.ps1 - InstallDir " $installDir " - Version $Version
59
+ $env: PATH = " $installDir ;$env: PATH "
60
+ } else {
61
+ if (! (Test-Path ./ .dotnet/ dotnet- install.sh)) {
62
+ Invoke-WebRequest " https://dot.net/v1/dotnet-install.sh" - OutFile " ./.dotnet/dotnet-install.sh"
63
+ }
64
+
65
+ & bash ./ .dotnet/ dotnet- install.sh -- install-dir " $installDir " -- version $Version
66
+ $env: PATH = " $installDir `:$env: PATH "
67
67
}
68
- }
69
-
70
- $callerPath = Split-Path $MyInvocation.PSCommandPath
71
- $installDir = Join-Path - Path $callerPath - ChildPath " .dotnet\cli"
72
- if (! (Test-Path $installDir ))
73
- {
74
- New-Item - ItemType Directory - Path " $installDir " | Out-Null
75
- }
76
-
77
- # Download the dotnet CLI install script
78
- if (! (Test-Path .\dotnet\install.ps1))
79
- {
80
- Invoke-WebRequest " https://dot.net/v1/dotnet-install.ps1" - OutFile " .\.dotnet\dotnet-install.ps1"
81
- }
82
-
83
- # Run the dotnet CLI install
84
- & .\.dotnet\dotnet- install.ps1 - InstallDir " $installDir " - Version $Version
85
-
86
- # Add the dotnet folder path to the process.
87
- $env: PATH = " $installDir ;$env: PATH "
88
68
}
89
69
90
70
<#
@@ -95,156 +75,162 @@ function Install-DotNetCli
95
75
. PARAMETER DirectoryName
96
76
The path to the directory containing the project to build.
97
77
#>
98
- function Invoke-DotNetBuild
99
- {
100
- [CmdletBinding ()]
101
- Param (
102
- [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
103
- [ValidateNotNull ()]
104
- [System.IO.DirectoryInfo []]
105
- $ProjectDirectory
106
- )
107
- Process
108
- {
109
- foreach ($Project in $ProjectDirectory )
110
- {
111
- & dotnet build (" "" " + $Project.FullName + " "" " ) -- configuration Release
112
- if ($LASTEXITCODE -ne 0 )
113
- {
114
- exit 1
115
- }
78
+ function Invoke-DotNetBuild {
79
+ [CmdletBinding ()]
80
+ Param (
81
+ [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
82
+ [ValidateNotNull ()]
83
+ [System.IO.DirectoryInfo []]
84
+ $ProjectDirectory
85
+ )
86
+ Process {
87
+ foreach ($Project in $ProjectDirectory ) {
88
+ & dotnet build (" "" " + $Project.FullName + " "" " ) -- configuration Release
89
+ if ($LASTEXITCODE -ne 0 ) {
90
+ exit 1
91
+ }
92
+ }
116
93
}
117
- }
118
94
}
119
95
120
96
<#
121
- . SYNOPSIS
122
- Invokes the dotnet utility to package a project.
97
+ . SYNOPSIS
98
+ Invokes the dotnet utility to package a project.
123
99
124
- . PARAMETER ProjectDirectory
125
- Path to the directory containing the project to package.
100
+ . PARAMETER ProjectDirectory
101
+ Path to the directory containing the project to package.
126
102
127
- . PARAMETER PackagesPath
128
- Path to the "artifacts\ packages" folder where packages should go.
103
+ . PARAMETER PackagesPath
104
+ Path to the "artifacts/ packages" folder where packages should go.
129
105
130
- . PARAMETER VersionSuffix
131
- The version suffix to use for the NuGet package version.
106
+ . PARAMETER VersionSuffix
107
+ The version suffix to use for the NuGet package version.
132
108
#>
133
- function Invoke-DotNetPack
134
- {
135
- [CmdletBinding ()]
136
- Param (
137
- [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
138
- [ValidateNotNull ()]
139
- [System.IO.DirectoryInfo []]
140
- $ProjectDirectory ,
141
-
142
- [Parameter (Mandatory = $True , ValueFromPipeline = $False )]
143
- [ValidateNotNull ()]
144
- [System.IO.DirectoryInfo ]
145
- $PackagesPath ,
146
-
147
- [Parameter (Mandatory = $True , ValueFromPipeline = $False )]
148
- [AllowEmptyString ()]
149
- [string ]
150
- $VersionSuffix = " "
151
- )
152
- Begin
153
- {
154
- New-Item - Path $PackagesPath - ItemType Directory - Force | Out-Null
155
- }
156
- Process
157
- {
158
- foreach ($Project in $ProjectDirectory )
159
- {
160
- if ($VersionSuffix -eq " " )
161
- {
162
- & dotnet build (" "" " + $Project.FullName + " "" " ) -- configuration Release
163
- }
164
- else
165
- {
166
- & dotnet build (" "" " + $Project.FullName + " "" " ) -- configuration Release -- version- suffix $VersionSuffix
167
- }
168
- if ($LASTEXITCODE -ne 0 )
169
- {
170
- exit 1
171
- }
172
-
173
- if ($VersionSuffix -eq " " )
174
- {
175
- & dotnet pack (" "" " + $Project.FullName + " "" " ) -- configuration Release -- output $PackagesPath
176
- }
177
- else
178
- {
179
- & dotnet pack (" "" " + $Project.FullName + " "" " ) -- configuration Release -- version- suffix $VersionSuffix -- output $PackagesPath
180
- }
181
- if ($LASTEXITCODE -ne 0 )
182
- {
183
- exit 1
184
- }
109
+ function Invoke-DotNetPack {
110
+ [CmdletBinding ()]
111
+ Param (
112
+ [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
113
+ [ValidateNotNull ()]
114
+ [System.IO.DirectoryInfo []]
115
+ $ProjectDirectory ,
116
+
117
+ [Parameter (Mandatory = $True , ValueFromPipeline = $False )]
118
+ [ValidateNotNull ()]
119
+ [System.IO.DirectoryInfo ]
120
+ $PackagesPath ,
121
+
122
+ [Parameter (Mandatory = $True , ValueFromPipeline = $False )]
123
+ [AllowEmptyString ()]
124
+ [string ]
125
+ $VersionSuffix
126
+ )
127
+ Begin {
128
+ New-Item - Path $PackagesPath - ItemType Directory - Force | Out-Null
129
+ }
130
+ Process {
131
+ foreach ($Project in $ProjectDirectory ) {
132
+ if ($VersionSuffix -eq " " ) {
133
+ & dotnet build (" "" " + $Project.FullName + " "" " ) -- configuration Release
134
+ }
135
+ else {
136
+ & dotnet build (" "" " + $Project.FullName + " "" " ) -- configuration Release -- version- suffix $VersionSuffix
137
+ }
138
+ if ($LASTEXITCODE -ne 0 ) {
139
+ exit 1
140
+ }
141
+
142
+ if ($VersionSuffix -eq " " ) {
143
+ & dotnet pack (" "" " + $Project.FullName + " "" " ) -- configuration Release -- output $PackagesPath
144
+ }
145
+ else {
146
+ & dotnet pack (" "" " + $Project.FullName + " "" " ) -- configuration Release -- version- suffix $VersionSuffix -- output $PackagesPath
147
+ }
148
+ if ($LASTEXITCODE -ne 0 ) {
149
+ exit 1
150
+ }
151
+ }
185
152
}
186
- }
187
153
}
188
154
189
155
<#
190
- . Synopsis
191
- Invokes dotnet test command.
156
+ . SYNOPSIS
157
+ Invokes dotnet test command.
192
158
193
- . Parameter ProjectDirectory
194
- Path to the directory containing the project to package.
159
+ . PARAMETER ProjectDirectory
160
+ Path to the directory containing the project to package.
195
161
#>
196
- function Invoke-Test
197
- {
198
- [CmdletBinding ()]
199
- Param (
200
- [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
201
- [ValidateNotNull ()]
202
- [System.IO.DirectoryInfo []]
203
- $ProjectDirectory
204
- )
205
- Process
206
- {
207
- foreach ($Project in $ProjectDirectory )
208
- {
209
- Push-Location $Project
210
-
211
- & dotnet test -- configuration Release -- logger:trx
212
- if ($LASTEXITCODE -ne 0 )
213
- {
214
- Pop-Location
215
- exit 3
216
- }
217
-
218
- Pop-Location
162
+ function Invoke-Test {
163
+ [CmdletBinding ()]
164
+ Param (
165
+ [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
166
+ [ValidateNotNull ()]
167
+ [System.IO.DirectoryInfo []]
168
+ $ProjectDirectory
169
+ )
170
+ Process {
171
+ foreach ($Project in $ProjectDirectory ) {
172
+ Push-Location $Project
173
+
174
+ & dotnet test `
175
+ -- configuration Release `
176
+ -- logger:trx `
177
+ / p:CollectCoverage= true `
178
+ / p:CoverletOutput= " ..\..\" `
179
+ / p:MergeWith= " ..\..\coverage.json" `
180
+ / p:CoverletOutputFormat= " json%2clcov" `
181
+ / p:ExcludeByAttribute= CompilerGeneratedAttribute `
182
+ / p:ExcludeByAttribute= GeneratedCodeAttribute
183
+
184
+ if ($LASTEXITCODE -ne 0 ) {
185
+ Pop-Location
186
+ exit 3
187
+ }
188
+
189
+ Pop-Location
190
+ }
219
191
}
220
- }
221
192
}
222
193
223
194
<#
224
- . SYNOPSIS
225
- Restores dependencies using the dotnet utility.
195
+ . SYNOPSIS
196
+ Restores dependencies using the dotnet utility.
226
197
227
- . PARAMETER ProjectDirectory
228
- Path to the directory containing the project with dependencies to restore.
198
+ . PARAMETER ProjectDirectory
199
+ Path to the directory containing the project with dependencies to restore.
229
200
#>
230
- function Restore-DependencyPackages
231
- {
232
- [CmdletBinding ()]
233
- Param (
234
- [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
235
- [ValidateNotNull ()]
236
- [System.IO.DirectoryInfo []]
237
- $ProjectDirectory
238
- )
239
- Process
240
- {
241
- foreach ($Project in $ProjectDirectory )
242
- {
243
- & dotnet restore (" "" " + $Project.FullName + " "" " ) -- no- cache
244
- if ($LASTEXITCODE -ne 0 )
245
- {
246
- exit 4
247
- }
201
+ function Restore-DependencyPackages {
202
+ [CmdletBinding ()]
203
+ Param (
204
+ [Parameter (Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
205
+ [ValidateNotNull ()]
206
+ [System.IO.DirectoryInfo []]
207
+ $ProjectDirectory
208
+ )
209
+ Process {
210
+ foreach ($Project in $ProjectDirectory ) {
211
+ & dotnet restore (" "" " + $Project.FullName + " "" " ) -- no- cache
212
+ if ($LASTEXITCODE -ne 0 ) {
213
+ exit 4
214
+ }
215
+ }
248
216
}
249
- }
217
+ }
218
+
219
+ <#
220
+ . SYNOPSIS
221
+ Writes a build progress message to the host.
222
+
223
+ . PARAMETER Message
224
+ The message to write.
225
+ #>
226
+ function Write-Message {
227
+ [CmdletBinding ()]
228
+ Param (
229
+ [Parameter (Mandatory = $True , ValueFromPipeline = $False , ValueFromPipelineByPropertyName = $False )]
230
+ [ValidateNotNullOrEmpty ()]
231
+ [string ]
232
+ $Message
233
+ )
234
+
235
+ Write-Host " [BUILD] $Message " - ForegroundColor Cyan
250
236
}
0 commit comments