1
- Framework ' 4.5.1x86'
2
-
3
- properties {
4
- $base_dir = resolve-path .
5
- $source_dir = " $base_dir \src"
6
- $result_dir = " $base_dir \results"
7
- $artifacts_dir = " $base_dir \artifacts"
8
- $global :config = " debug"
9
- }
10
-
11
-
12
- task default - depends local
13
- task local - depends init, compile, test
14
- task ci - depends clean , release, local
15
-
16
- task clean {
17
- rd " $artifacts_dir " - recurse - force - ErrorAction SilentlyContinue | out-null
18
- rd " $result_dir " - recurse - force - ErrorAction SilentlyContinue | out-null
19
- }
20
-
21
- task init {
22
- # Make sure per-user dotnet is installed
23
- Install-Dotnet
24
- }
25
-
26
- task release {
27
- $global :config = " release"
28
- }
29
-
30
- task compile - depends clean {
31
-
32
- $tag = $ (git tag - l -- points- at HEAD)
33
- $revision = @ { $true = " {0:00000}" -f [convert ]::ToInt32(" 0" + $env: APPVEYOR_BUILD_NUMBER , 10 ); $false = " local" }[$env: APPVEYOR_BUILD_NUMBER -ne $NULL ];
34
- $suffix = @ { $true = " " ; $false = " ci-$revision " }[$tag -ne $NULL -and $revision -ne " local" ]
35
- $commitHash = $ (git rev- parse -- short HEAD)
36
- $buildSuffix = @ { $true = " $ ( $suffix ) -$ ( $commitHash ) " ; $false = " $ ( $branch ) -$ ( $commitHash ) " }[$suffix -ne " " ]
37
-
38
- $buildParam = @ { $true = " " ; $false = " --version-suffix=$buildSuffix " }[$tag -ne $NULL -and $revision -ne " local" ]
39
- $packageParam = @ { $true = " " ; $false = " --version-suffix=$suffix " }[$tag -ne $NULL -and $revision -ne " local" ]
40
-
41
- Write-Output " build: Tag is $tag "
42
- Write-Output " build: Package version suffix is $suffix "
43
- Write-Output " build: Build version suffix is $buildSuffix "
44
-
45
- # restore all project references (creating project.assets.json for each project)
46
- exec { dotnet restore $base_dir \AutoMapper.Collection.sln / nologo }
47
-
48
- exec { dotnet build $base_dir \AutoMapper.Collection.sln - c $config $buildParam -- no- restore / nologo }
49
-
50
- exec { dotnet pack $base_dir \AutoMapper.Collection.sln - c $config -- include- symbols -- no- build -- no- restore -- output $artifacts_dir $packageParam / nologo }
1
+ # Taken from psake https://github.com/psake/psake
2
+
3
+ <#
4
+ . SYNOPSIS
5
+ This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
6
+ to see if an error occcured. If an error is detected then an exception is thrown.
7
+ This function allows you to run command-line programs without having to
8
+ explicitly check the $lastexitcode variable.
9
+ . EXAMPLE
10
+ exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
11
+ #>
12
+ function Exec
13
+ {
14
+ [CmdletBinding ()]
15
+ param (
16
+ [Parameter (Position = 0 , Mandatory = 1 )][scriptblock ]$cmd ,
17
+ [Parameter (Position = 1 , Mandatory = 0 )][string ]$errorMessage = ($msgs.error_bad_command -f $cmd )
18
+ )
19
+ & $cmd
20
+ if ($lastexitcode -ne 0 ) {
21
+ throw (" Exec: " + $errorMessage )
22
+ }
51
23
}
52
24
53
- task test {
25
+ $artifacts = " .\artifacts "
54
26
55
- exec { dotnet test $source_dir \AutoMapper.Collection.Tests - c $config -- no - build -- no - restore -- results - directory $result_dir -- logger trx / nologo }
27
+ if ( Test-Path $artifacts ) { Remove-Item $artifacts - Force - Recurse }
56
28
57
- exec { dotnet test $source_dir \AutoMapper.Collection.EntityFramework.Tests - c $config -- no - build -- no - restore -- results - directory $result_dir -- logger trx / nologo }
29
+ exec { & dotnet clean - c Release }
58
30
59
- }
31
+ exec { & dotnet build - c Release }
60
32
61
- function Install-Dotnet
62
- {
63
- $dotnetCli = (where - is " dotnet" | Select-Object - First 1 )
64
- $install = ($null -eq $dotnetCli -or ($null -ne $env: DOTNET_CLI_VERSION -and $null -eq (& " $dotnetCli " -- info | Where-Object { $_ -like " $env: DOTNET_CLI_VERSION *" })))
65
-
66
- if ($install )
67
- {
68
- $dotnetPath = " $pwd \.dotnet"
69
- $dotnetCliVersion = if ($null -eq $env: DOTNET_CLI_VERSION ) { ' Latest' } else { $env: DOTNET_CLI_VERSION }
70
- $dotnetInstallScriptUrl = ' https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.ps1'
71
- $dotnetInstallScriptPath = ' .\scripts\obtain\dotnet-install.ps1'
72
-
73
- mkdir - Force " .\scripts\obtain\" | Out-Null
74
- Invoke-WebRequest $dotnetInstallScriptUrl - OutFile $dotnetInstallScriptPath
75
- & .\scripts\obtain\dotnet- install.ps1 - Channel " preview" - version $dotnetCliVersion - InstallDir $dotnetPath - NoPath
76
- $env: Path = " $dotnetPath ;$env: Path "
77
- }
78
- }
33
+ exec { & dotnet test - c Release - r $artifacts -- no- build - l trx -- verbosity= normal }
79
34
80
- function where-is ($command ) {
81
- (Get-ChildItem env:\path).Value.split(' ;' ) | `
82
- Where-Object { $_ } | `
83
- ForEach-Object { [System.Environment ]::ExpandEnvironmentVariables($_ ) } | `
84
- Where-Object { test-path $_ } |`
85
- ForEach-Object { Get-ChildItem " $_ \*" - include * .bat, * .exe, * cmd } | `
86
- ForEach-Object { $file = $_.Name ; `
87
- if ($file -and ($file -eq $command -or `
88
- $file -eq ($command + ' .exe' ) -or `
89
- $file -eq ($command + ' .bat' ) -or `
90
- $file -eq ($command + ' .cmd' ))) `
91
- { `
92
- $_.FullName `
93
- } `
94
- } | `
95
- Select-Object - unique
96
- }
35
+ exec { & dotnet pack .\src\AutoMapper\AutoMapper.csproj - c Release - o $artifacts -- no- build }
0 commit comments