PowerShell as part of Efficient Development Environment

Posted in category powershell on 2013-08-15
Tags: powershell

Table of Contents

In this post I will present my small scripting project KuModules. It’s main purpose is to build more efficient and convenient development environment. It is now hosted on GitHub and free for everyone to use or contribute. Well, let me start from saying that I’m the kind of person that spends quite a bit of my time in the console :) and I definitely prefer to have some useful functionality at my hands at any time.

KuModules project is structured as a set of modules with distinctive separation of concerns:

Modules are hierarchically dependent on each other: KuTfsScm is dependent on KuDevelopment and KuCommon, KuDevelopment is dependent on KuCommon. So, if you will try importing KuTfsScm module for example, you will end up having three modules imported: KuCommon, KuDevelopment and KuTfsScm.

Installation procedure is super simple and only requires you to run this command in you powershell session (just copy and paste, nothing serious):

$c = New-Object Net.WebClient; `
$c.Encoding = [Text.Encoding]::Unicode; `
$c.Proxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials; `
$installUrl = "https://raw.github.com/kuznero/KuModules/master/InstallKuModules.ps1"; `
$c.DownloadString( $installUrl ).TrimStart() | iex

In order to automatically have this functionality, just place this code into your $PROFILE script:

Import-Module KuCommon
Import-Module KuDevelopment
Import-Module KuTfsScm

Let me now go through some of the use case scenarios in each module and in order not to make it terribly boring I will skip most of it for the most curious of you who will go and try it out your selves :).

KuCommon

Most noticeable in this module is probably navigation/bookmark management functionality. Everything is controlled with single function go which can navigate to bookmarked path, persist a new bookmark or remove existing one.

Another interesting functionality is to search for programs in the paths as they defined in the %PATH% environment variable:

$ Find-InPaths powershell.???
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
$ f powershell*
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShellCore.format.ps1xml
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShellTrace.format.ps1xml
C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe
C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe.config
$

KuDevelopment

Most important functions here are devoted for working with Visual Studio:

In order to get access to all Visual Studio Command Prompt Tools it’s required to import all visual studio variables with Import-VisualStudioEnvironment. But you should not be bothered calling it every time you start new powershell console - it’s enough to make sure KuDevelopment module is imported as Import-VisualStudioEnvironment will be automatically called.

There is also some functionality devoted for version control (specifically for incrementing versions in AssemblyInfo.cs files):

These function work only on C# projects at the moment!

The first one will take your AssemblyInfo.cs file and change it to have incremented versions (by Major, Minor, Revision or Build). Whether the second one will go through all of such files in your solution and update it respectively. Here is a bit of the demonstration for you:

PS D:\Projects\sandbox\csharp\OptimizedSolution
λ Update-SolutionVersions -IncrementTarget:Revision

Exclude pattern: Test
Skipping [ \Tests\OptimizedSolution.IntegrationTests\OptimizedSolution.IntegrationTests.csproj ]
Skipping [ \Tests\OptimizedSolution.UnitTests\OptimizedSolution.UnitTests.csproj ]

[ CHANGING: \ClassLibrary1\Properties\AssemblyInfo.cs ]
[+] [assembly: AssemblyVersion("1.0.0.0")] -> [assembly: AssemblyVersion("1.0.1.0")]
[+] [assembly: AssemblyFileVersion("1.0.0.0")] -> [assembly: AssemblyFileVersion("1.0.1.0")]
[+] [assembly: AssemblyInformationalVersion("1.0.0.0")]
      -> [assembly: AssemblyInformationalVersion("1.0.1.0")]

[ CHANGING: \ClassLibrary2\Properties\AssemblyInfo.cs ]
[+] [assembly: AssemblyVersion("1.0.0.0")] -> [assembly: AssemblyVersion("1.0.1.0")]
[+] [assembly: AssemblyFileVersion("1.0.0.0")] -> [assembly: AssemblyFileVersion("1.0.1.0")]
[+] [assembly: AssemblyInformationalVersion("1.0.0.0")]
      -> [assembly: AssemblyInformationalVersion("1.0.1.0")]

[ CHANGING: \ConsoleApplication1\Properties\AssemblyInfo.cs ]
[+] [assembly: AssemblyVersion("1.0.0.0")] -> [assembly: AssemblyVersion("1.0.1.0")]
[+] [assembly: AssemblyFileVersion("1.0.0.0")] -> [assembly: AssemblyFileVersion("1.0.1.0")]

Change version: [1.0.0.0 -> 1.0.1.0]

There is another, probably the most important function (for me anyway :) ) - the function that builds your solution, runs all your unit-tests and reports a detailed summary: