Skip to content

Commit

Permalink
(doc) Converting files to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gep13 committed Mar 31, 2016
1 parent 3e20343 commit 8cdee59
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 83 deletions.
52 changes: 27 additions & 25 deletions docs/dot-net-solution.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Here's an example of a basic script you can write to build a Visual Studio.Net solution:

<pre>
```powershell
Task Default -depends Build
Task Build {
Exec { msbuild "helloworld.sln" }
}
</pre>
<p>
```

Builds tend to be more complex than what's shown in the example above. Most builds will need to know what the current directory is relative to where the build script was executed or where to look for code, where to deploy build artifacts or svn settings, etc...

If you haven't guessed already, I'm referring to build properties.

Here's a script that uses properties:
</p>
<pre>

```powershell
#This build assumes the following directory structure
#
# \Build - This is where the project build code lives
# \BuildArtifacts - This folder is created if it is missing and contains output of the build
# \Code - This folder contains the source code or solutions you want to build
#
Properties {
$build_dir = Split-Path $psake.build_script_file
$build_dir = Split-Path $psake.build_script_file
$build_artifacts_dir = "$build_dir\..\BuildArtifacts\"
$code_dir = "$build_dir\..\Code"
}
Expand All @@ -33,40 +33,42 @@ Task Default -Depends BuildHelloWorld
Task BuildHelloWorld -Depends Clean, Build
Task Build -Depends Clean {
Task Build -Depends Clean {
Write-Host "Building helloworld.sln" -ForegroundColor Green
Exec { msbuild "$code_dir\helloworld\helloworld.sln" /t:Build /p:Configuration=Release /v:quiet /p:OutDir=$build_artifacts_dir }
Exec { msbuild "$code_dir\helloworld\helloworld.sln" /t:Build /p:Configuration=Release /v:quiet /p:OutDir=$build_artifacts_dir }
}
Task Clean {
Write-Host "Creating BuildArtifacts directory" -ForegroundColor Green
if (Test-Path $build_artifacts_dir)
{
if (Test-Path $build_artifacts_dir)
{
rd $build_artifacts_dir -rec -force | out-null
}
mkdir $build_artifacts_dir | out-null
Write-Host "Cleaning helloworld.sln" -ForegroundColor Green
Exec { msbuild "$code_dir\helloworld\helloworld.sln" /t:Clean /p:Configuration=Release /v:quiet }
Exec { msbuild "$code_dir\helloworld\helloworld.sln" /t:Clean /p:Configuration=Release /v:quiet }
}
</pre>
<p>
```

Here's a helper script "run-build.ps1" that I use to load the psake module and execute the build:
</p>
<pre>

```powershell
$scriptPath = Split-Path $MyInvocation.InvocationName
Import-Module (join-path $scriptPath psake.psm1)
invoke-psake -framework '4.0'
</pre>
<p>I run the build in powershell by just running the script:</p>
<pre>
```

I run the build in powershell by just running the script:

```
PS > .\run-build.ps1
</pre>
<p>
```

The output from running the above build:
</p>
<pre>

```
-------------------------[Clean]-------------------------
Creating BuildArtifacts directory
Cleaning helloworld.sln
Expand All @@ -92,4 +94,4 @@ Clean 00:00:09.4624557
Build 00:00:12.2191711
BuildHelloWorld 00:00:21.6931903
Total: 00:00:21.8308190
</pre>
```
16 changes: 7 additions & 9 deletions docs/getting-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ You can read this faq for help on how to use psake.

You can also use the powershell command-let get-help on the *Invoke-psake* function to get more detailed help.

<pre>
# First import the psake.psm1 file
```powershell
# First import the psake.psm1 file
Import-Module .\psake.psm1
Get-Help Invoke-psake -full
</pre>
```

To list functions available in the psake module:

<pre>
```
C:\Software\psake> Get-Command -module psake
CommandType Name Definition
Expand All @@ -26,13 +26,11 @@ Function Properties ..
Function Task ...
Function TaskSetup ...
Function TaskTearDown ...

</pre>
```

To Get example usage for individual functions in the psake powershell module, use Get-Help, For example:

<pre>

```
C:\Software\psake> Get-Help Assert -examples
NAME
Expand All @@ -57,4 +55,4 @@ SYNOPSIS
This exmaple may throw an exception if $i is not an even number
</pre>
```
13 changes: 6 additions & 7 deletions docs/how-does-psake-work.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<p>**psake** is a domain specific language to create builds using a dependency pattern just like Ant, NAnt, Rake or MSBuild.
**psake** is a domain specific language to create builds using a dependency pattern just like Ant, NAnt, Rake or MSBuild.

You create a build script using PowerShell that consists of _Tasks_ which are simply function calls. Each _Task_ function can define dependencies on other _Task_ functions.

In the example script below, Task _Compile_ depends on Tasks _Clean_ and _Init_, which means that before Task _Compile_ can execute, both tasks _Clean_ and _Init_ have to execute. psake ensures that this is done.
</p>
<pre>

```powershell
Task Compile -Depends Init,Clean {
"compile"
}
Expand All @@ -16,7 +16,6 @@ Task Clean -Depends Init {
Task Init {
"init"
}
</pre>
<p>
psake reads in your build script and executes the _Task_ functions that are defined within it and enforces the dependencies between tasks. The great thing about psake is that it is written in PowerShell and that means you have the power of .NET and all the features of PowerShell at your disposal within your build script. Not to mention that you don't have to pay the *XML* bracket tax anymore.
</p>
```

psake reads in your build script and executes the _Task_ functions that are defined within it and enforces the dependencies between tasks. The great thing about psake is that it is written in PowerShell and that means you have the power of .NET and all the features of PowerShell at your disposal within your build script. Not to mention that you don't have to pay the *XML* bracket tax anymore.
32 changes: 16 additions & 16 deletions docs/property-overrides.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<p>You can override a property in your build script using the "properties" parameter of the Invoke-psake function. The following is an example:</p>
<pre>
You can override a property in your build script using the "properties" parameter of the Invoke-psake function. The following is an example:

```
C:\PS>Invoke-psake .\properties.ps1 -properties @{"x"="1";"y"="2"}
</pre>
<p>
```

The example above runs the build script called "properties.ps1" and passes in parameters 'x' and 'y' with values '1' and '2'. The parameter value for the "properties" parameter is a PowerShell hashtable where the name and value of each property is specified. Note: You don't need to use the "$" character when specifying the property names in the hashtable.

The "properties.ps1" build script looks like this:
</p>
<pre>

```powershell
properties {
$x = $null
$y = $null
Expand All @@ -16,19 +17,18 @@ properties {
task default -depends TestProperties
task TestProperties {
task TestProperties {
Assert ($x -ne $null) "x should not be null"
Assert ($y -ne $null) "y should not be null"
Assert ($z -eq $null) "z should be null"
}
</pre>
<p>
```

The value of $x should be 1 and $y should be 2 by the time the "TestProperties" task is executed. The value of $z was not over-ridden so it should still be $null.
</p>
<p>


To summarize the differences between passing parameters and properties to the Invoke-psake function:
</p>
<ul>
<li>Parameters and "properties" can both be passed to the Invoke-psake function simultaneously</li>
<li>Parameters are set before any "properties" blocks are run</li>
<li>Properties are set after all "properties" blocks have run</li>

* Parameters and "properties" can both be passed to the Invoke-psake function simultaneously
* Parameters are set before any "properties" blocks are run
* Properties are set after all "properties" blocks have run
18 changes: 9 additions & 9 deletions docs/retry-rules.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
You can set retry rules for a ~~task~~ exec function by using the **maxRetries** parameter. For example, to have your ~~task~~ exec retry 3 times due to **any** unhandled exception:
You can set retry rules for a **task** exec function by using the **maxRetries** parameter. For example, to have your **task** exec retry 3 times due to **any** unhandled exception:

~~task MyTask -maxRetries 3~~
exec -maxRetries 3
```powershell
exec -maxRetries 3
```

You can also optionally specify a ~~task~~ exec to be retried only when a certain error message occurs using the **retryTriggerErrorPattern** parameter in conjunction with **maxRetries**:
You can also optionally specify a **task** exec to be retried only when a certain error message occurs using the **retryTriggerErrorPattern** parameter in conjunction with **maxRetries**:

~~task MyTask -maxRetries 3 -retryTriggerErrorPattern "Service is not currently available."~~

exec -maxRetries 3 -retryTriggerErrorPattern "Service is not currently available."
```powershell
exec -maxRetries 3 -retryTriggerErrorPattern "Service is not currently available."
```

### Notes
1. psake will wait 1 second between retries.
2. The default for the maxRetries parameter if not specified is 0, i.e. the task will not be retried.
1. The default for the maxRetries parameter if not specified is 0, i.e. the task will not be retried.
33 changes: 16 additions & 17 deletions docs/run-psake.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
<p>
*psake* is a PowerShell module and is contained in a file named psake.psm1.

There are 2 ways to run psake:

1) Import the psake.psm1 module and call the Invoke-psake function
2) Call the psake.ps1 helper script
2) Call the psake.ps1 helper script

Following is the first option:
</p>
<pre>

```powershell
Import-Module .\psake.psml
Invoke-psake .\default.ps1
</pre>
<p>
```

Second option:
</p>
<pre>

```powershell
# call the psake.ps1 file directly
.\psake.ps1 .\default.ps1
</pre>
<p>
```

When you call the psake.ps1 script, it forwards the parameters on to the Invoke-psake function.

The benefit of option 1 is that you can get detailed help on the Invoke-psake function:
</p>
<pre>

```powershell
Import-Module .\psake.psml
Get-Help Invoke-psake -full
</pre>
<p>
```

You may also consider making a helper script for your builds so that you can configure any psake options (-framework, etc)

The following is an example helper script that configures psake to use the .NET 4.0 framework.
</p>
<pre>

```powershell
Import-Module (join-path $PSScriptRoot psake.psm1) -force
Invoke-psake -framework '4.0'
</pre>
```

0 comments on commit 8cdee59

Please sign in to comment.