@@ -15,6 +15,20 @@ function Test-IsWindows
1515 [environment ]::OSVersion.Platform -ne " Unix"
1616}
1717
18+ function Test-IsMonoInstalled
19+ {
20+ <#
21+ . DESCRIPTION
22+ Checks to see whether the current environment has the Mono framework installed.
23+
24+ . EXAMPLE
25+ if (Test-IsMonoInstalled) { Write-Host "Mono is available." }
26+ #>
27+
28+ $result = Invoke-Cmd " mono --version" - Silent
29+ return $result.StartsWith (" Mono JIT compiler version" )
30+ }
31+
1832function Get-UbuntuVersion
1933{
2034 <#
@@ -25,11 +39,13 @@ function Get-UbuntuVersion
2539 $ubuntuVersion = Get-UbuntuVersion
2640 #>
2741
28- $version = Invoke-Cmd " lsb_release -r -s"
42+ $version = Invoke-Cmd " lsb_release -r -s" - Silent
2943 return $version
3044}
3145
32- function Invoke-UnsafeCmd ($cmd )
46+ function Invoke-UnsafeCmd (
47+ [string ] $Cmd ,
48+ [switch ] $Silent )
3349{
3450 <#
3551 . DESCRIPTION
@@ -45,12 +61,14 @@ function Invoke-UnsafeCmd ($cmd)
4561 Use this PowerShell command to execute any CLI commands which might not exit with 0 on a success.
4662 #>
4763
48- Write-Host $cmd - ForegroundColor DarkCyan
64+ if ( ! ( $Silent .IsPresent )) { Write-Host $cmd - ForegroundColor DarkCyan }
4965 if (Test-IsWindows ) { $cmd = " cmd.exe /C $cmd " }
5066 Invoke-Expression - Command $cmd
5167}
5268
53- function Invoke-Cmd ($Cmd )
69+ function Invoke-Cmd (
70+ [string ] $Cmd ,
71+ [switch ] $Silent )
5472{
5573 <#
5674 . DESCRIPTION
@@ -66,7 +84,7 @@ function Invoke-Cmd ($Cmd)
6684 Use this PowerShell command to execute any dotnet CLI commands in order to ensure that they behave the same way in the case of an error across different environments (Windows, OSX and Linux).
6785 #>
6886
69- Invoke-UnsafeCmd $cmd
87+ if ( $Silent .IsPresent ) { Invoke-UnsafeCmd $cmd - Silent } else { Invoke-UnsafeCmd $cmd }
7088 if ($LastExitCode -ne 0 ) { Write-Error " An error occured when executing '$Cmd '." ; return }
7189}
7290
@@ -131,30 +149,6 @@ function Test-CompareVersions ($version, [string]$gitTag)
131149# .NET Core functions
132150# ----------------------------------------------
133151
134- function dotnet-info { Invoke-Cmd " dotnet --info" }
135- function dotnet-version { Invoke-Cmd " dotnet --version" }
136- function dotnet-restore ($project , $argv ) { Invoke-Cmd " dotnet restore $project $argv " }
137- function dotnet-build ($project , $argv ) { Invoke-Cmd " dotnet build $project $argv " }
138- function dotnet-run ($project , $argv ) { Invoke-Cmd " dotnet run --project $project $argv " }
139- function dotnet-pack ($project , $argv ) { Invoke-Cmd " dotnet pack $project $argv " }
140- function dotnet-publish ($project , $argv ) { Invoke-Cmd " dotnet publish $project $argv " }
141-
142- function Get-DotNetRuntimeVersion
143- {
144- <#
145- . DESCRIPTION
146- Runs the dotnet --info command and extracts the .NET Core Runtime version number.
147-
148- . NOTES
149- The .NET Core Runtime version can sometimes be useful for other dotnet CLI commands (e.g. dotnet xunit -fxversion ".NET Core Runtime version").
150- #>
151-
152- $info = dotnet- info
153- [System.Array ]::Reverse($info )
154- $version = $info | Where-Object { $_.Contains (" Version" ) } | Select-Object - First 1
155- $version.Split (" :" )[1 ].Trim()
156- }
157-
158152function Get-TargetFrameworks ($projFile )
159153{
160154 <#
@@ -198,20 +192,43 @@ function Get-NetCoreTargetFramework ($projFile)
198192 Get-TargetFrameworks $projFile | Where-Object { $_ -like " netstandard*" -or $_ -like " netcoreapp*" }
199193}
200194
201- function dotnet-test ($project , $argv )
195+ function Invoke-DotNetCli ($cmd , $proj , $argv )
202196{
203197 # Currently dotnet test does not work for net461 on Linux/Mac
204198 # See: https://github.com/Microsoft/vstest/issues/1318
205- #
206- # Previously dotnet-xunit was a working alternative, however
207- # after issues with the maintenance of dotnet xunit it has been
208- # discontinued since xunit 2.4: https://xunit.github.io/releases/2.4
209- if (! (Test-IsWindows ))
199+
200+ if ((! (Test-IsWindows ) -and ! (Test-IsMonoInstalled )) `
201+ -or (! (Test-IsWindows ) -and ($cmd -eq " test" )))
210202 {
211- $fw = Get-NetCoreTargetFramework $project ;
203+ $fw = Get-NetCoreTargetFramework ( $proj )
212204 $argv = " -f $fw " + $argv
213205 }
214- Invoke-Cmd " dotnet test $project $argv "
206+ Invoke-Cmd " dotnet $cmd $proj $argv "
207+ }
208+
209+ function dotnet-info { Invoke-Cmd " dotnet --info" - Silent }
210+ function dotnet-version { Invoke-Cmd " dotnet --version" - Silent }
211+ function dotnet-restore ($project , $argv ) { Invoke-Cmd " dotnet restore $project $argv " }
212+ function dotnet-build ($project , $argv ) { Invoke-DotNetCli - Cmd " build" - Proj $project - Argv $argv }
213+ function dotnet-test ($project , $argv ) { Invoke-DotNetCli - Cmd " test" - Proj $project - Argv $argv }
214+ function dotnet-run ($project , $argv ) { Invoke-Cmd " dotnet run --project $project $argv " }
215+ function dotnet-pack ($project , $argv ) { Invoke-Cmd " dotnet pack $project $argv " }
216+ function dotnet-publish ($project , $argv ) { Invoke-Cmd " dotnet publish $project $argv " }
217+
218+ function Get-DotNetRuntimeVersion
219+ {
220+ <#
221+ . DESCRIPTION
222+ Runs the dotnet --info command and extracts the .NET Core Runtime version number.
223+
224+ . NOTES
225+ The .NET Core Runtime version can sometimes be useful for other dotnet CLI commands (e.g. dotnet xunit -fxversion ".NET Core Runtime version").
226+ #>
227+
228+ $info = dotnet- info
229+ [System.Array ]::Reverse($info )
230+ $version = $info | Where-Object { $_.Contains (" Version" ) } | Select-Object - First 1
231+ $version.Split (" :" )[1 ].Trim()
215232}
216233
217234function Write-DotnetCoreVersions
0 commit comments