Monday, October 21, 2013

Windows 8.1 Install: Don't panic on the first screen

So I am creating my standard development VM's for Windows 8.1 (Visual Studio 2013 and SQL Server 2012)  and the first screen that shows up during install is:


I tend to be a meticulous chaps and was surprised I'd selected the Windows 8 ISO by mistake. To quote the late, great Douglas Adams, "Don't panic." Windows 8.1 is just a flavor of Windows 8 so the screenshot is correct but the OS being installed is Windows 8.1.

Sunday, October 20, 2013

If it's an MSDN licensed Windows 8 -- no auto upgrade to Windows 8.1

I upgraded to Windows 8 immediately when it was released. The reason was simple -- Windows 8 64-bit supports Hyper-V with 64-bit VMs. As a server developer Windows 2008 R2 and Windows 2012 are 64-bit only. Windows 8's ability to mount ISO's is also a nice perk.

So Windows 8.1 arrives and my laptop that came initially with Windows 8.0 found the update in Windows Store without issue. Alas most of my other machines are installed using the MSDN Windows 8.0 ISO. After some googling (I binged it!) I found: Not all versions of Windows 8 support the free update from the Windows Store. The black list included editions of Windows 8 installed from an MSDN ISO and activated using multiple activation keys as is the case with MSDN.

Microsoft spells it out clearly here: Why can't I find the update in the Store?

Tuesday, October 15, 2013

PowerShell: Preventing Arrays from Acting like Scalars

PowerShell like many scripting languages plays fast and loose with types. When dealing with arrays, this can be problematic because PowerShell will interpret arrays to be scalars. This is exacerbated by PowerShell using the + operator to append items to an array. If the alleged array variable is treated as a scalar and not an array, the + operator has a completely different meaning.

This write-up will demonstrate how to insure arrays behave as arrays and not scalars. This write-up will cover the simple case of arrays created programmatically and the more interesting cases of arrays created through serialization via cmdlets and arrays returned by functions.

Consider the PowerShell script that any C++/C# developer would have written where allegedly the variable's type is specified ([Array] $BadArray):

[Array] $BadArray

$BadArray += 1
$BadArray += 2
$BadArray += 3

Write-Host "BadArray: $BadArray"

It should be noted that the line "[Array] $BadArray" does not declare a variable of type Array but instead casts a variable.

The previous code executes without an error and it is assumed the += operator will append the values of 1, 2, and 3 to be elements of the array. The output of this script should be an array with elements 1, 2, 3 but instead is the scalar value of 6:


Clearly, the variable $BadArray was treated as a scalar integer as 1 + 2 + 3 = 6.

The correct way to declare an array is to assign the array to an empty array using $() as is the case with variable $GoodArray below:

$GoodArray = @()

$GoodArray += 1
$GoodArray += 2
$GoodArray += 3

Write-Host "GoodArray: $GoodArray"

The output generated is as expected, an array containing elements 1, 2, and 3:


To make things interesting, an array of two elements is exported to an XML file using cmdlet Export-Clixml and then re-imported as an array using cmdlet Import-Clixml. After the array is de-serialized an additional element is appended to the end of the array ($BadFromDiskArray += 3):


$ToDiskArray = @()
$ToDiskArray += 1
$ToDiskArray += 2
$SerializationFile = 'D:\Blog\SerializedData.xml'

$ToDiskArray | Export-Clixml $SerializationFile
$BadFromDiskArray = Import-Clixml $SerializationFile
$BadFromDiskArray += 3
Write-Host "BadFromDiskArray: $BadFromDiskArray"

The output from the previous script shows the array being serialized and de-serialized correctly. The reason this works is because the array that was serialized has more than one element when it was serialized:


The previous example behaved correctly. The twist occurs when the serialized array contains one element. The below snippet shows an array with one element being serialized and de-serialized. Once the array is de-serialized two elements are appended to the array with the += operator (+= 2 and +=3):
$SerializationFile = 'D:\Blog\SerializedData.xml'

$ToDiskArray = @()
$ToDiskArray += 1
$ToDiskArray | Export-Clixml $SerializationFile
$BadFromDiskArray = Import-Clixml $SerializationFile
$BadFromDiskArray += 2
$BadFromDiskArray += 3
Write-Host "BadFromDiskArray: $BadFromDiskArray"

