App development

Building apps? This is the stuff about that

Visual Studio 2012 Update Guide

Submitted by Robert MacLean on Mon, 02/25/2013 - 13:43

Version: 2 – March 4 2013

This page is meant to provide a one stop shop for the updates that are available for Visual Studio 2012. Included here will be only updates from Microsoft. Some maybe betas, CTPs etc. If you think I have missed any please contact me!

VS_Purp256_rgb (1)Visual Studio Update 1

VS_Purp256_rgb (1)Visual Studio Update 2 CTP 4(NEW/UPDATED!)

Git-Icon-1788CGit Tooling for Visual Studio

VS_Purp256_rgb (1)Productivity Power Tools 2012

NuGet_project_logo_svgNuGet

web essentialsWeb Essentials 2012

AzureVS2012_LogoASP.NET and Web Tools 2012.2

AzureVS2012_LogoWindows Azure SDK for .NET (VS 2012) 1.8.1 - February 2013

VS_Purp256_rgb (1)Microsoft Office Developer Tools For Visual Studio (NEW/UPDATED!)

WFM-128pxWorkflow Manager Tools for Visual Studio 2012

expressWindows Phone SDK 8.0

sql-option-aSQL Server Data Tools for VS 2012 December Update

odatalogoWCF Data Services 5.0 for OData v3

Want more extensions for Visual Studio? Check out the 31 extensions created by Microsoft for Visual Studio 2012 on the Visual Studio Gallery

Timeline (out of date)

Since I like to visualise these things here is a timeline of the updates:

image

Download timeline in Excel

Dealing with off by x issues when using the TextBox

Submitted by Robert MacLean on Sun, 01/20/2013 - 14:53

image

Introduction

One of the toughest problems I faced when I built Notepad Classic was an issue where many functions like Go To & Find were always off a few characters. After a bit of experimenting I noticed a pattern, it was off by the number of characters equal to the line number (0 based).

i.e.: no issues on the first line (line index 0); Off by one on the second line (line index 1); Off by two on the third line (line index 2); Off by three on the forth line etc…

Problem

It turned out that the way the string functions count a line break (i.e. \r\n) as two characters, and rightly so – it is two characters a \r & a \n. However the TextBox functions like Select treat \r\n as a single character because that is what is displayed visually – a line break is one character visually. So there is a difference between the two scenarios and thus the “off by one x line count” error I found.

Solution

The solution I used is to compensate for it by working out the number of lines to the point (i.e. count all the line breaks before the point) and adjusting the results (adding +1 for each \r\n) as needed.

Sample application to show this problem and the solution can be found at: https://bitbucket.org/rmaclean/off-by-one-x-sample-code

NDepend + Windows Store apps = WINNING

Submitted by Robert MacLean on Thu, 12/13/2012 - 09:49

I <3 NDepend, it is an amazingly powerful tool that is brutally honest & unforgiving, and the rewards it brings are massive. Building Windows Store apps without it has always worried me – how do I know if this is going right? Thankfully yesterday the NDepend team released 4.1 which includes support for Windows Store apps, which includes the ability to analyse the .winmd files too!

This not only means I have personal benefits, but it is a sign of something too. NDepend really is cutting edge, and so the sign that they professional tools are arriving for Windows Store apps really shows commitment from the community to the platform! This means it will get easier and better to develop Windows Store apps in the future!

You can download a trial of NDepend at http://www.ndepend.com/NDependDownload.aspx

Presenting on Windows 8 - Pro tip

Submitted by Robert MacLean on Fri, 11/30/2012 - 09:41
image

This tip is aimed at presenting, but is just as useful to those who want to focus in Windows 8 without distractions!

Windows 8 is a great operating system to use, especially the background tasks system that ensures other applications are not destroying your CPU & memory. However, there is a downside to background tasks!

Previously, if I wanted to ensure no annoying Skype popups (during my talks for example) I just shutdown Skype and no popups could occur, but in Windows 8, since the application isn’t running, how do we stop the popups?

It is a simple solution, bring up the settings charm (see image on left) and in the bottom right hand corner is an option called Notifications. If you tap that, you will get options to block notifications for 1, 3 or 8 hours.

I am tending towards 3 hours for my 1 hour talks to allow for setup, clean-up etc.

image

Once you have disabled it, the icon will change to show you it is disabled! If you want them back, for example when you are finished, then you can tap the icon again to enable them!

image

What is great is that live tiles & the background tasks still occur, just no popups anymore.

Windows Store app Development Snack: File Type Association Icons

Submitted by Robert MacLean on Thu, 11/29/2012 - 08:58

For more posts in this series, see the series index.

