Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switched to psake from custom powershell scripts.

  • Loading branch information...
commit 309d702e1e43945b3040fcea530b8ac59a759ab9 1 parent 0b7294f
@enyim enyim authored
View
9 Enyim.Caching.Log4NetAdapter/Enyim.Caching.Log4NetAdapter.csproj
@@ -14,14 +14,6 @@
<TargetFrameworkProfile />
</PropertyGroup>
<Import Project="..\build\CommonProperties.targets" />
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <NoWarn>1591</NoWarn>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <NoWarn>1591</NoWarn>
- </PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\binaries\log4net\log4net.dll</HintPath>
@@ -47,7 +39,6 @@
<ItemGroup>
<None Include="Demo.config">
<SubType>Designer</SubType>
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
View
1  Enyim.Caching.NLogAdapter/Enyim.Caching.NLogAdapter.csproj
@@ -48,7 +48,6 @@
<ItemGroup>
<None Include="Demo.config">
<SubType>Designer</SubType>
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
View
8 Enyim.Caching/Enyim.Caching.csproj
@@ -255,12 +255,8 @@
<Compile Include="UIntEqualityComparer.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="Changes.mdown">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Demo.config">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
+ <None Include="Changes.mdown" />
+ <None Include="Demo.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
View
2  Membase/Demo.config
@@ -24,7 +24,7 @@
- retryTimeout (optional, default 2secs): the time to wait between two retry attempts
-->
- <servers bucket="enyim" bucketPassword="password" userName="Administrator" password="password" retryCount="2" retryTimeout="00:00:02">
+ <servers bucket="enyim" bucketPassword="password" retryCount="2" retryTimeout="00:00:02">
<!--
Provide at least 2-3 urls from your cluster.
Usually you only need to change the host, except when connecting to older versions.
View
8 Membase/Membase.csproj
@@ -78,12 +78,8 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="Demo.config">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Changes.mdown">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
+ <None Include="Demo.config" />
+ <None Include="Changes.mdown" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
View
31 build/CommonProperties.targets
@@ -1,29 +1,44 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
- <OutputPath>..\build\output\$(MSBuildProjectName)\</OutputPath>
- <DefineConstants>TRACE;SIGN</DefineConstants>
+ <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
- <!-- local sign key -->
+
<PropertyGroup>
+ <OutputPath>bin\$(Configuration)</OutputPath>
+ <IntermediateOutputPath>obj\$(Configuration)</IntermediateOutputPath>
<SignAssembly>true</SignAssembly>
- <AssemblyOriginatorKeyFile>..\localbuild.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
+
+ <!-- delay sign the assembly if the PrivateKeyPath property is not specified -->
+ <PropertyGroup Condition=" '$(PrivateKeyPath)' == '' And '$(PrivateKeyName)' == ''">
+ <AssemblyOriginatorKeyFile>..\public_key.snk</AssemblyOriginatorKeyFile>
+ <DelaySign>true</DelaySign>
+ </PropertyGroup>
+
+ <!-- sign the assembly using the specified key file containing both the private and public keys -->
+ <PropertyGroup Condition=" '$(PrivateKeyPath)' != '' ">
+ <AssemblyOriginatorKeyFile>$(PrivateKeyPath)</AssemblyOriginatorKeyFile>
+ <DelaySign>false</DelaySign>
+ </PropertyGroup>
+
+ <!-- sign the assembly using the specified key container containing both the private and public keys -->
+ <PropertyGroup Condition=" '$(PrivateKeyName)' != '' ">
+ <AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
+ <DelaySign>false</DelaySign>
</PropertyGroup>
</Project>
View
3  build/Readme.mdown
@@ -0,0 +1,3 @@
+See "get-help .\build.ps1" from the Windows PowerShell 2.0 prompt.
+
+Build parameters should be adjusted in the 'parameters.ps1' first.
View
67 build/VersionInfo.targets
@@ -25,49 +25,64 @@
</Code>
</Task>
</UsingTask>
-
<PropertyGroup>
- <ShouldGenerate Condition="$(IsReleaseBuild) == 'true'">true</ShouldGenerate>
- <GeneratedAssemblyInfo>obj\$(Configuration)\__versioninfo.cs</GeneratedAssemblyInfo>
- <GitDescribe>obj\$(Configuration)\__gitinfo.cs</GitDescribe>
+ <GeneratedAssemblyInfo>$(IntermediateOutputPath)\__versioninfo.cs</GeneratedAssemblyInfo>
+ <GitDescribe>$(IntermediateOutputPath)\__gitinfo</GitDescribe>
+ <GitVersionCache>$(IntermediateOutputPath)\__gitlastknown</GitVersionCache>
<GitTagMatch Condition=" '$(GitTagMatch)' == '' ">*</GitTagMatch>
+ <HasForcedKey Condition=" '$(PrivateKeyName)' != '' Or '$(PrivateKeyPath)' != '' ">true</HasForcedKey>
</PropertyGroup>
- <PropertyGroup Condition="$(ShouldGenerate) == 'true'">
- <AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
- </PropertyGroup>
-
- <Target Name="CreateAssemblyInfoFromGit" Condition="$(ShouldGenerate) == 'true'">
- <MakeDir Directories="obj\$(Configuration)" ContinueOnError="true" />
- <Exec Command="git describe --tags --match $(GitTagMatch) > $(GitDescribe)" />
+ <Target Name="GetGitVersionInfo">
+ <MakeDir Directories="$(IntermediateOutputPath)" ContinueOnError="true" />
+ <Exec Command="git describe --tags --match $(GitTagMatch) > $(GitDescribe)" IgnoreExitCode="true" />
<ReadLinesFromFile File="$(GitDescribe)">
- <Output TaskParameter="Lines" PropertyName="_Describe"/>
+ <Output TaskParameter="Lines" PropertyName="_CurrentGitVersion"/>
</ReadLinesFromFile>
+ <ReadLinesFromFile File="$(GitVersionCache)" ContinueOnError="true">
+ <Output TaskParameter="Lines" PropertyName="_LastGitVersion"/>
+ </ReadLinesFromFile>
+ <CreateProperty Condition=" '$(_CurrentGitVersion)' == '' " Value="none0.0-yet">
+ <Output PropertyName="_CurrentGitVersion" TaskParameter="Value"/>
+ </CreateProperty>
+ </Target>
+
+ <!--
+ assembly info is only regenerated if the git repo changes
+ this speeds up local builds considerably
+ -->
+ <Target Name="CreateAssemblyInfoFromGit" Condition=" '$(_CurrentGitVersion)' != '$(_LastGitVersion)' Or '$(HasForcedKey)' == 'true' ">
+ <Delete Files="$(GeneratedAssemblyInfo)" />
+
+ <!--
+ cache the current git describe output
+ but only if we're not doing a release (signing with private keys) build
+ -->
+ <WriteLinesToFile File="$(GitVersionCache)" Lines="$(_CurrentGitVersion)" Overwrite="true" Condition="'$(HasForcedKey)' != 'true'"/>
+ <Delete Files="$(GitVersionCache)" Condition =" '$(HasForcedKey)' == 'true' " />
- <GitDescribeToVersion Describe="$(_Describe)">
+ <GitDescribeToVersion Describe="$(_CurrentGitVersion)">
<Output TaskParameter="Version" PropertyName="_AssemblyVersion"/>
</GitDescribeToVersion>
- <Delete Files="$(GeneratedAssemblyInfo)" />
- <WriteLinesToFile File="$(GeneratedAssemblyInfo)" Lines="
-[assembly: System.Reflection.AssemblyKeyName(&quot;enyim&quot;)]
+ <WriteLinesToFile File="$(GeneratedAssemblyInfo)" Overwrite="true"
+ Lines="
[assembly: System.Reflection.AssemblyFileVersion(&quot;$(_AssemblyVersion)&quot;)]
-[assembly: System.Reflection.AssemblyTitle(&quot;$(_Describe)&quot;)]
+[assembly: System.Reflection.AssemblyTitle(&quot;$(_CurrentGitVersion)&quot;)]
[assembly: System.Reflection.AssemblyVersion(&quot;$(_AssemblyVersion)&quot;)]" />
+ <WriteLinesToFile File="$(GeneratedAssemblyInfo)" Overwrite="false"
+ Condition=" '$(PrivateKeyName)' != '' "
+ Lines="[assembly: System.Reflection.AssemblyKeyName(&quot;$(PrivateKeyName)&quot;)]" />
</Target>
- <Target Name="CreateStaticAssemblyInfo" Condition="$(ShouldGenerate) != 'true' And !Exists('$(GeneratedAssemblyInfo)')">
- <MakeDir Directories="obj\$(Configuration)" ContinueOnError="true" />
- <WriteLinesToFile File="$(GeneratedAssemblyInfo)" Lines="
-[assembly: System.Reflection.AssemblyTitle(&quot;2.4.6-custom&quot;)]
-[assembly: System.Reflection.AssemblyFileVersion(&quot;2.4.6.0&quot;)]
-[assembly: System.Reflection.AssemblyVersion(&quot;2.4.6.0&quot;)]" />
- </Target>
-
- <Target Name="BeforeBuild" DependsOnTargets="CreateAssemblyInfoFromGit;CreateStaticAssemblyInfo">
+ <Target Name="BeforeBuild" DependsOnTargets="GetGitVersionInfo;CreateAssemblyInfoFromGit">
+ <Error Condition="!Exists('$(GeneratedAssemblyInfo)')" Text="The version info file is missing, although it should have been generated by the previous step." />
<CreateItem Include="$(GeneratedAssemblyInfo)">
<Output TaskParameter="Include" ItemName="Compile"/>
</CreateItem>
</Target>
+ <Target Name="BeforeClean">
+ <Delete Files="$(GeneratedAssemblyInfo);$(GitDescribe);$(GitVersionCache)" ContinueOnError="true" />
+ </Target>
</Project>
View
127 build/build.ps1
@@ -1,101 +1,52 @@
-$config = "Release"
+<#
+ .SYNOPSIS
+ This is the entry point of the build process.
-function get-assembly-title
-{
- param([string] $Path)
+ .DESCRIPTION
+ By default the build script rebuilds, signs and zips the project,
+ so you need to specify the signing key using either the KeyPath or
+ the KeyName parameters.
- $file = get-item $Path
- $content = [io.file]::ReadAllBytes($file.fullname)
- $a = [System.Reflection.Assembly]::Load($content)
- $d = [System.Attribute]::GetCustomAttribute($a, [System.Reflection.AssemblyTitleAttribute])
+ You can still build the project locally if you need so, but the
+ resulting assemblies will be delay signed, so you need to disable
+ verification using 'sn -Vr' (see the MSDN for more information).
- return $d.Title
-}
+ .PARAMETER TaskList
+ The comma-separated list of task(s) to be run from the build script.
+ The following task name can be passed to the build script:
+ - Clean
+ - Build
+ - Rebuild
-function transform
-{
- param($Markdown, $TemplatePath, $FilePath, $Title)
+ If omitted the 'Default' task will be run.
- return (get-content $TemplatePath) -replace '\$title', $Title -replace '\$content', $Markdown.Transform([io.file]::ReadAllText($FilePath))
-}
+ .PARAMETER KeyPath
+ Specify the full path of a .snk file which will be used to sign
+ the resulting assemblies. The file must contain both the public
+ and the private keys.
-# prepare
-pushd
+ .PARAMETER KeyName
+ Specify the name of the key container which will be used to sign
+ the resulting assemblies. The file must contain both the public
+ and the private keys.
-# tools
-$msbuild = "$Env:SYSTEMROOT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
-$zip = "$Env:ProgramFiles\7-Zip\7z.exe"
+ .EXAMPLE
+ C:\PS> .\build.ps1 Rebuild
-if ((test-path $zip) -eq $False)
-{
- "Could not find 7-zip, exiting."
- return
-}
+ .EXAMPLE
+ C:\PS> .\build.ps1 -KeyPath C:\keys\enyim.snk
-if ((test-path "build.ps1") -eq $True) {
- cd ..
-}
+#>
-$projectRoot = (get-location).path
+param(
+ [string]$TaskList = "Default",
+ [string]$KeyPath = $null,
+ [string]$KeyName = $null)
-$buildRoot = "$projectRoot\build\output"
+. .\parameters.ps1
-$projects = @( "Enyim.Caching", "Membase" )
-$includes = @{ "Enyim.Caching.Log4NetAdapter" = "log4net"; "Enyim.Caching.NLogAdapter" = "NLog" }
+$tmp = $buildParams + @{ "private_key_path" = "$KeyPath"; "private_key_name" = "$KeyName"; }
-# remove the output folders
-
-try {
- if ((test-path $buildRoot) -eq $True) {
- remove-item $buildRoot -Recurse -Force -ErrorAction Stop
- }
-}
-catch {
- write-host "Couldn't clean the build directory, exiting." -foregroundcolor red
- return
-}
-
-md $buildRoot > $nul
-
-[System.Reflection.Assembly]::Load([io.file]::ReadAllBytes("$projectRoot\build\markdownsharp.dll")) > $nul
-$md = new-object MarkdownSharp.Markdown
-
-set-content "$buildRoot\Readme.html" -Value (transform -TemplatePath "$projectRoot\build\template.html" -FilePath "$projectRoot\README.mdown" -Title "Read Me" -Markdown $md)
-
-# build the projects
-.$msbuild /m:1 /v:m /nologo /target:Rebuild /property:"Configuration=Release;IsReleaseBuild=true" Enyim.Caching.sln
-
-$projects | % {
-
- $current = $_
- $currentDest = "$buildRoot\$current"
-
- $includes.Keys | % {
-
- $includeDest = $currentDest + "\" + $includes[$_]
- md $includeDest > $nul
-
- $what = @("$buildRoot\$_\$_.*", "$buildRoot\$_\Demo.config")
- copy $what -Destination $includeDest
- }
-
- set-content "$currentDest\Changes.html" -Value (transform -TemplatePath "$projectRoot\build\template.html" -FilePath "$currentDest\Changes.mdown" -Title "Change Log" -Markdown $md)
- rm "$currentDest\Changes.mdown" > $nul
-
- # we have to remove the tag from the version (emc2.3.4-9786545)
- $version = get-assembly-title -Path "$currentDest\$current.dll"
- $zipname = $projectRoot + "\" + $current + "." + ($version -replace "^[^0-9]+", "") + ".zip"
-
- del $zipname -ErrorAction SilentlyContinue
-
- # 7zip roots the files relative to the current path
- pushd
- cd $currentDest > $nul
-
- .$zip a -mx9 "$zipname" "." "$projectRoot\LICENSE" "$buildRoot\Readme.html"
-
- popd
-}
-
-## all done
-popd
+import-module .\psake.psm1
+invoke-psake -buildFile .\default.ps1 -TaskList $TaskList -framework 4.0 -parameters $tmp
+remove-module psake
View
145 build/default.ps1
@@ -0,0 +1,145 @@
+Properties {
+ # these options must be overriden by the parent script
+ #$solution_name = "Enyim.Caching.sln"
+ #$projects = @( "Enyim.Caching", "Membase" )
+ #$extras = @{ "Enyim.Caching.Log4NetAdapter" = "log4net"; "Enyim.Caching.NLogAdapter" = "NLog" }
+
+ # these are fixed
+ $build_root = Split-Path $psake.build_script_file
+ $source_root = "$build_root\.."
+ $output_root = "$build_root\output"
+}
+
+Include "./utils.ps1"
+FormatTaskName (("-"*20) + "[{0}]" + ("-"*20))
+
+Task Default -depends _NeedsPrivateKey, Rebuild, _Package
+
+Task Clean -depends _Clean {
+ # removes the files created by the build process
+}
+
+Task Build -depends _Build {
+ # builds the projects
+}
+
+Task Rebuild -depends Clean,Build {
+ # clean & build
+}
+
+################################################################################
+################################################################################
+
+Task _CheckConfig {
+ Assert ($solution_name -or $false) "Solution file name must be specifed!"
+ Assert (($projects -ne $null) -and ($projects.length -gt 0)) "Project(s) to be packaged must be specified!"
+}
+
+Task _NeedsPrivateKey {
+ Assert ( $private_key_path -or $private_key_name ) "Either the key path or the key container name must be specified!"
+
+ if ($private_key_path) {
+ Assert (test-path $private_key_path) "The key file '$private_key_path' does not exist."
+ $script:private_key_path = resolve-path $private_key_path
+ }
+}
+
+#################### Clean ####################
+
+Task _Clean -depends _CheckConfig {
+
+ Write-Host "Cleaning the solution." -ForegroundColor Green
+
+ remove-output-dir
+
+ Exec { msbuild "$source_root\$solution_name" /t:Clean /p:"Configuration=Release" }
+}
+
+#################### Build ####################
+
+Task _Build -depends _CheckConfig {
+
+ Write-Host "Building the solution." -ForegroundColor Green
+ "got it: $script:private_key_path"
+
+ Exec { msbuild "$source_root\$solution_name" /t:Build /p:"Configuration=Release;PrivateKeyName=$private_key_name;PrivateKeyPath=$script:private_key_path" }
+}
+
+#################### Package ####################
+
+Task _Package -depends _PreparePackage -PostAction { remove-output-dir } {
+
+ $zip = get7zip
+
+ $projects | % {
+
+ $proj = $_
+ $proj_dest = "$output_root\$proj"
+
+ # we have to remove the tag from the version (emc2.3.4-9786545)
+ $version = get-assembly-title -Path "$proj_dest\$proj.dll"
+ $zipname = $build_root + "\" + $proj + "." + ($version -replace "^[^0-9]+", "") + ".zip"
+
+ del $zipname -ErrorAction SilentlyContinue | out-null
+
+ # 7zip roots the files relative to the current path
+ pushd
+ cd $proj_dest > $nul
+
+ .$zip a -mx9 "$zipname" "." "$source_root\LICENSE" "$output_root\Readme.html"
+
+ popd
+ }
+}
+
+Task _PreparePackage -depends _CheckConfig, _Build -PreAction { remove-output-dir;create-output-dir } {
+
+ $projects | % {
+
+ $proj = $_
+
+ # output\project_name
+ $proj_dest = "$output_root\$proj"
+
+ mkdir $proj_dest | out-null
+ copy "$source_root\$proj\bin\Release\*.*" $proj_dest
+ copy "$source_root\$proj\Demo.config" $proj_dest
+
+ set-content "$proj_dest\Changes.html" `
+ -Value (transform-markdown `
+ -TemplatePath "$build_root\template.html" `
+ -FilePath "$source_root\$proj\Changes.mdown" `
+ -Title "Changes")
+
+ if ($extras -ne $null) {
+ $extras.Keys | % {
+
+ # output\project_name\extra_project
+ $extra_dest = $proj_dest + "\" + $extras[$_]
+ md $extra_dest | out-null
+
+ copy @("$source_root\$_\bin\release\$_.*", "$source_root\$_\Demo.config") -Destination $extra_dest
+ }
+ }
+ }
+
+ set-content "$output_root\Readme.html" `
+ -Value (transform-markdown `
+ -TemplatePath "$build_root\template.html" `
+ -FilePath "$source_root\README.mdown" `
+ -Title "Read Me")
+}
+
+#################### helpers ####################
+
+function remove-output-dir
+{
+ remove-item $output_root -Recurse -Force -ErrorAction SilentlyContinue
+}
+
+function create-output-dir
+{
+ mkdir $output_root -ErrorAction SilentlyContinue | out-null
+}
+
+#################### EOF ####################
View
5 build/parameters.ps1
@@ -0,0 +1,5 @@
+$buildParams = @{
+ "solution_name" = "Enyim.Caching.sln";
+ "projects" = @( "Enyim.Caching", "Membase" );
+ "extras" = @{ "Enyim.Caching.Log4NetAdapter" = "log4net"; "Enyim.Caching.NLogAdapter" = "NLog" };
+}
View
1,208 build/psake.psm1
@@ -0,0 +1,1208 @@
+# psake
+# Copyright (c) 2010 James Kovacs
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+#Requires -Version 2.0
+
+#-- Private Module Variables (Listed here for quick reference)
+[system.collections.stack]$script:context
+
+#-- Public Module Variables -- The psake hashtable variable is initialized in the invoke-psake function
+$script:psake = @{}
+$script:psake.use_exit_on_error = $false # determines if psake uses the "exit()" function when an exception occurs
+$script:psake.log_error = $false # determines if the exception details are written to a file
+$script:psake.build_success = $false # indicates that the current build was successful
+$script:psake.version = "4.00" # contains the current version of psake
+$script:psake.build_script_file = $null # contains a System.IO.FileInfo for the current build file
+$script:psake.framework_version = "" # contains the framework version # for the current build
+$script:psake.default_build_file_name = 'default.ps1'
+
+Export-ModuleMember -Variable "psake"
+
+#-- Private Module Functions
+function ExecuteTask
+{
+ param([string]$taskName)
+
+ Assert (![string]::IsNullOrEmpty($taskName)) "Task name should not be null or empty string"
+
+ $taskKey = $taskName.ToLower()
+
+ Assert ($script:context.Peek().tasks.Contains($taskKey)) "task [$taskName] does not exist"
+
+ if ($script:context.Peek().executedTasks.Contains($taskKey))
+ {
+ return
+ }
+
+ Assert (!$script:context.Peek().callStack.Contains($taskKey)) "Error: Circular reference found for task, $taskName"
+
+ $script:context.Peek().callStack.Push($taskKey)
+
+ $task = $script:context.Peek().tasks.$taskKey
+
+ $taskName = $task.Name
+
+ $precondition_is_valid = if ($task.Precondition -ne $null) {& $task.Precondition} else {$true}
+
+ if (!$precondition_is_valid)
+ {
+ "Precondition was false not executing $name"
+ }
+ else
+ {
+ if ($taskKey -ne 'default')
+ {
+ $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
+
+ if ( ($task.PreAction -ne $null) -or ($task.PostAction -ne $null) )
+ {
+ Assert ($task.Action -ne $null) "Error: Action parameter must be specified when using PreAction or PostAction parameters"
+ }
+
+ if ($task.Action -ne $null)
+ {
+ try
+ {
+ foreach($childTask in $task.DependsOn)
+ {
+ ExecuteTask $childTask
+ }
+
+ $script:context.Peek().currentTaskName = $taskName
+
+ if ($script:context.Peek().taskSetupScriptBlock -ne $null)
+ {
+ & $script:context.Peek().taskSetupScriptBlock
+ }
+
+ if ($task.PreAction -ne $null)
+ {
+ & $task.PreAction
+ }
+
+ $script:context.Peek().formatTaskNameString -f $taskName
+ & $task.Action
+
+ if ($task.PostAction -ne $null)
+ {
+ & $task.PostAction
+ }
+
+ if ($script:context.Peek().taskTearDownScriptBlock -ne $null)
+ {
+ & $script:context.Peek().taskTearDownScriptBlock
+ }
+ }
+ catch
+ {
+ if ($task.ContinueOnError)
+ {
+ "-"*70
+ "Error in Task [$taskName] $_"
+ "-"*70
+ }
+ else
+ {
+ throw $_
+ }
+ }
+ } # if ($task.Action -ne $null)
+ else
+ {
+ #no Action was specified but we still execute all the dependencies
+ foreach($childTask in $task.DependsOn)
+ {
+ ExecuteTask $childTask
+ }
+ }
+ $stopwatch.stop()
+ $task.Duration = $stopwatch.Elapsed
+ } # if ($name.ToLower() -ne 'default')
+ else
+ {
+ foreach($childTask in $task.DependsOn)
+ {
+ ExecuteTask $childTask
+ }
+ }
+
+ if ($task.Postcondition -ne $null)
+ {
+ Assert (& $task.Postcondition) "Error: Postcondition failed for $taskName"
+ }
+ }
+
+ $poppedTaskKey = $script:context.Peek().callStack.Pop()
+
+ Assert ($poppedTaskKey -eq $taskKey) "Error: CallStack was corrupt. Expected $taskKey, but got $poppedTaskKey."
+
+ $script:context.Peek().executedTasks.Push($taskKey)
+}
+
+function Configure-BuildEnvironment
+{
+ if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
+ throw "Error: Invalid .NET Framework version, $framework, specified"
+ }
+ $versionPart = $framework.Substring(0,3)
+ $bitnessPart = $framework.Substring(3)
+ $versions = $null
+ switch ($versionPart)
+ {
+ '1.0' { $versions = @('v1.0.3705') }
+ '1.1' { $versions = @('v1.1.4322') }
+ '2.0' { $versions = @('v2.0.50727') }
+ '3.0' { $versions = @('v2.0.50727') }
+ '3.5' { $versions = @('v3.5','v2.0.50727') }
+ '4.0' { $versions = @('v4.0.30319') }
+ default { throw "Error: Unknown .NET Framework version, $versionPart, specified in $framework" }
+ }
+
+ $bitness = 'Framework'
+ if($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
+ switch ($bitnessPart)
+ {
+ 'x86' { $bitness = 'Framework' }
+ 'x64' { $bitness = 'Framework64' }
+ $null {
+ $ptrSize = [System.IntPtr]::Size
+ switch ($ptrSize)
+ {
+ 4 { $bitness = 'Framework' }
+ 8 { $bitness = 'Framework64' }
+ default { throw "Error: Unknown pointer size ($ptrSize) returned from System.IntPtr." }
+ }
+ }
+ default { throw "Error: Unknown .NET Framework bitness, $bitnessPart, specified in $framework" }
+ }
+ }
+ $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
+
+ $frameworkDirs | foreach { Assert (test-path $_) "Error: No .NET Framework installation directory found at $_" }
+
+ $env:path = [string]::Join(';', $frameworkDirs) + ";$env:path"
+ #if any error occurs in a PS function then "stop" processing immediately
+ # this does not effect any external programs that return a non-zero exit code
+ $global:ErrorActionPreference = "Stop"
+}
+
+function Cleanup-Environment
+{
+ $env:path = $script:context.Peek().originalEnvPath
+ Set-Location $script:context.Peek().originalDirectory
+ $global:ErrorActionPreference = $script:context.Peek().originalErrorActionPreference
+}
+
+#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
+function Resolve-Error($ErrorRecord=$Error[0])
+{
+ "ErrorRecord"
+ $ErrorRecord | Format-List * -Force | Out-String -Stream | ? {$_}
+ ""
+ "ErrorRecord.InvocationInfo"
+ $ErrorRecord.InvocationInfo | Format-List * | Out-String -Stream | ? {$_}
+ ""
+ "Exception"
+ $Exception = $ErrorRecord.Exception
+ for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))
+ {
+ "$i" * 70
+ $Exception | Format-List * -Force | Out-String -Stream | ? {$_}
+ ""
+ }
+}
+
+function Write-Documentation
+{
+ $list = New-Object System.Collections.ArrayList
+ foreach($key in $script:context.Peek().tasks.Keys)
+ {
+ if($key -eq "default")
+ {
+ continue
+ }
+ $task = $script:context.Peek().tasks.$key
+ $content = "" | Select-Object Name, Description
+ $content.Name = $task.Name
+ $content.Description = $task.Description
+ $index = $list.Add($content)
+ }
+
+ $list | Sort 'Name' | Format-Table -Auto
+}
+
+function Write-TaskTimeSummary
+{
+ "-"*70
+ "Build Time Report"
+ "-"*70
+ $list = @()
+ while ($script:context.Peek().executedTasks.Count -gt 0)
+ {
+ $taskKey = $script:context.Peek().executedTasks.Pop()
+ $task = $script:context.Peek().tasks.$taskKey
+ if($taskKey -eq "default")
+ {
+ continue
+ }
+ $list += "" | Select-Object @{Name="Name";Expression={$task.Name}}, @{Name="Duration";Expression={$task.Duration}}
+ }
+ [Array]::Reverse($list)
+ $list += "" | Select-Object @{Name="Name";Expression={"Total:"}}, @{Name="Duration";Expression={$stopwatch.Elapsed}}
+ $list | Format-Table -Auto | Out-String -Stream | ? {$_} # using "Out-String -Stream" to filter out the blank line that Format-Table prepends
+}
+
+#-- Public Module Functions
+function Exec
+{
+<#
+.SYNOPSIS
+Helper function for executing command-line programs.
+
+.DESCRIPTION
+This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error occcured.
+If an error is detected then an exception is thrown. This function allows you to run command-line programs without
+having to explicitly check fthe $lastexitcode variable.
+
+.PARAMETER cmd
+The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
+Required
+
+.PARAMETER errorMessage
+The error message used for the exception that is thrown.
+Optional
+
+.EXAMPLE
+exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
+
+This example calls the svn command-line client.
+
+.LINK
+Assert
+Invoke-psake
+Task
+Properties
+Include
+FormatTaskName
+TaskSetup
+TaskTearDown
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+
+ param(
+ [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
+ [Parameter(Position=1,Mandatory=0)][string]$errorMessage = "Error executing command: " + $cmd
+ )
+ & $cmd
+ if ($lastexitcode -ne 0)
+ {
+ throw $errorMessage
+ }
+}
+
+function Assert
+{
+<#
+.SYNOPSIS
+Helper function for "Design by Contract" assertion checking.
+
+.DESCRIPTION
+This is a helper function that makes the code less noisy by eliminating many of the "if" statements
+that are normally required to verify assumptions in the code.
+
+.PARAMETER conditionToCheck
+The boolean condition to evaluate
+Required
+
+.PARAMETER failureMessage
+The error message used for the exception if the conditionToCheck parameter is false
+Required
+
+.EXAMPLE
+Assert $false "This always throws an exception"
+
+This example always throws an exception
+
+.EXAMPLE
+Assert ( ($i % 2) -eq 0 ) "%i is not an even number"
+
+This exmaple may throw an exception if $i is not an even number
+
+.LINK
+Invoke-psake
+Task
+Properties
+Include
+FormatTaskName
+TaskSetup
+TaskTearDown
+
+.NOTES
+It might be necessary to wrap the condition with paranthesis to force PS to evaluate the condition
+so that a boolean value is calculated and passed into the 'conditionToCheck' parameter.
+
+Example:
+ Assert 1 -eq 2 "1 doesn't equal 2"
+
+PS will pass 1 into the condtionToCheck variable and PS will look for a parameter called "eq" and
+throw an exception with the following message "A parameter cannot be found that matches parameter name 'eq'"
+
+The solution is to wrap the condition in () so that PS will evaluate it first.
+
+ Assert (1 -eq 2) "1 doesn't equal 2"
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+
+ param(
+ [Parameter(Position=0,Mandatory=1)]$conditionToCheck,
+ [Parameter(Position=1,Mandatory=1)]$failureMessage
+ )
+ if (!$conditionToCheck) { throw $failureMessage }
+}
+
+function Task
+{
+<#
+.SYNOPSIS
+Defines a build task to be executed by psake
+
+.DESCRIPTION
+This function creates a 'task' object that will be used by the psake engine to execute a build task.
+Note: There must be at least one task called 'default' in the build script
+
+.PARAMETER Name
+The name of the task
+Required
+
+.PARAMETER Action
+A scriptblock containing the statements to execute
+Optional
+
+.PARAMETER PreAction
+A scriptblock to be executed before the 'Action' scriptblock.
+Note: This parameter is ignored if the 'Action' scriptblock is not defined.
+Optional
+
+.PARAMETER PostAction
+A scriptblock to be executed after the 'Action' scriptblock.
+Note: This parameter is ignored if the 'Action' scriptblock is not defined.
+Optional
+
+.PARAMETER Precondition
+A scriptblock that is executed to determine if the task is executed or skipped.
+This scriptblock should return $true or $false
+Optional
+
+.PARAMETER Postcondition
+A scriptblock that is executed to determine if the task completed its job correctly.
+An exception is thrown if the scriptblock returns $false.
+Optional
+
+.PARAMETER ContinueOnError
+If this switch parameter is set then the task will not cause the build to fail when an exception is thrown
+
+.PARAMETER Depends
+An array of tasks that this task depends on. They will be executed before the current task is executed.
+
+.PARAMETER Description
+A description of the task.
+
+.EXAMPLE
+A sample build script is shown below:
+
+task default -depends Test
+
+task Test -depends Compile, Clean {
+ "This is a test"
+}
+
+task Compile -depends Clean {
+ "Compile"
+}
+
+task Clean {
+ "Clean"
+}
+
+The 'default' task is required and should not contain an 'Action' parameter.
+It uses the 'depends' parameter to specify that 'Test' is a dependency
+
+The 'Test' task uses the 'depends' parameter to specify that 'Compile' and 'Clean' are dependencies
+The 'Compile' task depends on the 'Clean' task.
+
+Note:
+The 'Action' parameter is defaulted to the script block following the 'Clean' task.
+
+The equivalent 'Test' task is shown below:
+
+task Test -depends Compile, Clean -Action {
+ $testMessage
+}
+
+The output for the above sample build script is shown below:
+Executing task, Clean...
+Clean
+Executing task, Compile...
+Compile
+Executing task, Test...
+This is a test
+
+Build Succeeded!
+
+----------------------------------------------------------------------
+Build Time Report
+----------------------------------------------------------------------
+Name Duration
+---- --------
+Clean 00:00:00.0065614
+Compile 00:00:00.0133268
+Test 00:00:00.0225964
+Total: 00:00:00.0782496
+
+.LINK
+Invoke-psake
+Properties
+Include
+FormatTaskName
+TaskSetup
+TaskTearDown
+Assert
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [string]$name = $null,
+ [Parameter(Position=1,Mandatory=0)]
+ [scriptblock]$action = $null,
+ [Parameter(Position=2,Mandatory=0)]
+ [scriptblock]$preaction = $null,
+ [Parameter(Position=3,Mandatory=0)]
+ [scriptblock]$postaction = $null,
+ [Parameter(Position=4,Mandatory=0)]
+ [scriptblock]$precondition = $null,
+ [Parameter(Position=5,Mandatory=0)]
+ [scriptblock]$postcondition = $null,
+ [Parameter(Position=6,Mandatory=0)]
+ [switch]$continueOnError = $false,
+ [Parameter(Position=7,Mandatory=0)]
+ [string[]]$depends = @(),
+ [Parameter(Position=8,Mandatory=0)]
+ [string]$description = $null
+ )
+
+ if ($name.ToLower() -eq 'default')
+ {
+ Assert ($action -eq $null) "Error: 'default' task cannot specify an action"
+ }
+
+ $newTask = @{
+ Name = $name
+ DependsOn = $depends
+ PreAction = $preaction
+ Action = $action
+ PostAction = $postaction
+ Precondition = $precondition
+ Postcondition = $postcondition
+ ContinueOnError = $continueOnError
+ Description = $description
+ Duration = 0
+ }
+
+ $taskKey = $name.ToLower()
+
+ Assert (!$script:context.Peek().tasks.ContainsKey($taskKey)) "Error: Task, $name, has already been defined."
+
+ $script:context.Peek().tasks.$taskKey = $newTask
+}
+
+function Properties
+{
+<#
+.SYNOPSIS
+Define a scriptblock that contains assignments to variables that will be available to all tasks in the build script
+
+.DESCRIPTION
+A build script may declare a "Properies" function which allows you to define
+variables that will be available to all the "Task" functions in the build script.
+
+.PARAMETER properties
+The script block containing all the variable assignment statements
+Required
+
+.EXAMPLE
+A sample build script is shown below:
+
+Properties {
+ $build_dir = "c:\build"
+ $connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi"
+}
+
+Task default -depends Test
+
+Task Test -depends Compile, Clean {
+}
+
+Task Compile -depends Clean {
+}
+
+Task Clean {
+}
+
+.LINK
+Invoke-psake
+Task
+Include
+FormatTaskName
+TaskSetup
+TaskTearDown
+Assert
+
+.NOTES
+You can have more than 1 "Properties" function defined in the script
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [scriptblock]$properties
+ )
+ $script:context.Peek().properties += $properties
+}
+
+function Include
+{
+<#
+.SYNOPSIS
+Include the functions or code of another powershell script file into the current build script's scope
+
+.DESCRIPTION
+A build script may declare an "includes" function which allows you to define
+a file containing powershell code to be included and added to the scope of
+the currently running build script.
+
+.PARAMETER fileNamePathToInclude
+A string containing the path and name of the powershell file to include
+Required
+
+.EXAMPLE
+A sample build script is shown below:
+
+Include ".\build_utils.ps1"
+
+Task default -depends Test
+
+Task Test -depends Compile, Clean {
+}
+
+Task Compile -depends Clean {
+}
+
+Task Clean {
+}
+
+
+.LINK
+Invoke-psake
+Task
+Properties
+FormatTaskName
+TaskSetup
+TaskTearDown
+Assert
+
+.NOTES
+You can have more than 1 "Include" function defined in the script
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [string]$fileNamePathToInclude
+ )
+ Assert (test-path $fileNamePathToInclude) "Error: Unable to include $fileNamePathToInclude. File not found."
+ $script:context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
+}
+
+function FormatTaskName
+{
+<#
+.SYNOPSIS
+Allows you to define a format mask that will be used when psake displays
+the task name
+
+.DESCRIPTION
+Allows you to define a format mask that will be used when psake displays
+the task name. The default is "Executing task, {0}..."
+
+.PARAMETER format
+A string containing the format mask to use, it should contain a placeholder ({0})
+that will be used to substitute the task name.
+Required
+
+.EXAMPLE
+A sample build script is shown below:
+
+FormatTaskName "[Task: {0}]"
+
+Task default -depends Test
+
+Task Test -depends Compile, Clean {
+}
+
+Task Compile -depends Clean {
+}
+
+Task Clean {
+}
+
+You should get the following output:
+------------------------------------
+
+[Task: Clean]
+[Task: Compile]
+[Task: Test]
+
+Build Succeeded
+
+----------------------------------------------------------------------
+Build Time Report
+----------------------------------------------------------------------
+Name Duration
+---- --------
+Clean 00:00:00.0043477
+Compile 00:00:00.0102130
+Test 00:00:00.0182858
+Total: 00:00:00.0698071
+
+.LINK
+Invoke-psake
+Include
+Task
+Properties
+TaskSetup
+TaskTearDown
+Assert
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [string]$format
+ )
+ $script:context.Peek().formatTaskNameString = $format
+}
+
+function TaskSetup
+{
+<#
+.SYNOPSIS
+Adds a scriptblock that will be executed before each task
+
+.DESCRIPTION
+This function will accept a scriptblock that will be executed before each
+task in the build script.
+
+.PARAMETER include
+A scriptblock to execute
+Required
+
+.EXAMPLE
+A sample build script is shown below:
+
+Task default -depends Test
+
+Task Test -depends Compile, Clean {
+}
+
+Task Compile -depends Clean {
+}
+
+Task Clean {
+}
+
+TaskSetup {
+ "Running 'TaskSetup' for task $script:context.Peek().currentTaskName"
+}
+
+You should get the following output:
+------------------------------------
+
+Running 'TaskSetup' for task Clean
+Executing task, Clean...
+Running 'TaskSetup' for task Compile
+Executing task, Compile...
+Running 'TaskSetup' for task Test
+Executing task, Test...
+
+Build Succeeded
+
+----------------------------------------------------------------------
+Build Time Report
+----------------------------------------------------------------------
+Name Duration
+---- --------
+Clean 00:00:00.0054018
+Compile 00:00:00.0123085
+Test 00:00:00.0236915
+Total: 00:00:00.0739437
+
+.LINK
+Invoke-psake
+Include
+Task
+Properties
+FormatTaskName
+TaskTearDown
+Assert
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [scriptblock]$setup
+ )
+ $script:context.Peek().taskSetupScriptBlock = $setup
+}
+
+function TaskTearDown
+{
+<#
+.SYNOPSIS
+Adds a scriptblock that will be executed after each task
+
+.DESCRIPTION
+This function will accept a scriptblock that will be executed after each
+task in the build script.
+
+.PARAMETER include
+A scriptblock to execute
+Required
+
+.EXAMPLE
+A sample build script is shown below:
+
+Task default -depends Test
+
+Task Test -depends Compile, Clean {
+}
+
+Task Compile -depends Clean {
+}
+
+Task Clean {
+}
+
+TaskTearDown {
+ "Running 'TaskTearDown' for task $script:context.Peek().currentTaskName"
+}
+
+You should get the following output:
+------------------------------------
+
+Executing task, Clean...
+Running 'TaskTearDown' for task Clean
+Executing task, Compile...
+Running 'TaskTearDown' for task Compile
+Executing task, Test...
+Running 'TaskTearDown' for task Test
+
+Build Succeeded
+
+----------------------------------------------------------------------
+Build Time Report
+----------------------------------------------------------------------
+Name Duration
+---- --------
+Clean 00:00:00.0064555
+Compile 00:00:00.0218902
+Test 00:00:00.0309151
+Total: 00:00:00.0858301
+
+.LINK
+Invoke-psake
+Include
+Task
+Properties
+FormatTaskName
+TaskSetup
+Assert
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [scriptblock]$teardown)
+ $script:context.Peek().taskTearDownScriptBlock = $teardown
+}
+
+function Invoke-psake
+{
+<#
+.SYNOPSIS
+Runs a psake build script.
+
+.DESCRIPTION
+This function runs a psake build script
+
+.PARAMETER BuildFile
+The psake build script to execute (default: default.ps1).
+
+.PARAMETER TaskList
+A comma-separated list of task names to execute
+
+.PARAMETER Framework
+The version of the .NET framework you want to build. You can append x86 or x64 to force a specific framework. If not specified, x86 or x64 will be detected based on the bitness of the PowerShell process.
+Possible values: '1.0', '1.1', '2.0', '2.0x86', '2.0x64', '3.0', '3.0x86', '3.0x64', '3.5', '3.5x86', '3.5x64', '4.0', '4.0x86', '4.0x64'
+Default = '3.5'
+
+.PARAMETER Docs
+Prints a list of tasks and their descriptions
+
+.PARAMETER Parameters
+A hashtable containing parameters to be passed into the current build script. These parameters will be processed before the 'Properties' function of the script is processed. This means you can access parameters from within the 'Properties' function!
+
+.PARAMETER Properties
+A hashtable containing properties to be passed into the current build script. These properties will override matching properties that are found in the 'Properties' function of the script.
+
+.EXAMPLE
+Invoke-psake
+
+Runs the 'default' task in the 'default.ps1' build script in the current directory
+
+.EXAMPLE
+Invoke-psake '.\build.ps1'
+
+Runs the 'default' task in the '.build.ps1' build script
+
+.EXAMPLE
+Invoke-psake '.\build.ps1' Tests,Package
+
+Runs the 'Tests' and 'Package' tasks in the '.build.ps1' build script
+
+.EXAMPLE
+Invoke-psake Tests
+
+If you have your Tasks in the .\default.ps1. This example will run the 'Tests' tasks in the 'default.ps1' build script.
+
+.EXAMPLE
+Invoke-psake 'Tests, Package'
+
+If you have your Tasks in the .\default.ps1. This example will run the 'Tests' and 'Package' tasks in the 'default.ps1' build script.
+NOTE: the quotes around the list of tasks to execute.
+
+.EXAMPLE
+Invoke-psake '.\build.ps1' -docs
+
+Prints a report of all the tasks and their descriptions and exits
+
+.EXAMPLE
+Invoke-psake .\parameters.ps1 -parameters @{"p1"="v1";"p2"="v2"}
+
+Runs the build script called 'parameters.ps1' and passes in parameters 'p1' and 'p2' with values 'v1' and 'v2'
+
+.EXAMPLE
+Invoke-psake .\properties.ps1 -properties @{"x"="1";"y"="2"}
+
+Runs the build script called 'properties.ps1' and passes in parameters 'x' and 'y' with values '1' and '2'
+
+.OUTPUTS
+ If there is an exception and '$psake.use_exit_on_error' -eq $true
+ then runs exit(1) to set the DOS lastexitcode variable
+ otherwise set the '$psake.build_success variable' to $true or $false depending
+ on whether an exception was thrown
+
+.NOTES
+When the psake module is loaded a variabled called $psake is created it is a hashtable
+containing some variables that can be used to configure psake:
+
+$psake.use_exit_on_error = $false # determines if psake uses the "exit()" function when an exception occurs
+$psake.log_error = $false # determines if the exception details are written to a file
+$psake.build_success = $false # indicates that the current build was successful
+$psake.version = "4.00" # contains the current version of psake
+$psake.build_script_file = $null # contains a System.IO.FileInfo for the current build file
+$psake.framework_version = "" # contains the framework version # for the current build
+
+$psake.use_exit_on_error and $psake.log_error are boolean variables that can be set before you call Invoke-Psake.
+
+You should see the following when you display the contents of the $psake variable right after importing psake
+
+PS projects:\psake> Import-Module .\psake.psm1
+PS projects:\psake> $psake
+
+Name Value
+---- -----
+version 4.00
+build_script_file
+use_exit_on_error False
+build_success False
+log_error False
+framework_version
+
+After a build is executed the following $psake values are updated (build_script_file, build_success, and framework_version)
+
+PS projects:\psake> Invoke-psake .\examples\default.ps1
+Executing task: Clean
+Executed Clean!
+Executing task: Compile
+Executed Compile!
+Executing task: Test
+Executed Test!
+
+Build Succeeded!
+
+----------------------------------------------------------------------
+Build Time Report
+----------------------------------------------------------------------
+Name Duration
+---- --------
+Clean 00:00:00.0798486
+Compile 00:00:00.0869948
+Test 00:00:00.0958225
+Total: 00:00:00.2712414
+
+PS projects:\psake> $psake
+
+Name Value
+---- -----
+version 4.00
+build_script_file C:\Users\Jorge\Documents\Projects\psake\examples\default.ps1
+use_exit_on_error False
+build_success True
+log_error False
+framework_version 3.5
+
+.LINK
+Task
+Include
+Properties
+FormatTaskName
+TaskSetup
+TaskTearDown
+Assert
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+
+ param(
+ [Parameter(Position=0,Mandatory=0)]
+ [string]$buildFile = $script:psake.default_build_file_name,
+ [Parameter(Position=1,Mandatory=0)]
+ [string[]]$taskList = @(),
+ [Parameter(Position=2,Mandatory=0)]
+ [string]$framework = '3.5',
+ [Parameter(Position=3,Mandatory=0)]
+ [switch]$docs = $false,
+ [Parameter(Position=4,Mandatory=0)]
+ [System.Collections.Hashtable]$parameters = @{},
+ [Parameter(Position=5, Mandatory=0)]
+ [System.Collections.Hashtable]$properties = @{}
+ )
+
+ Begin
+ {
+ $script:psake.build_success = $false
+ $script:psake.framework_version = $framework
+
+ if ($script:context -eq $null)
+ {
+ $script:context = New-Object System.Collections.Stack
+ }
+
+ $script:context.push(@{
+ "formatTaskNameString" = "Executing task: {0}";
+ "taskSetupScriptBlock" = $null;
+ "taskTearDownScriptBlock" = $null;
+ "executedTasks" = New-Object System.Collections.Stack;
+ "callStack" = New-Object System.Collections.Stack;
+ "originalEnvPath" = $env:path;
+ "originalDirectory" = Get-Location;
+ "originalErrorActionPreference" = $global:ErrorActionPreference;
+ "tasks" = @{};
+ "properties" = @();
+ "includes" = New-Object System.Collections.Queue;
+ })
+ }
+
+ Process
+ {
+ try
+ {
+ $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
+
+ <#
+ If the default.ps1 file exists and the given "buildfile" isn't found assume that the given
+ $buildFile is actually the target Tasks to execute in the default.ps1 script.
+ #>
+ if((Test-Path $script:psake.default_build_file_name ) -and !(test-path $buildFile)) {
+ $list = New-Object System.Collections.ArrayList
+ foreach($t in $buildFile.Split(',')) {
+ $t1 = $t.Trim()
+ if($t1 -ne $null -or $t1 -ne "") {
+ $list.Add($t1)
+ }
+ }
+ $taskList = $list.ToArray()
+ $buildFile = $script:psake.default_build_file_name
+ }
+
+ # Execute the build file to set up the tasks and defaults
+ Assert (test-path $buildFile) "Error: Could not find the build file, $buildFile."
+
+ $script:psake.build_script_file = dir $buildFile
+ set-location $script:psake.build_script_file.Directory
+ . $script:psake.build_script_file.FullName
+
+ if ($docs)
+ {
+ Write-Documentation
+ Cleanup-Environment
+ return
+ }
+
+ Configure-BuildEnvironment
+
+ # N.B. The initial dot (.) indicates that variables initialized/modified
+ # in the propertyBlock are available in the parent scope.
+ while ($script:context.Peek().includes.Count -gt 0)
+ {
+ $includeBlock = $script:context.Peek().includes.Dequeue()
+ . $includeBlock
+ }
+
+ foreach($key in $parameters.keys)
+ {
+ if (test-path "variable:\$key")
+ {
+ set-item -path "variable:\$key" -value $parameters.$key | out-null
+ }
+ else
+ {
+ new-item -path "variable:\$key" -value $parameters.$key | out-null
+ }
+ }
+
+ foreach($propertyBlock in $script:context.Peek().properties)
+ {
+ . $propertyBlock
+ }
+
+ foreach($key in $properties.keys)
+ {
+ if (test-path "variable:\$key")
+ {
+ set-item -path "variable:\$key" -value $properties.$key | out-null
+ }
+ }
+
+ # Execute the list of tasks or the default task
+ if($taskList.Length -ne 0)
+ {
+ foreach($task in $taskList)
+ {
+ ExecuteTask $task
+ }
+ }
+ elseif ($script:context.Peek().tasks.default -ne $null)
+ {
+ ExecuteTask default
+ }
+ else
+ {
+ throw 'Error: default task required'
+ }
+
+ $stopwatch.Stop()
+
+ "`nBuild Succeeded!`n"
+
+ Write-TaskTimeSummary
+
+ $script:psake.build_success = $true
+ }
+ catch
+ {
+ #Append detailed exception and script variables to error log file
+ if ($script:psake.log_error)
+ {
+ $errorLogFile = "psake-error-log-{0}.log" -f ([DateTime]::Now.ToString("yyyyMMdd"))
+ "-" * 70 >> $errorLogFile
+ "{0}: An Error Occurred. See Error Details Below: " -f [DateTime]::Now >>$errorLogFile
+ "-" * 70 >> $errorLogFile
+ Resolve-Error $_ >> $errorLogFile
+ "-" * 70 >> $errorLogFile
+ "Script Variables" >> $errorLogFile
+ "-" * 70 >> $errorLogFile
+ Get-Variable -scope script >> $errorLogFile
+ }
+
+ $buildFileName = Split-Path $buildFile -leaf
+ if (test-path $buildFile) { $buildFileName = $script:psake.build_script_file.Name }
+ Write-Host -foregroundcolor Red ($buildFileName + ":" + $_)
+
+ if ($script:psake.use_exit_on_error)
+ {
+ exit(1)
+ }
+ else
+ {
+ $script:psake.build_success = $false
+ }
+ }
+ } #Process
+
+ End
+ {
+ # Clear out any global variables
+ Cleanup-Environment
+ [void]$script:context.Pop()
+ }
+}
+
+Export-ModuleMember -Function "Invoke-psake","Task","Properties","Include","FormatTaskName","TaskSetup","TaskTearDown","Assert","Exec"
View
45 build/utils.ps1
@@ -0,0 +1,45 @@
+function global:get-assembly-title
+{
+ param([string] $Path)
+
+ $file = get-item $Path
+ $content = [io.file]::ReadAllBytes($file.fullname)
+ $a = [System.Reflection.Assembly]::Load($content)
+ $d = [System.Attribute]::GetCustomAttribute($a, [System.Reflection.AssemblyTitleAttribute])
+
+ return $d.Title
+}
+
+$Markdown = $null
+
+function global:transform-markdown
+{
+ param($TemplatePath, $FilePath, $Title)
+
+ if ($Markdown -eq $null) {
+ [System.Reflection.Assembly]::Load([io.file]::ReadAllBytes("$variable:build_root\markdownsharp.dll")) > $nul
+ $Markdown = new-object MarkdownSharp.Markdown
+ }
+
+ return (get-content $TemplatePath) -replace '\$title', $Title -replace '\$content', $Markdown.Transform([io.file]::ReadAllText($FilePath))
+}
+
+function global:get7zip
+{
+ $pfx86 = "${Env:ProgramFiles(x86)}"
+ $pf = $env:ProgramFiles
+
+ $tmp = join-path $pf "7-Zip\7z.exe"
+ if (test-path $tmp) { return $tmp }
+
+ $tmp = join-path $pfx86 "7-Zip\7z.exe"
+ if (test-path $tmp) { return $tmp }
+
+ # if this is an x86 host on x64 we'll get the x86 PF folder both time so try to get the x64 dir
+ $tmp = join-path ($pf -replace ' \(x86\)$', "") "7-Zip\7z.exe"
+ if (test-path $tmp) { return $tmp }
+
+ throw "7-Zip is not installed."
+}
+
+# $zip = "$Env:ProgramFiles\7-Zip\7z.exe"
View
BIN  localbuild.snk
Binary file not shown
View
BIN  public_key.snk
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.