When the previous script is executed the de-serialized array is converted to a scalar because the array has one element:

This is the worst kind of developer nightmare – the code works correctly sometimes but at other times does not work. The solution is not to assign arrays directly from the return value from a cmdlet. The following code is not correct:

$BadFromDiskArray = Import-Clixml $SerializationFile

The correct way to handle arrays is to always append the results from the function to the array using the += operator. When the left-hand side is an array and the right-hand side is a scalar the += appends the scalar to the array on the left-hand side. When the left-hand side is an array and the right-hand side is an array the += appends the array to the right to the end of the array on the left.

The following snippet shows a single-element array being serialized and de-serialized. The de-serialized value may be an array or may be a scalar. The += operator highlighted below with boldface appends the value or values returned by Import-Clixml to the array on the left:

$ToDikArray = @()
$ToDiskArray += 1
$SerializationFile = 'D:\Blog\SerializedData.xml'
$ToDiskArray | Export-Clixml $SerializationFile

$GoodFromDiskArray = @()
$GoodFromDiskArray += Import-Clixml $SerializationFile
$GoodFromDiskArray += 2
$GoodFromDiskArray += 3
Write-Host "GoodFromDiskArray: $GoodFromDiskArray"

The results of this script demonstrate the array behaving as an array by the following screenshot displaying all the elements of the array and not behaving like a scalar:


Using += applies to both cmdlets and functions. Consider the following function that returns an array of elements based on the input parameter $numberOfElements:

function CreateAnArray($numberOfElements)
{
    $ReturnValue = @()
    for ($i = 0 $i -lt $numberOfElements $i++)
    {
        $ReturnValue += $i + 1
    }
    
    return $ReturnValue
}   

The previous function behaves correctly. The array is created as an empty array correctly ($ReturnValue = @()) and each element is appended to the array correctly using operator += ($ReturnValue += $i + 1).

The following code would exhibit incorrect behavior where an array, $EvilFromFunctionArray,  is assigned to the return value of the function:

$EvilFromFunctionArray = CreateAnArray(1)
$EvilFromFunctionArray += 2
$EvilFromFunctionArray += 3
Write-Host "EvilFromFunctionArray: $EvilFromFunctionArray"

The previous code will display a value of 6 because the alleged array $EvilFromFunctionArray is a scalar due to assignment.

The following code would exhibit correct behavior where the array is created as an empty array and the return value to the function is appended to the existing array variable $GoodFromFunctionArray:

$GoodFromFunctionArray = @()
$GoodFromFunctionArray += CreateAnArray(1)
$GoodFromFunctionArray += 2
$GoodFromFunctionArray += 3
Write-Host "GoodFromFunctionArray: $GoodFromFunctionArray"

The previous code will display a value of 1, 2, 3 because the return value of the CreateAnArray function is appended to the array variable $GoodFromFunctionArray.

The lesson learned is with arrays, append, and don't assign.

Thursday, October 10, 2013

Visual Studio Online (cloud-hosted TFS) for non-Visual Studio Developers

Update (September 18, 2014): the link to Team Explorer for Microsoft Visual Studio 2013 RC in this post was updated to reference the production release of this product Team Explorer for Microsoft Visual Studio 2013.

I was approached by a team of firmware engineers who had heard my pontificating on Microsoft's Visual Studio Online (Signing up for Microsoft Hosted Team Foundation Server (TFS) ). The firmware team was using SVN which gets high praise for how it integrates with Windows Explorer using various free open source clients. The question the firmware team asked me was, "Did they need to purchase Visual Studio to access Visual Studio Online?"

Team Explorer is the stand-alone client for accessing Visual Studio Online.  It just so happens that Visual Studio Online's Team Explorer is free from Microsoft so there are no barriers to using it with Team Foundation Server (TFS) run on an intranet or Visual Studio Online. Team Explorer is actually integrated with Visual Studio but it can be run stand-alone. When run stand-alone, Team Explorer is actually a one trick version of Visual Studio. The one trick it can perform is access to a TFS instance or Visual Studio Online.