image

One of the declarations you can have with a Windows Store app is the file type association, which lets file types become associated with your application. This means you can customise the icon for the file type & if the user double clicks an associated file, it will launch the application.

One of the properties of declaration is the logo property which is the icon to use for the file type. Logo is optional and if you do not specify it, or you specify it incorrectly, it uses the applications small icon (i.e. the 30x30) one – which doesn’t look great.

image

The solution to this is to correctly specify the logo, but that isn’t as straight forward as it seems. Firstly you don’t just have a single image you need FOUR icons with different resolutions

  • 16x16
  • 32x32
  • 48x48
  • 256x256

Next you need to name them correctly, the format is <name>.targetsize-<resolution>.<extension>, so for example if we wanted to use MyLogo.png as the file name we would have:

  • MyLogo.targetsize-16.png
  • MyLogo.targetsize-32.png
  • MyLogo.targetsize-48.png
  • MyLogo.targetsize-256.png

Lastly is putting in the correct logo name in the manifest, since you have four icons what do you use? You use the name + extension components. Using the example about we would have MyLogo.png as the name & Windows 8 is smart enough to figure out the resolution, insert the target bit and get the right image for the right resolution!

Windows Store app Development Snack: Background Colour

Submitted by Robert MacLean on Wed, 11/28/2012 - 11:47

For more posts in this series, see the series index.

When you are configuring the appxmanifest for your Windows Store app, one of the options is the background colour for the tile – YOU SHOULD ALWAYS SET THIS!

image

It is used for two things, firstly if your image is transparent this is the colour that will show through for example for Notepad Classic that is what I do – the actual image is just plain white & transparent.

image

The second one, which is not always the most obvious is when a small icon is needed, for example you do a pinch gesture on the start screen (semantic zoom is the technical term for it), the background colour is what is used as a border around the image. Below you can see a screen shot from my machine, and note two of them have this ugly black border – that is because they do not have a matching background colour set!

image

It is not always possible, especially for games with rich tile icons (note Angry Birds in the screen shot below) but I would suggest trying to find a similar colour anyway for example the top two below have a similar colour & Jetpack Joyride (the last one) chose white (which is at least better than ugly grey).

image

Another location for the small icon is the search charm

image

English to Afrikaans to English

Submitted by Robert MacLean on Thu, 11/15/2012 - 08:12

image

South Africa, the amazing country I live in, has 11 official languages including the language of Afrikaans which I can muddle my way through speaking. However often I struggle and that inspired me to create an app to help with a phrase book that helps you translate English to Afrikaans & back again!

I see some real value in this on a tablet, when people come to South Africa on holiday as they will be able to quickly find out what “jou ma se…” means and take the required action (ducking is generally the required action at that point).

While I did some planning for this app before hand (finding content, prototyping UI’s etc…) the app was mostly built at the recent WowzApp event, which is an event aimed at students (although we had professionals & even a 13 year old).

This app is also in the Apptivate competition so please go there and vote for it by clicking the image below:

apptivate

Video

Screen shots

screenshot_11112012_221229screenshot_11112012_221241screenshot_11112012_221250screenshot_11112012_221321screenshot_11112012_221636

Windows Store app Development Snack: The vastness of CPU time

Submitted by Robert MacLean on Thu, 11/08/2012 - 19:20

For more posts in this series, see the series index.

I have written in a previous post (What do you get from being a lock screen app?) about how your background processing has a limited amount of time to do it’s processing in, what the odd unit of measurement used (the CPU second) and the overflow bucket. Even with the thinking it is hard to understand what you can accomplish in the time available, so help let’s look at what an app I built (Bing my lockscreen) does in it’s time.

In short what I hope you take away from this, is that you do get a decent amount of time and that with careful planning you can do a lot!

The Process

First off, Bing my lockscreen since it uses a timer requires lock screen permissions which means it gets at least 2 CPU seconds every fifteen minutes, plus overflow from the bucket.

First thing that happens is we get a deferral object (similar to what was explained in Async & Sharing) since we need to use async in the background task. Now we go to the RoamingSettings values to get a boolean (which needs to be cast, since RoamingSettings is a Dictionary of string & object) to see if the user has disabled automatic updates. Now assuming the user hasn’t disabled automatic updates, we connect to a web site using the HttpClient & HttpClientHandler classes and pull down some JSON as a string and convert it to an object using Windows.Data.Json.JsonObject.

Aside: if I felt too tight on CPU, I may swop to the AWESOME Json.NET, which has a better parsing performance.

