<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Derik Whittaker : PSake</title><link>http://devlicio.us/blogs/derik_whittaker/archive/tags/PSake/default.aspx</link><description>Tags: PSake</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Deploying Database Projects with psake</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2013/03/19/deploying-database-projects-with-psake.aspx</link><pubDate>Tue, 19 Mar 2013 10:32:16 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:103233</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=103233</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=103233</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2013/03/19/deploying-database-projects-with-psake.aspx#comments</comments><description>&lt;p&gt;Recently I joined a project that was using a Sql Server Database Project to manage their DB scheme and so far it is pretty cool.&amp;#160; This project type like others has a deploy/publish option which will allow you to publish your changes to a target database.&amp;#160; And like other project types this is very easy to do via Visual Studio, but if you know me you will know that I like to automate tasks like these rather than have to use the IDE so I did.&amp;#160; Here is what I did in order to use &lt;a href="https://github.com/JamesKovacs/psake"&gt;pSake&lt;/a&gt;, a build automation tool written in powershell, to handle my clean, build and deployment of my database projects.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: Learn&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Understand the automation options available for this &lt;a href="http://msdn.microsoft.com/en-US/library/aa833165(v=vs.80).aspx"&gt;project type&lt;/a&gt; and MSBuild&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 2: Create your psake task file (database.upgrade.ps1)&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="C#" style="display:none;" name="code"&gt;Framework &amp;quot;4.0x64&amp;quot;

properties {
    $buildSolution = &amp;quot;Database.sqlproj&amp;quot;
    $targetServer = $parmTargetServer
    $targetDatabase = $parmTargetdatabase
    $databaseUsername = $parmDatabaseUsername
    $databasePassword = $parmDatabasePassword
}


task default -depends upgrade

task upgrade{

    Write-Host &amp;quot;Upgrading the $target_database database from $build_solution&amp;quot; 
        
    msbuild /target:clean`;build`;deploy 
                /p:UseSandboxSettings=false 
                /p:TargetDatabase=$targetDatabase 
                /p:TargetConnectionString=`&amp;quot;Data Source=$targetServer`;user id=$databaseUsername`;password=$databasePassword`;Pooling=False`&amp;quot; $buildSolution
    
}&lt;/pre&gt;

&lt;p&gt;**** Please not that the formatting of the MSBuild above will NOT RUN and is done to allow the sample code to be clean.&amp;#160; You the entire MSBuild task needs to be on ONE LINE ****&lt;/p&gt;

&lt;p&gt;**** I am setting my properties to ‘parm’ variables because I am passing these into the script by using the –&lt;a href="https://github.com/JamesKovacs/psake/wiki/How-can-I-pass-parameters-to-my-psake-script%3F"&gt;parameters&lt;/a&gt; feature of psake **** &lt;/p&gt;

&lt;p&gt;There is one part of the MSBuild task above that you MUST PAY ATTENTION TO, that is the way items are escaped.&amp;#160; They are being escaped with the back tick (`).&amp;#160; If you omit this you are going to get some odd errors depending on what you do.&amp;#160; These errors could range from ‘Multiple projects were provided’ to issues with the connection string not being formatted.&amp;#160; The root cause for these errors and the need to use the back tick (`) has to do with white space in the connection string… ugg&lt;/p&gt;