The push to Visual Studio Online  is not meant to be a criticism of SVN. I respect SVN and have enjoyed using it. I have enjoyed using it in an environment with a strong IT department to manage SVN and insure it is backed up properly and maintained in a secure manner. Microsoft's Visual Studio Online is backed up and secured by Microsoft and Visual Studio is free for up to five users with source code access and an unlimited number of "stack holder" users with bug/task tracking access (Visual Studio Online - Stakeholder License).

To download Microsoft's Team Explorer at no charge access any of the following sites:

To download there is no need to log in or have an MSDN account. The Visual Studio 2013 download site is as follows:



When you click on download, you are prompted to download the executable or CD/DVD format (ISO):


Check the version to download and click on Next:


Obviously if the download does not start, you should pay attention to the prompt, "If your download has not start after 30 seconds, Click here".


Wednesday, September 25, 2013

Signing up for Visual Studio Online (cloud-based Team Foundation Server)

October 3, 2014: updated to reflect Microsoft's rebranding and subsequently changing the name of Hosted TFS to Visual Studio Online. Additionally this posted was updated to reflect the prices of Visual Studio as of October 3, 2014.

This article introduces Microsoft's cloud-based Team Foundation Server (TFS), Visual Studio Online. Signing up for Visual Studio ONline will be demonstrated as will how to access this cloud-based TFS from Visual Studio 2012.


Introduction


Visual Studio Online is free for up to five users -- at least for the present (as of September 2013). This cloud-based version of TFS supports source code control, bug/work-item tracking and project management. More importantly, this service places your source code in an environment where Microsoft will provide, free of charge, complete source control backup. Developers can access source code remotely using a standard Microsoft accounts. The URL used to access an instance of Visual Studio Online is of the elegant form (a vanity URL): YOUR_NAME_HERE.visualstudio.com.

A classic use of Visual Studio Online came when I started working at a firm that was using SVN. The server hosting SVN was an older PC, running Linux, setup by a developer who was no longer at the firm. The company used outsourced IT and the SVN host was rarely backed up if ever. There were five developers on the team. In order to access SVN remotely developers had to access the company's incredibly slow VPN. Visual Studio Online was an easy sell in this environment.

Signing up for Visual Studio Online

Signing up for Visual Studio Online is straightforward. If you already have a Microsoft account (hotmail.com, live.com, outlook.com, etc.) skip to Step 2. You can also skip to Step 2 if your work email address is already mapped to be used as a Microsoft account. It is important to note that your Microsoft account will be the initial administrator for Visual Studio Online. Other administrative rights can be assigned once signup is completed.

Step 1: create a Microsoft account. You can use your work email as Microsoft account name and sign up at https://signup.live.com/signup.aspx or just create an email account at Outlook.com.

Step 2: in Internet Explorer (when working with Microsoft service, IE is often the best choice of browsers) navigate to http://tfs.visualstudio.com.


Step 3: clearly shown on this page is the "Sign up for free" button which should be clicked on.



Step 4: pick the name for your source code vanity URL where below I chose to name my source code control after software pioneer Admiral Grace Hopper:


Step 5: click on "Create Account" which will display the log in screen for the Microsoft account.


Step 6: sign in using your Microsoft account. You may have to provide additional information as Microsoft validates your account.


Step 7: create a project by clicking on "New team project".  Below the new project name was MarkI after the computer Admiral Hopper first developed software on:


Step 8: clicking on "Create project" will create the project within TFS. Remember that Visual Studio Online provides process management capabilities so for "Process template" the template, "Microsoft Visual Studio Scrum 3.0" was selected (the default value).


Step 9: from the previous screen click on "Navigate to project":



Step 10: click on "Manage all members..." in order to add your coworkers as TFS users. Make sure your coworkers have created Microsoft accounts so they can be added to TFS as users.

Access Visual Studio Online from Visual Studio

Once Visual Studio Online has been setup, Visual Studio can be used to utilize this free source code service. In support of this, Visual Studio (below Visual Studio 2012 is shown) contains a Team menu item:


When the Team is selected the user is given the option to "Connect to Team Foundation Server":


Click on "Connect to Team Foundation Server" reveals rather indirectly the "Team Explorer - Connect" view:


Under "Team Foundation server" select the Connect link button which displays the "Connect to Team Foundation Server" dialog:



From the "Connect to Team Foundation Server" dialog, select "Servers" which displays the "Add/Remove Team Foundation Server" dialog:


From the "Add/Remove Team Foundation Server" dialog, select "Add" which displays the "Add Team Foundation Server" dialog:


In the "Add Team Foundation Server" dialog, add the name/URL of your TFS location which for the purposes of this article was: admiralgracehopper.visualstudio.com. Click on "OK" which prompts users to enter their Microsoft account credentials which allows them to access TFS:


Once a user is logged in they are returned to the "Add/Remove Team Foundation Server" dialog:


Clicking on "Close" to close this dialog returns the users to the "Connect to Team Foundation Server" dialog which now lists the "Team Projects" that include the MarkI project. This project was previously created via the Visual Studio Online web site:



From this screen the MarkI project can be checked following by clicking on the "Connect" button which closes the "Connect to Team Foundation Server" dialog. The connection to TFS is established along with a connection to the MarkI project.

To access source code control select the sub menu item: View | Other Windows | Source Control Explorer:


Clicking on the "Source Control Explorer" sub menu item displays the "Source Control Explorer" dialog:


Right clicking on the MarkI project shows what is expected, access to source code related functionality:


Pricing
Visual Studio Online from Microsoft is a fantastic service given that it is free for up to five users with access to source code control. An unlimited number of Stake Holder users (accessing to bugs/tasks) is supported Visual Studio Online (cloud hosted TFS): Unlimited (no cost) users can Create/Access Bugs/Tasks. To find out more information on project navigate to the Visual Studio Online web site (http://visualstudio.com) and select the "Pricing" menu:



The pricing menu displayed is as follows:



From the pricing menu select "Overview of User Plans" which shows the pricing (as of October 3,2014):



Of note for any startup for small development firm is user plan "Visual Studio Online Basic". As stated previously (and above in the screenshot) five users with access to source code control (a.k.a. "5 users FREE"). Not mentioned in any of the user plans are the unlimited stakeholders.

Clicking on the Stakeholders buttons reveals an overview of the cost (free) and capabilities of such users:



Friday, September 20, 2013

Affordable Windows Phone 8 development (the Nokia Lumia 521)

The goal here is to develop software for Windows Phone 8 and not pay thousands of dollars a year. There is a cost to getting started in Windows Phone 8 development but developers can code for this environment for a reasonable cost.  $249.99 is all it should cost per-year to develop on Windows Phone 8. Let's break down the options.

The phone we all love, the Nokia Lumia 1020 is $199 with a two year contract from AT&T. The plan costs $39.99 per month for 450 minutes and $20 for 300 MB of data monthly (as of September 2013). Summing it all up, there is a cost of $1638.76 over the life of the two year plan.

Paul Thurrott's Super Site for Windows (http://winsupersite.com) points out that the Nokia Lumia 520 can be purchased for $99 (In Praise of the Nokia Lumia 520) with no commitment. This phone could be used with WIFI only or could be placed on an AT&T GoPhone (pay as you go plan). You can get a GoPhone plan for $25 a month for calling (250 minutes per month) and $5 a month for data (50 MB per $5). It would be pretty reasonable to develop with such a phone and only turning on calling/data when it is required.

There is better alternative, the Nokia Lumia 521. The Lumia 521 costs $149.99 without a contract. For $100 you get 1000 minutes to use over an entire year -- Prepaid phones t-mobile. Text messages reduce the balance by 10 cents each message  For $30 per month you can get 100 calling minutes and unlimited web (the web is throttled after 200 MB of data access). Obviously with no data plan, the phone can be used on WIFI.

So for $249.99 a year it is possible to develop with Windows Phone 8.

If you are torn between the Lumia 520 and 521, findthebest.com has a great comparison between the two phones: Nokia-Lumia-520-vs-Nokia-Lumia-521.

The Lumia 520 and 521 are nearly feature equivalent. The Lumia 520 comes with a Qualcomm Snapdragon MSM8227 processor running at 1 GHz. The Lumia 521 comes with a Qualcomm S4 Plus Snapdragon MSM8227 processor running at 1.4 GHz.

The Lumia 521 makes a good phone for a kid (replacing their pricey, fragile screened IPod touch). A key application for the phone is Metro Talk (http://metrotalk.wordpress.com). Google does not provide a native Google Voice application for Windows Phone 8. Metrotalk supports Google Voice which means using WIFI text messages can be sent for free using the phone number associated with Google Voice.

With alternatives like the Lumia 521 and the Lumia 520, costs should be a barrier to Windows Phone 8 development.



Thursday, September 19, 2013

Visual Studio Online (cloud based TFS): Getting multiple labels using TF GET (without deleting the files associated with the previous TF GET)

This article presents how to pull source code from TFS using the TF utility. Pulling source code in this manner is the first step in automating a build. Rather than simply pulling one label from a collection in TFS, this article presents how to pull multiple labels.

As a developer, I am a big fan of Microsoft's hosted Team Foundation Server (TFS) which is free for up to five users: http://tfs.visualstudio.com. So for a project I work on, I was tasked with automating the build using PowerShell. Before writing any PowerShell script, I wanted to learn how to pull code using TF.

Within TFS, I created two team projects: ATest and BTest. I placed a single text file in each project. I created a label for each project ATest01 and BTest01 respectively. Project is the terminology used by Microsoft's hosted TFS. ATest01 and BTest02 are actually TFS collections.

I did not want to test with the production code from TFS simply because it takes too long to pull the code so two project each with one file seemed like an efficient development environment.

TF for Visual Studio 2012 is documented here: http://msdn.microsoft.com/en-us/library/cc31bk2e.aspx. How to run TF is documented here: http://msdn.microsoft.com/en-us/library/cc31bk2e.aspx#run which explains how to open a Visual Studio console window.

The steps to get source code are;

1) Delete the workspace in case it was previously created by the build. Below we delete WorkSpaceATest and make sure not to prompt since this will be automated process:

tf workspace /delete WorkSpaceATest /noprompt

2) Create the workspace. Below we create the workspace WorkSpaceATest and again insure there is no prompt:

tf workspace /new WorkSpaceATest /noprompt

3) Map the collection to a folder and associate the mapping to a workspace. Below we map collection ATest to folder D:\ATest and associate this mapping with WorkSpaceATest:

tf workfold /map $/ATest D:\ATest /WorkSpace:WorkSpaceATest

4) Get the source code by specifying the label;
tf get /version:LATest01

The /version command-line option is used to specify a version number. By prefixing the label name with an L, the /version command-line option can be used to specific a label. The L prefixes the label ATest01.

Using the previous commands to pull the source code for the ATest and BTest collections is as follows:

tf workspace /delete WorkSpaceATest /noprompt
tf workspace /new WorkSpaceATest /noprompt
tf workfold /map $/ATest D:\ATest /WorkSpace:WorkSpaceATest
tf get /version:LATest01

tf workspace /delete WorkSpaceBTest /noprompt
tf workspace /new WorkSpaceBTest /noprompt
tf workfold /map $/BTest D:\BTest /WorkSpace:WorkSpaceBTest
tf get /version:LBTest01

As it turns out the "tf get /version:LBTest01" command deletes all the files for the ATest collection.



The command "tf workspace /new" created a new workspace and associates the current folder (c:\temp) with this workspace.  There is an error in the previous screenshot. The workspace WorkSpaceBTest was not created because the current directory (C:\Temp) was already associated with the workspace WorkSpaceATest. When the second "tf get" is invoked for label BTest01 all the files associated with label ATesst01 are deleted.

The trick here is to create each workspace while the script is running in a separate folder. Workspace WorkspaceATest will be created while the current directory is D:\ATest.
MKDIR D:\ATest
CD /D D:\ATest

Workspace WorkspaceBTest will be created while the current directory is D:\BTest.
MKDIR D:\BTest
CD /D D:\BTest

The resulting script to pull two different labels from TFS is as follows:
MKDIR D:\ATest
CD /D D:\ATest
tf workspace /delete WorkSpaceATest /noprompt
tf workspace /new WorkSpaceATest /noprompt
tf workfold /map $/ATest D:\ATest /WorkSpace:WorkSpaceATest
tf get /version:LATest01

MKDIR D:\BTest
CD /D D:\BTest
tf workspace /delete WorkSpaceBTest /noprompt
tf workspace /new WorkSpaceBTest /noprompt 
tf workfold /map $/BTest D:\BTest /WorkSpace:WorkSpaceBTest
tf get /version:LBTest01

I'd prefer a cleaner solution such as a way via the command-line to suppress "tf workspace /new" from associating the workspace with the current directory.