If all that worked (and there is minimal logging and status checks happening in here too), I use a touch of Linq to get the first image from the IEnumerable collection that it is stored in internally. I then check the URL of the image against a value stored in LocalSettings, as I do not wish to update the lock screen with the same image multiple times. If the image is different, I download the image from Bing to the TemporaryFolder, check the file size is greater than 0. If it is, then I call the SetImageFileAsync method to change the lock screen, else I delete the damage file. Downloading is far more complex than it first appears as I need to handle proxies, handle scenarios where I can’t get the 1920x1200 resolution and need to fall back to the 1366x766 resolution image, ensure everything is written to disk BEFORE the lockscreen is set (I had some issues with I/O buffers in earlier versions that caused a minor corruption on images because they were not flushed to disk!).

Aside: Important to remember that CPU seconds, is time the CPU works – when the CPU is idle say because you are doing something I/O bound like a download, it doesn’t count!

Next I store the result of this to the log, which is just a container in LocalSettings (so that means the first time this is run we create the container too!) and store the URL of the newly changed image too. Now the process continues in a similar way for the live tile! We check if the last live tile update is the same based on the URL for the image (again comparing to a value stored in LocalSettings). I then use the TileNotification and the TileUpdateManager to send the tile update. I do not need to download the tile image in this case, as tiles do support remote URL’s for the images. Lastly I update the LocalSettings for the updated tile!

Line count

If you count the lines of code executed for this, and I am excluding blank lines, namespace declarations, comments – really just the code that actually runs it is approx. 190 lines of C# code! Far more than you may think.

More stats!

I used the always amazing NDepend to generate some more stats on the assembly which does all the background processing:

  • IL instructions: 2 092
  • lines of code (LOC): 80
  • lines of comment: 9
  • Percentage Comment: 10%
  • Methods: 99
  • Fields: 75
  • Types: 18
  • Namespaces: 2
  • Assembly Level: 1
  • Abstractness: 0.11111
  • Instability: 1
  • Dist from main seq: 0.078567
  • Normalized dist from main seq: 0.11111
  • Relational cohesion: 2.3333
  • Afferent coupling (AsmCa): 0
  • Efferent coupling (AsmCe): 17

LOC is different here since NDepend uses the compiled assembly and works back, while I counted lines in Visual Studio. Same is true for methods, which NDepend works out from the compiled assembly and thus includes all anonymous methods - where if I counted that in VS, it would be 8 or 9 methods.

Image Grabber

Submitted by Robert MacLean on Fri, 10/26/2012 - 16:02

svg2raster - pink-190x190This is really a simple app, find images on a website and pull them down to your machine so you can browse them, save them or share them. There is some special logic for some websites – such as Tumblr blogs where it will pull down using the API rather than raw scraping of the pages.

This was the very first app I built and tried to publish – it took numerous attempts to get through certification and in the process I learnt a lot.

You can get the app from the store using the download link below!

Download

This app is also in the Apptivate competition so please go there and vote for it by clicking the image below:

apptivate

Video

Screen shots

Windows Store app Development Snack: Side loading apps for development purposes!

Submitted by Robert MacLean on Mon, 10/22/2012 - 09:52

For more posts in this series, see the series index.

One of the things you need to think of when you are going through your development cycle is how the decision makers are going to test your app? 

Likely the best solution is to get it to their hands via a device, but how do you load your application onto that other device? Well there are TWO options!

Building the app

Before you do that however you need open your project in Visual Studio, right click on the project and go to the Store option, then client the Create App Packages option.

image

Since you are creating them for side loading you do not need to associate them with the store.

image

Once done you will have a folder (called the output location) with both a .appxupload & another folder in it – we will call this the deployment folder.

image

PowerShell

imageRegardless of the machine, if it has Windows 8 on it – it has PowerShell too so this option works FANTASTICALLY for everyone.  Step one is to load a developer license onto the machine, you can do this by typing: Show-WindowsDeveloperLicenseRegistration

You will now get the prompt for your Live ID to register the device unlocked for three months.

Next you need to ensure you can run PowerShell scripts, this is done using: Set-ExecutionPolicy unrestricted

Now copy the deployment folder to the device and using PowerShell run the Add-AppDevPackage.ps1 – This will prompt you about installing it and installing the required certificates. Say yes to those and the app will install on the device!

Visual Studio Debuggable Package Manager

If the device has has Visual Studio on it there is another option you can use which just requires the .appx package. That is the Debuggable Package Manager

image

When you launch that you can use the Add-AppxPackage command to install any appx you have. You can find the .appx file in the deployment folder.

AppXUpload

if you only have an .appxupload file – you can still use that too! Just remain it to a zip file, open it up in your favourite compression tool and extract the appx file from there!