&lt;p&gt;One you have this psake task setup you can call it like any other task and it should just work.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=103233" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/PSake/default.aspx">PSake</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>Deploying Asp.Net 4.5 site to IIS Error: ManagedRuntimeVersion to v.45</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2012/12/18/deploying-asp-net-4-5-site-to-iis-error-managedruntimeversion-to-v-45.aspx</link><pubDate>Tue, 18 Dec 2012 14:28:46 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:70720</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=70720</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=70720</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2012/12/18/deploying-asp-net-4-5-site-to-iis-error-managedruntimeversion-to-v-45.aspx#comments</comments><description>&lt;p&gt;Today I was trying to publish a Asp.net 4.5 site to our server and I received the following error;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The Application pool that you are trying to use has the ‘managedRuntimeVersion’ property set to v4.0. This application requires ‘v4.5’&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I thought this was odd so I went to change the App pool, only to see there is no v4.5 option.&amp;#160; After a bit of Goggling my suspicions about v4.5 not having an app pool as v4.5 of .net is inplace update and does not have a new ‘version’.&lt;/p&gt;  &lt;p&gt;After a bit more Goggling and looking at StackoverFlow answers I found the &lt;a href="http://stackoverflow.com/questions/11057814/deploying-a-net-4-5-website-to-an-iis-7-5-server"&gt;solution&lt;/a&gt;, although it was not the ‘selected’ solution but oh well.&lt;/p&gt;  &lt;p&gt;See I am doing my deploy via a powershell script using &lt;a href="https://github.com/JamesKovacs/psake"&gt;pSake&lt;/a&gt; and my deploy looked something like this&lt;/p&gt;  &lt;p&gt;&amp;amp;$msBuildpath /verbosity:m $projectFileAndPath /T:Rebuild /T:Package /p:&amp;quot;Configuration=$buildMode;Packagelocation=$packageFolder&amp;quot;&amp;#160; &lt;br /&gt;/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=True     &lt;br /&gt;/p:MSDeployPublishMethod=RemoteAgent /p:MSDeployServiceUrl=$deploymentServer /p:DeployIisAppPath=$deploymentAppPath&amp;#160; &lt;br /&gt;/p:UserName=$deployuser /p:Password=$deploypassword&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;What I needed to add was the &lt;code&gt;/P:VisualStudioVersion=11.0 &lt;/code&gt;switch to force the right compiler.&amp;#160; Once I added this switch my deploy was right as rain.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=70720" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/ASP.Net+MVC/default.aspx">ASP.Net MVC</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/PSake/default.aspx">PSake</category></item><item><title>PSake and building Silverlight solutions</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2012/02/04/psake-and-building-silverlight-solutions.aspx</link><pubDate>Sat, 04 Feb 2012 18:02:17 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:69465</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=69465</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=69465</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2012/02/04/psake-and-building-silverlight-solutions.aspx#comments</comments><description>&lt;p&gt;If you are using PSake to build .net projects and your project has a silverlight project in it you may get the following error.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.Common.targets(104,9): error : The Silverlight 4 SDK is not installed. [C:\Development\Source\Main\Libraries\SilverlightShared\Silverlight.csproj]&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;When I encountered this I was not sure what to do since I was telling PSake that I was building with the ‘–framework 4.0; option.&amp;#160; However it appears that PSake does not look in the right path for the CORRECT MSBuild version.&amp;#160; The way that I found to solve this problem was to fully qualify the version of MSBuild that I wanted to use.&amp;#160; I did the following&lt;/p&gt;  &lt;p&gt;C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /verbosity:m $SolutionFileWithPath&lt;/p&gt;  &lt;p&gt;I have spoken with James (the author of PSake and he thinks he can have a fix for this) but just incase he does not get it or you have this problem now at least you know how to solve it.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=69465" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/PSake/default.aspx">PSake</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>From 0 to doing solution builds w/ PSake–Part 1 of N</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2012/02/04/from-0-to-doing-solution-builds-w-psake-part-1-of-n.aspx</link><pubDate>Sat, 04 Feb 2012 16:16:30 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:69462</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=69462</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=69462</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2012/02/04/from-0-to-doing-solution-builds-w-psake-part-1-of-n.aspx#comments</comments><description>&lt;p&gt;Recently I decided I would kill two birds with one stone, I figured I would learn a bit of &lt;a href="http://technet.microsoft.com/en-us/scriptcenter/dd742419"&gt;Powershell&lt;/a&gt; and setup some build scripts for our project.&amp;#160; I have been wanting to play around with Powershell for the longest time but could never really either find the time or the reason to play with it.&amp;#160; So I figured that setting up build scripts would be a perfect use of my time (I know I could have choose any other build language/framework but &lt;a href="https://github.com/JamesKovacs/psake"&gt;PSake&lt;/a&gt; meet my need).&lt;/p&gt;  &lt;p&gt;In this post I will walk you though how to setup a build from scratch.&amp;#160; I will warn that because I am a COMPLETE NOOB with powershell it is very likely that my powershell code is less than optimal but it meets my needs.&lt;/p&gt;  &lt;p&gt;In my script we are going to accomplish 3 things:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Setup a PSake Task to perform a clean on our solution &lt;/li&gt;    &lt;li&gt;Setup a PSake Task to perform a build on our solution &lt;/li&gt;    &lt;li&gt;Setup a PSake Task to run Tests in our solution &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Before you continue I would suggest you download PSake and read the Readme.markdown script because this will tell you how to setup PSake to be run via Poweshell.&amp;#160; Once you have read the markdown file you can continue.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating your shell ps1 file.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You will want to create a build file to put the following code into.&amp;#160; Call it build.ps1 for our purposes.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Adding the Clean Task&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The raw PSake ‘Task’ for the clean.&amp;#160; &lt;/p&gt;  &lt;pre class="c#" name="code"&gt;task Clean {
  Invoke-Clean &amp;quot;My Solution&amp;quot; &amp;quot;..\Subfolder\MySolution.sln&amp;quot;  
}&lt;/pre&gt;

&lt;p&gt;As you can see from the task above this is just a pass through call into another method called Invoke-Clean.&amp;#160; I have done this because over time I expect to build out multiple build scripts, one per application, and I don’t want to duplicate the code which does a clean in each script.&lt;/p&gt;

