@@ -29,13 +29,6 @@ function Invoke-Cmd ($cmd)
2929 if ($LastExitCode -ne 0 ) { Write-Error " An error occured when executing '$cmd '." ; return }
3030}
3131
32- function dotnet-info { Invoke-Cmd " dotnet --info" }
33- function dotnet-version { Invoke-Cmd " dotnet --version" }
34- function dotnet-build ($project , $argv ) { Invoke-Cmd " dotnet build $project $argv " }
35- function dotnet-run ($project , $argv ) { Invoke-Cmd " dotnet run --project $project $argv " }
36- function dotnet-test ($project , $argv ) { Invoke-Cmd " dotnet test $project $argv " }
37- function dotnet-pack ($project , $argv ) { Invoke-Cmd " dotnet pack $project $argv " }
38-
3932function Get-DotNetRuntimeVersion
4033{
4134 $info = dotnet- info
@@ -44,12 +37,52 @@ function Get-DotNetRuntimeVersion
4437 $version.Split (" :" )[1 ].Trim()
4538}
4639
47- function dotnet-xunit ($project , $argv )
40+ function Get-TargetFrameworks ($projFile )
41+ {
42+ [xml ]$proj = Get-Content $projFile
43+
44+ if ($proj.Project.PropertyGroup.TargetFrameworks -ne $null ) {
45+ ($proj.Project.PropertyGroup.TargetFrameworks ).Split(" ;" )
46+ }
47+ else {
48+ @ ($proj.Project.PropertyGroup.TargetFramework )
49+ }
50+ }
51+
52+ function Get-NetCoreTargetFramework ($projFile )
53+ {
54+ Get-TargetFrameworks $projFile | where { $_ -like " netstandard*" -or $_ -like " netcoreapp*" }
55+ }
56+
57+ function dotnet-info { Invoke-Cmd " dotnet --info" }
58+ function dotnet-version { Invoke-Cmd " dotnet --version" }
59+ function dotnet-run ($project , $argv ) { Invoke-Cmd " dotnet run --project $project $argv " }
60+ function dotnet-pack ($project , $argv ) { Invoke-Cmd " dotnet pack $project $argv " }
61+
62+ function dotnet-build ($project , $argv )
63+ {
64+ if ($OnlyNetStandard.IsPresent ) {
65+ $fw = Get-NetCoreTargetFramework $project
66+ $argv = " -f $fw " + $argv
67+ }
68+
69+ Invoke-Cmd " dotnet build $project $argv "
70+ }
71+
72+ function dotnet-test ($project , $argv )
4873{
49- $fxversion = Get-DotNetRuntimeVersion
50- Push-Location (Get-Item $project ).Directory.FullName
51- Invoke-Cmd " dotnet xunit -fxversion $fxversion $argv "
52- Pop-Location
74+ # Currently dotnet test does not work for net461 on Linux/Mac
75+ # See: https://github.com/Microsoft/vstest/issues/1318
76+ #
77+ # Previously dotnet-xunit was a great alternative, however after
78+ # issues with the maintenance dotnet xunit has been discontinued
79+ # after xunit 2.4: https://xunit.github.io/releases/2.4
80+ if (! (Test-IsWindows ) -or $OnlyNetStandard.IsPresent ) {
81+ $fw = Get-NetCoreTargetFramework $project ;
82+ $argv = " -f $fw " + $argv
83+ }
84+
85+ Invoke-Cmd " dotnet test $project $argv "
5386}
5487
5588function Write-DotnetVersion
@@ -108,26 +141,6 @@ function Remove-OldBuildArtifacts
108141 Remove-Item $_ - Recurse - Force }
109142}
110143
111- function Get-TargetFrameworks ($projFile )
112- {
113- [xml ]$proj = Get-Content $projFile
114- ($proj.Project.PropertyGroup.TargetFrameworks ).Split(" ;" )
115- }
116-
117- function Get-NetCoreTargetFramework ($projFile )
118- {
119- Get-TargetFrameworks $projFile | where { $_ -like " netstandard*" -or $_ -like " netcoreapp*" }
120- }
121-
122- function Get-FrameworkArg ($projFile )
123- {
124- if ($OnlyNetStandard.IsPresent ) {
125- $fw = Get-NetCoreTargetFramework $projFile
126- " -f $fw "
127- }
128- else { " " }
129- }
130-
131144# ----------------------------------------------
132145# Main
133146# ----------------------------------------------
@@ -149,19 +162,13 @@ Remove-OldBuildArtifacts
149162$configuration = if ($Release.IsPresent ) { " Release" } else { " Debug" }
150163
151164Write-Host " Building Giraffe.TokenRouter..." - ForegroundColor Magenta
152- $framework = Get-FrameworkArg $src
153- dotnet- build $src " -c $configuration $framework "
165+ dotnet- build $src " -c $configuration "
154166
155167if (! $ExcludeTests.IsPresent -and ! $Run.IsPresent )
156168{
157169 Write-Host " Building and running tests..." - ForegroundColor Magenta
158- $framework = Get-FrameworkArg $tests
159-
160- dotnet- build $tests $framework
161-
162- $xunitArgs = " "
163- if (! (Test-IsWindows )) { $tfw = Get-NetCoreTargetFramework $tests ; $xunitArgs = " -framework $tfw " }
164- dotnet- xunit $tests $xunitArgs
170+ dotnet- build $tests
171+ dotnet- test $tests
165172}
166173
167174if ($Pack.IsPresent )
0 commit comments