&lt;p&gt;Here is the actual Invoke-Clean function&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;function Invoke-Clean
{  [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)] [string]$BuildName = $null,
        [Parameter(Position=1,Mandatory=1)] [string]$SolutionFileWithPath = $null
        )
    
    Write-Host &amp;quot;Running Clean for&amp;quot; $BuildName &amp;quot;on Solution @&amp;quot; $SolutionFileWithPath
    
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /verbosity:m /t:Clean $SolutionFileWithPath
}&lt;/pre&gt;

&lt;p&gt;The code above is doing 2 things.&amp;#160; &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;I an writing to the host (aka console) that I am running a clean for the given build &lt;/li&gt;

  &lt;li&gt;I am directly referencing the msbuild.exe from the folder.&amp;#160; Now with PSake you don’t always have to do this because it just ‘knows’ where msbuild is located.&amp;#160; However, I am building a silverlight app and the version of msbuild that PSake was finding was wrong and this was my solution for this. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Adding the Compile Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When doing a compile we are going to simply call out to MSBuild and allow it to do its thing.&amp;#160; Below is the PSake task for doing a compile&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;task Compile -depends Clean {
  
  Invoke-Build &amp;quot;My solution&amp;quot; &amp;quot;..\Subfolder\MySolution.sln&amp;quot;  
    
}&lt;/pre&gt;

&lt;p&gt;Again the task above is just wrapper call around the Invoke-Build function.&amp;#160; It is the Invoke-Build function which is doing all the heavy lifting.&amp;#160; Below is our function.&lt;/p&gt;

&lt;p&gt;It is important to point out that our Compile task depends on the Clean task.&amp;#160; This means that the Clean task will be run prior to the actual compile.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;function Invoke-Build
{  
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)] [string]$BuildName = $null,
        [Parameter(Position=1,Mandatory=1)] [string]$SolutionFileWithPath = $null
        )
    
    Write-Host &amp;quot;Running Build for&amp;quot; $BuildName &amp;quot;on Solution @&amp;quot; $SolutionFileWithPath
    
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /verbosity:m $SolutionFileWithPath
}&lt;/pre&gt;

&lt;p&gt;The Invoke-Build above is also calling to a specific version of the MSBuild but this time rather than doing a clean it is doing a compile.&amp;#160; Of course if you want to perform more actions via MSBuild you can find the full list of command line switches on &lt;a href="http://msdn.microsoft.com/en-us/library/ms164311.aspx"&gt;MSDN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding the Test Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The last task I want to build is the testing task.&amp;#160; Because our team is using MSTest the code below is for this.&amp;#160; if you are using NUnit or any other testing framework the code should be close to this but of course calling the correct runner exe.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;task Test -depends Compile, Clean {
  
  Invoke-MSTest &amp;quot;MyTestDll.dll&amp;quot; &amp;quot;..\Subfolder\UnitTests\bin\Debug\MyUnitTests.dll&amp;quot; &amp;quot;MyUnitTests.dll.trx&amp;quot;     
  
}&lt;/pre&gt;

&lt;p&gt;Our Test task above is pretty simple.&amp;#160; We are passing in 3 values, Display name, the dll to test and because this is MSTest I am providing the name of the output file I want generated with the test results.&lt;/p&gt;

&lt;p&gt;Below is the implementation for Invoke-MSTest.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;function Invoke-MSTest
{
  [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)] [string]$TestName = $null,
        [Parameter(Position=1,Mandatory=1)] [string]$TestDll = $null,
        [Parameter(Position=2,Mandatory=1)] [string]$ResultTrx = $null
        )
        
    Write-Host &amp;quot;Running Tests for&amp;quot; $TestName &amp;quot;Located @&amp;quot; $TestDll &amp;quot; Output to:&amp;quot; $ResultTrx
    
    
    if ( Test-Path $ResultTrx )       
    {
        Write-Host &amp;quot;Found&amp;quot; $ResultTrx &amp;quot;it will be deleted prior to running the test&amp;quot;
        Remove-Item $ResultTrx
    }       
    
    $result = mstest /testcontainer:$TestDll /resultsfile:$ResultTrx
       
    foreach( $line in $result )
    {
        if ( $line -ne $null )
        {
            if ( $line.StartsWith(&amp;quot;Passed&amp;quot;) -ne $true )
            {
                $line
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;Looking at the Invoke-MSTest function above you can see I am doing more than simply making a call out to MSTest. I am doing 2 specific things.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;I am checking to see if there is an existing output file and if there is I am deleting it &lt;/li&gt;

  &lt;li&gt;I am only outputting the failure test results to the console.&amp;#160; This allows me to remove all the extra noise of passed tests. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can see from above getting up and running w/ PSake is not that hard and does not take much effort.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=69462" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/PSake/default.aspx">PSake</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Powershell/default.aspx">Powershell</category></item></channel></rss>