Winners of Windows Phone competition announced, more NZ Windows Phone apps

, posted: 13-Feb-2012 10:49

Microsoft has announced the winners four Samsung Focus Flash Phones in New Zealand.

Shane S Anderson – Auckland Bus Stops 
Donald Dingwall – Tap That 
Brian Donovan-Smith – Ye Be Lame 
Craig Moodie – Hip Hop Blog

And here is a list of all new New Zealand-developed apps submited to this competition:

App TitleDeep Link
Auckland Bus Stops
BAPS Satsang App
Beer Rater
Big Bang Fan Quiz
Bus Card Balance Auckland
CCNet Monitor
D&B Blogs
Dice Roller
Discover Boston
Doodle Draw
DubStep Blogs
Follow Curiosity
Game of Life
HipHop Blog
Indoor Rowing Calc
Learn NZSL
Life Hacks
Light Weight Free
Log Book
Magic 8 Ball
Mood Finger Scanner
Mugglenet News
My Deal USA
My Powershop
Nigh and Day
Number Guess
NZ Post
NZ rain Radar
NZ Soundboard
Office Calculator
Palmerston North City & Manawatu
Paris Movie Walks
Rainbow Calculator
Roadside Stories
Rock Blogs
Rock Paper Sissors
Simple Buzzer
Simple Calculator
Simple Strobelight
SlingShot Internet Usage
SuperMarket Finder NZ
Tap That
Team Connect
Team MCG RSS Feed
Vodafone NZ SMS Service
Walk Auckland
Word Rush
Ye Be Lame
Zombie Madness

Customise your Visual Studio 2010 colour scheme

, posted: 24-Jan-2012 10:12

While the default blue on white base colour scheme in Visual Studio 2010 is fine for most, some people (like myself and several of my colleagues) prefer working against a darker background or with different sets of font styles and colours – in my case this is mostly to help with eye strain, staring into a bright white monitor for hours on end can be somewhat harsh on the ol’ eye-balls at times.  

Luckily its quite simple to customise your environment in Visual Studio 2010, right down the the minute of details. Simply open up the preferences through the menu: ‘Tools –> Options –> Environment Fonts and Colors’.

It’s a good idea to back up your settings first (‘Import and Export Settings’) before playing around. This will ensure you can always revert back to your original settings at any point without fear.  

A fantastic little developer community has popped up recently over at where you can browse and download hundreds of pre-rolled themes that other people have already built and tested for longevity.

The top-rated schemes are a great place to start if you’re keen to try something new without spending a lot of time on tweaking everything just so.   

Download a trial of Visual Studio.

About the author

Phil Gale is a Software Architect and Graphic Designer with over a decade of hands on experience in the web and software industry. He is a director at Red Jungle where they make fantastic software with exceptional user experiences. You can catch him twitter at @redjungle and on Geekzone as well.

Secure Development Tips and Techniques for use in websites and web applications

, posted: 16-Jan-2012 16:42

When developing any type of website or web application in .Net there are plenty of tips to help make sure your creation is protected against hackers and scanners.

I have compiled a check list of tips and techniques that I have built up in the years of development in .Net – So I’m here to share them with you all – so that you can also develop more securely in your own projects.

1. Configuration – SSL and services
Once your website is live to the public, it’s a good idea if you have control of the server to uninstall or disable services that aren’t required. Anything other than HTTP/HTTPS left open to the public is a risk. Try to enforce SSL for parts of your website that you wish to encrypt the data for. The SSL connection will ensure the data between the webserver and the client browser is encrypted end to end. Normal situations for this include payment processing etc.

2. Deployment – Release Build  
Once you have done your testing – make sure you only deploy a “release” build of your website. It will remove all the debug code that is automatically injected when you are normally testing the website. It means if anything does happen/crash, there will be less information displayed to the user on-screen.

3. Deployment – Exception Handling  
Inside the Global.asax file that is generated with all website projects in .Net, put code in the Application_Error function to capture any exception that may occur that isn’t handled properly in the website code. There are always scenarios that we can’t/don’t test, and slip through the gaps. Get the code to log the issues internally, and display a User-Friendly error page to the user. Do not reveal any error specific information in the Error Page.

4. Database – Queries  
When accessing data to and from the database, make sure you use Stored Procedures instead of generating SQL queries dynamically. Because the query is outside the code base – there is no potential for the query to be altered/re-written. It does happen in attacks through a series of different attacks like Cross-Site scripting (XSS) and SQL Injection. If there is potential for the query to change, you have to assume that it might happen.

5. Database – Sanitization  
When storing any strings/data in the database – you should sanitize your data by using the built in Server.HTMLEncode/Server.HTMLDecode functions to store the data safely. It will remove any script injections from being readable.

6. Field Input – Sanitization  
All fields on a screen can be changed, even if they are labels or disabled textboxes through scripts/man-in-the-middle attacks (MITM). All data inputted must be validated correctly for format, and for XSS/Sql Injection input. Microsoft provides a library that can help deal with this – called Microsoft Anti-XSS ( Funnily enough it’s been around since 2005/2006 and still hasn’t been incorporated into Visual Studio yet.

7. Password requirements  
Ensuring users make it more difficult for anyone to guess their password; you need to enforce decent rules for a valid password. There needs to be a mix of upper/lowercase, symbols and numbers with at least 1 or 2 of each and a minimum length of 8-16 characters. The longer the harder it is to guess.

8. Login functionality  
They should never reveal what exactly is wrong with the credentials – leave room for ambiguity. “Wrong Login or Password” is more secure than “Wrong Password for this Login”. Similar principle applies to Forgotten Password pages – never inform the user that the email/user specified was found – but more like “If the user/email exists, then a password will be sent to the user.”

9. Brute Force attempts  
A method to prevent this from happening/affecting your website – Every failed attempt to login is counted by IP Address, once this hits a set limit (I used 3 attempts), does a lockout for the attack for 5 minutes. Each attempt returns the same error message “Invalid Login or Password” – even once the lockout has occurred. The user has no idea that the system isn’t even checking the login or password anymore since you have missed it too many times. Every sequential attempt during the lockout period restarts the lockout delay.  This method prevents tools that are attempting brute-force attempts, as they keep trying different combinations and read the output on the page to understand it has a wrong Login/password combination. All attempts should be logged with Login attempted, date attempted and IP Address it came from. You can easily see when someone has attempted to brute-force your login system without gaining entry.

Take all those in account when creating new or building on existing websites/web applications – and you’ll be helping provide a more secure and safe website.

Download a trial of Visual Studio 2010.

About the author

Stephen Aitchison is senior developer at Aura Redeye Security Ltd. You can find him on Twitter as @NZCoderGuy and on Geekzone as well.

NuGet Package Manager extension for Visual Studio 2010

, posted: 21-Dec-2011 10:48

One of the most exciting add-on extensions that have appeared for Visual Studio 2010 has to be Nuget.

Without a doubt it has profoundly changed the way we work with external libraries and dependencies in our projects here at Red Jungle.

To quote the Nuget codeplex site:

NuGet is a free, open source developer focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development.


There are a large number of useful 3rd party open source libraries out there for the .NET platform, but for those not familiar with the OSS ecosystem, it can be a pain to pull these libraries into a project.


NuGet automates all these common and tedious tasks for a package as well as its dependencies. It removes nearly all of the challenges of incorporating a third party open source library into a project’s source tree.

In effect, what Nuget does is to allow a developer to (either via command line console, or through a GUI – as shown below) find and add packages [such as libraries, tools, etc.] to projects, in a profoundly seamless and simple way. In other words, a feature which was long overdue!

When a package is added, Nuget will download the package, extract it, copy the files to their correct locations within your project structure and automatically make whatever changes are needed to your project, such as adding references and even modifying your .config files appropriately.

Nuget will even keep track of when a new version of each package is available, and allow you to upgrade with a single command. Le

Let’s take ELMAH as an example. It’s a fine error logging utility which has no dependencies on other libraries, but is still a challenge to integrate into a project. These are the steps it takes without NuGet:

1. Find ELMAH
2. Download the correct zip package.
3. “Unblock” the package.
4. Verify its hash against the one provided by the hosting environment.
5. Unzip the package contents into a specific location in the solution.
6. Add an assembly reference to the assembly.
7. Update web.config with the correct settings which a developer needs to search for.

And this is for a library that has no dependencies. Imagine doing this for NHibernate.Linq which has multiple dependencies each needing similar steps. We can do much better!

Since its initial beta release back in October 2010 (originally named NuPack) the Nuget project has been in continuous development and has rapidly improved at each stage; it has now become part of our ‘must have’ tooling support.

For insight into the Nuget project and its development it’s worthwhile reading through Phil Haack’s previous blog posts.

Download a trial of Visual Studio.

About the author

Phil Gale is a Software Architect and Graphic Designer with over a decade of hands on experience in the web and software industry. He is a director at Red Jungle where they make fantastic software with exceptional user experiences. You can catch him twitter at @redjungle and on Geekzone as well.

Competition: be in to win one of four Samsung Focus Flash Windows Phone by developing a Windows Phone app

, posted: 19-Dec-2011 20:00

NOTE: Your app doesn’t have to be published on the Marketplace by January 31st, but it should have been submitted. If you still don’t have a Marketplace account, email us a screenshot of your app to get a free one-year Marketplace token.

So you want to be a Phone Developer? Be in to win one of four Samsung Focus Flash Phones for developing a Windows Phone application. The first 50 entries also get a free Market Place account.

I happen to have one of the best jobs within Microsoft - managing the Windows Phone Developer Ecosystem in New Zealand. I work within the Developer Platform Evangelism team, alongside Thiago Almeida (Cloud Evangelist), Nathan Mercer (IT Pro Evangelist) and Nigel Parker (Windows 8 Evangelist).

As part of my role, I manage Microsoft New Zealand's Windows Phone training events and workshops, and work with developers to help them get their hands on Windows Phone devices for testing apps nearing completion.  We have some exciting opportunities to ramp up developers on to our Windows Phone Ecosystem so keep reading.

Over the last 12 months we have seen the launch of the highly anticipated Windows Phone in New Zealand, launching with the LG Optimus and HTC Trophy on Telecom and Vodafone, respectively. Since the launch in NZ, developers in New Zealand have released over 250 apps to the Marketplace. Globally, over 40,000 apps have been released, with over 120,000 downloads/day. Three successful New Zealand apps have taken the world by storm, Alphajax, Metrotube, and RWC2011 have had hundreds of thousands of downloads.

The market has already begun to shift, and Windows Phone is quickly becoming a major player.  We will be working heavily with our developer community to take advantage of this trend. There are also now several ways to market your application to your specified audience: public domain, targeted domain i.e. enterprise applications, and testing domain. These three options now give you all the flexibility you need to customise your applications, including the opportunity to test your application before submitting to the public market place.

There is no reason to put it off any longer! For those new to the platform - Windows Phone development is completed using familiar tools, Visual Studio 2010 and Expression Blend, both available as free versions to develop for the phone. Use Silverlight and XNA to build rich, immersive experiences in the languages you know, C#, VB.Net. And with exposure to over 35 markets there is a huge opportunity to be the next Angry Birds.

If you're stuck and looking for resources, just do a quick search and you will find a plethora of training material - but to get you started, check out:

.    Jump Start Training Sessions
.    Mini Training Videos
.    MSDN Resources
.    Absolute Beginner videos
.    App Hub Registration Walkthrough
.    App Hub FAQ

There are several interesting sites to keep you up-to-date with the latest on the Windows Phone Ecosystem - including WP Central, Windows Phone NZ, Windows Phone Developer blog, and our MSDN Facebook page. There is also the Auckland Metro Meetup and Linkedin Windows Phone group.

If you need a device to test your application, email us and let us know - we can help. One of best things about the submission process on the Marketplace is that you get a full report on why your app didn't pass certification, so that you can go back to rectify the errors, and feel confident that your application will give your users the best experience possible.

Finally, as part of our ongoing effort working with local developers to build some great local phone apps, we will be running free seminars and workshops throughout the country, and will be working with the local MS Communities group across the next six months.

Now it's time to step up and show us what you can do! We have four Samsung Focus Flash phones to give away at the end of January.  How can you win - simply build an application and get it published on the Windows Phone Market Place by 30th Jan to be in to win. The more applications you publish, the more chances you have to win. Every app goes in a random draw to win one of four Samsung Focus Flash handsets.

But wait, there's more! The first 50 developers to email us a screenshot of their first application will get a Market Place account for free - that's waiving the $150 annual registration fee. So get started today!

Step 1: Build your app.
Step 2: To get a free marketplace account email us a screenshot of the finished app.
Step 3: To go int the draw, email us a link to your app on the marketplace, and a brief app description.   

Happy coding!

About the author

Ryan Tarak (Technology Evangelist, Microsoft New Zealand, blog, Twitter) is passionate about academic audiences, Windows Phone, and the NZ developer community. Supporting the .NET User Groups and engaging with academics as well as tertiary students, Ryan focuses on helping institutions introduce Microsoft technologies, and helping students to connect with the industry through programs such as the Microsoft Imagine Cup. A graduate from both the University of Auckland and the University of Otago, Ryan no longer has any free time - thanks to his beautiful baby girl, Kayla.



Windows Phone Competition. Please read below specific Terms and Conditions:
  1. To be eligible you must be a New Zealand Resident using a New Zealand Market Place Account.
  2. To be eligible for the competition, you must have a new published Windows Phone application anytime between the 1st of January 2012 to 31st January 2012. If your application is in the process of being approved by 31st of January 2012, we will still accept your entry provided you email Your app will then get a 7 day grace period to be published for you entry to be eligible.
  3. Entries must be emailed to with a link to the application on the Market Place and a short two/three line sentence describing the application
  4. Microsoft is not responsible for entries not received and incomplete, illegible, 'hacked' or otherwise fraudulent entries are not valid.
  5. By entering this prize draw you agree to be bound by these terms & conditions.
  6. Each published entry will go in to the draw to win one for four Samsung Focus Flash Phone Handsets
  7. Winners will be notified on 5th of February 2012 via the email or contact phone number provided.
  8. Prizes will be delivered to each winner at a New Zealand address (as advised by the winner) at Microsoft's expense.
  9. Only people living in New Zealand are eligible to win. Employees and independent contractors (and each of their immediate family members) of Microsoft are not eligible to enter.
  10. Prizes are not transferable or redeemable for cash. If you are unable or unwilling to accept your prize, Microsoft may award it to an alternate winner.
  11. If you accept a prize you will be solely responsible for all applicable taxes related to accepting the prize.
  12. If for any reason an advertised prize is unavailable, Microsoft may substitute the advertised prized for another prize which has approximately the same recommended retail price.
  13. If there is a dispute as to who submitted the winning entry, the winner will be the authorized account holder of the market place account used to publish the Windows Phone Application. Applications submitted in to the draw must be by the actual owner of the Market Place Account.
  14. Microsoft New Zealand Limited is the promoter of this prize draw and may modify these terms & conditions without notice. The judge's decision in relation to the winners or any other aspect of this prize draw is final and no correspondence will be entered into.
  15. Microsoft may disqualify, from participating in this prize draw, any person who tampers with the entry process, or submits an entry not in accordance with these terms and conditions.
  16. Microsoft is committed to complying with the Government gift and ethics policies. Employees and independent contracts of the Government must adhere to gift and ethics policies applicable to them when entering this prize draw or accepting any prize.
  17. Microsoft is not responsible for any problems or technical malfunction of any telephone network or lines, servers or providers, or any combination thereof. Nor is it responsible for any incorrect or inaccurate information caused by any of the equipment or programming associated with or utilized in this prize draw, or by any technical or human error that may occur in the course of the administration of this prize draw.
  18. To the extent permitted by law, Microsoft, its retailers, suppliers, associated companies and agencies will not be liable to you for any direct, indirect or consequential loss or damage whatsoever, including personal injury, which is suffered as a result of, or arising from, your participation in the prize draw or winning (or not winning) any prize.
  19. At Microsoft, we are committed to protecting your privacy. Microsoft will collect and use your details for the purposes of running this prize draw. You can access or request correction of your details by emailing

Consuming JSON web APIs with Visual Studio

, posted: 16-Dec-2011 09:59

Most web APIs (including the recently introduced Geekzone API) will happily return a JSON result. Using a little serializing and de-serializing magic from JSON.NET it's now a trivial task to consume such services in a nice object oriented way. In this blog post I will show how to do it with Visual Studio.

Take for example the ForumsList method of the Geekzone API, which will (oddly enough) return the list of available forums, and their associated details such as a description, topic and post counts, etc.

Lets mock up how we would consume this service call. First, we'll create a local class structure in our project - into which we are able to map the results we expect back from our API call. In this case we'll create a 'Forum' class. We will be serializing our JSON results into this class, giving us a nice, friendly, strongly typed interface to work against (we like those).

Next we'll add a reference to the JSON.NET project (in this case I'm using Nuget to do so).

Then, using the WebClient class of the .NET Framework, we initiate an asynchronous HTTP GET request to the API URL, which will result in a JSON response string being returned.

On first glace the returned JSON string resembles a jumble of text, but it's actually a structured way of representing hierarchical data (similar to XML). Read a little more background on JSON (Javascript object notation) over at if you wish.

In this case, what we have returned is a JSON string representing a collection of forum results. You'll also see within the structure that there are fields which match up perfectly with our 'Forum' class we created earlier (what a co-incidence). This convention means we'll easily be able to auto-magically map these strings into our strongly typed class structure.

Now using the JSON.NET converter class to serialize our string of textual information into a class structure we are left with a 1 to 1 mapped object which retains all hierarchy and structure ready to be used.

So there we go, a couple of small method calls and a little help from our friend JSON.NET and we're consuming a REST API and mapping results to nice friendly objects.

PS. Lookout for additions to the Geekzone API coming soon (including better documentation!).

Download a trial of Visual Studio.

About the author

Phil Gale is a Software Architect and Graphic Designer with over a decade of hands on experience in the web and software industry. He is a director at Red Jungle where they make fantastic software with exceptional user experiences. You can catch him twitter at @redjungle and on Geekzone as well.

Recommended documentation add-on for Visual Studio 2010: GhostDoc

, posted: 12-Dec-2011 16:00

During my six years of commercial development experience I have stumbled upon different kinds of add-ons that developers can use to integrate into the Visual Studio environment and get extra functionality that was missing.

Generally these tools make it for a better experience for the developer, saving both time and effort in long projects. GhostDoc is one I've been using especially in Visual Studio 2010 to help with documentation, so I decided to write a brief blog post on how it works and what it does.

GhostDoc comes in two different versions (free or paid) and works with both C# and VB.Net.

I've been using the free version, which accomplishes exactly what I need it to do. Once it is installed browse to your class/code that you have created:

Right click on the section you wish to create comments on, which could be the Class, Variable or Sub/Function declaration - and Click "Document This!":

GhostDoc will auto generate comments on each section, and on Sub/Functions will try to guess what the function is used for, along with what Parameters are expected.

It is a basic add-on, but I have found that even the simple add-ons add extra value.

Documentation is a normal practice used in the Industry, so this add-in will definitely help you with this. It integrates perfectly in the Visual Studio IDE.

Download a trial of Visual Studio 2010.

About the author

Stephen Aitchison is senior developer at Aura Redeye Security Ltd. You can find him on Twitter as @NZCoderGuy and on Geekzone as well.

Test driven development in Visual Studio 2010

, posted: 1-Dec-2011 14:33

For every development project it is definitely a great idea to incorporate some sort of testing, either automated or by user. In this blog post I will be covering some of the basics with automated testing using Visual Studio 2010, more specifically Unit Testing.

Within the IDE you will need to create a Test Project, which you be able to easily find under your chosen language -> project types.

This will create another project in your solution that will be just for your Unit Tests. In this solution, right click and select Add Item -> New Test, which will open the next dialog:

From in this New Test dialog, select Unit Test Wizard to bring up the wizard screen for selecting the classes you wish to automatically generate Test Classes for:

When selecting the class you wish to generate a test for, you can select what methods/properties of the class you want to test if you want to go down to that level. For my testing, I select the Class level, to test all the methods/properties included in the class. Once you have selected your classes Visual Studio will create individual classes for each Class you are testing. In this example I have selected the Password Library class:

There are two test functions here. Visual Studio only generated one function for testing IsNumber(), but I made a duplicate copy to test two different values (one being a number, the other being a letter).

To understand what it's doing inside the test function, you start by defining what you expect as the result, and then what conditions to set then calling them. Once you have done that, you compare what you got with what you expected - by using the Assert object (part of the Visual Studio Test Units framework) along with a specific function you need - in this case I am using AreEqual() - which will return a Pass if both results are the same (Actual vs Expected), else will result in a Fail if they aren't.

Once you have setup your tests you need to right-click on your Test Project, and select as a Start-up Project. Then Build/Run your solution - you will then get this nice window at the bottom of your Visual Studio instance:

So here we can see there were six auto-generated tests by the Test Wizard, with the addition of the IsNumberTest test function that we duplicated (so seven in total). We can easily see that five of the seven have passed successfully.

So that is the basics of creating, modifying and running Unit Tests as part of the Visual Studio Test Units framework. It is all built into Visual Studio, so there is no additional add-ins or downloads to have this nice functionality.

The last bit of advice I can post - run these tests as often as you modify classes. If you do modify your classes often, then it is best to re-run or modify then re-run these to have a sanity check on your code to make-sure it all runs as expected.

Download a trial of Visual Studio 2010.

About the author

Stephen Aitchison is senior developer at Aura Redeye Security Ltd. You can find him on Twitter as @NZCoderGuy and on Geekzone as well.

Web.config transforms

, posted: 29-Nov-2011 12:21

Most web applications (and probably all ASP.NET applications) will, as they go through the various stages of the development and deployment process, be required to run in a number of different environments with different characteristics.  A development shop will typically have separate development and user acceptance testing environments at the very least, and then of course there's the production environment.

Each of these environments will typically (at least hopefully) have its own version of the database (usually on a different server, especially for production), and other settings that logically need to vary from one environment to another (the most obvious being for instance whether or not "debug" is enabled). There may additionally be different mail settings, different web service endpoint settings and so on.

Managing these differences has been tedious and error-prone to do manually, and not exactly a piece of cake with automated systems either (I remember having to include post-build steps to copy and rename configuration files, for instance).

Fortunately, Visual Studio 2010 includes a feature which improves this situation considerably.

If you create a new project using one of the Web templates (such as ASP.NET Web Application or ASP.NET MVC 3 Application for example, but not Web Site) and glance at the Solution Explorer you'll notice an arrow next to the Web.config, indicating the presence of dependent files. If you expand this arrow you'll see the following:

If you now open Web.Release.config, you'll see something like this:

Note the unfamiliar xdt:Transform attribute on the element - this has the value "RemoveAttributes(debug)", and it does exactly what it says: it is an instruction to remove the debug attribute from the compilation element. Since we do not typically want out production code to run as debug, this makes sense for the release version of a config file.

By default, any values in the original Web.config file not explicitly removed, overridden or modified will carry through to the final output, so the only things you need to specify explicitly in the transformation files are those you want to add, remove or change.

If you look at the commented-out examples in the Web.Release.config file (and I suggest you do as a good place to start), you'll notice that the first example shows a section containing an entry for a "MyDB" connection string, and in addition to the xdt:Transform attribute we have already seen there is an xdt:Locator attribute, with the value "Match(name)", which as you can probably guess instructs that in selecting the element to modify, it should be matched according to the name attribute of the element.

A connectionStrings section may contain multiple connection strings, so to identify which one you want to apply a particular transformation to you use a Locator attribute (the same applies in other cases where there is potential ambiguity - note that you didn't need one on the element because there is only one.

The Web.config transform is applied when the application is published - one obvious way to try this out is to select "Build->Publish " from the Visual Studio menu, and then use the publish method of your choice - I find that publishing to the local file system is a good way to verify results quickly.

The Web.config transformation applied is the one corresponding to the currently selected build configuration - so for instance to apply the transformations specified in Web.Release.config you would publish with the build configuration set to Release. If you add additional build configurations (which if you use automated builds you probably will) you can generate additional configuration transform files, which will be named to reflect the new or additional build configurations.

If for instance you use the Configuration Manager to create a new build configuration named "Test", you will find that when you right-click Web.config the Add Config Transforms context menu entry is now enabled. If you click this option it will generate a Web.Test.config file (as well as config transform files for any other build configurations you may have created).

Note that if for example you chose to base your hypothetical Test build configuration on Release (which is what I generally do) it will generate a Web.Test.config file that is a duplicate of the default (unmodified)  Web.Release.config file.

If we go back to our Web.Release.config file, remove the comments around the connectionStrings section and publish with build configuration set to Release, you may possibly be surprised by the result. The output Web.config file includes an ApplicationServices connection string because it is included in the project's Web.config file, but it does not include the MyDB entry that we added in Web.Release.config - this is because the xdt:Locator attribute is set to "Match(name)", and there is no existing connection string with a name attribute of "MyDB", so the match fails.

We can fix this by adding a "MyDB" connection string in the project's Web.config and leaving its connectionString attribute as an empty string. This is a good approach when an element such as a connection string is present in all build configurations but we want to give it different values in each (or for given subsets). If on the other hand you wanted to add a completely new connection string in one configuration (unlikely in the case of connection strings, but there are other elements where it would make sense) you would omit the xdt:Locator attribute and give xdt:Transform the value "Insert".

So what else can you do with xdt:Transform?

Possible values are as follows: Replace (replaces the matching element, or the first of a series if there is more than one match), Insert (inserts a new element at the end of the selected collection), InsertBefore (followed in brackets by an absolute XPath expression used to identify the element before which it is inserted), InsertAfter (similar to InsertBefore except for the position at which it inserts), Remove (removes the selected element or the first of a matching),  RemoveAll (removes the selected element or elements), RemoveAttributes (removes the specified attribute or a comma-delimited list of attributes - this is the transform that is enabled by default for the element's debug attribute in Web.Release.config) and SetAttributes (allows you to change selected attributes to the values they have on element containing the SetAttributes attribute, without replacing the elements containing those attributes).

More on xdt:Locator

The examples of matching I've shown have been simple matches on the value of an attribute, but the Locator syntax is actually much more flexible than that. "Match" can take not just a single attribute but a comma-delimited list, and for more complex matches you can instead use "Condition" or "XPath": both take an XPath expression as their argument, but whereas with "Condition" the expression evaluates a path relative to the selected element, with "XPath" it is absolute and applies to the entire configuration.

MSDN documentation covering Transform and Locator syntax (with examples) can be found here.

Publishing with Automated Builds

While it's all very well being able to publish a web application from your PC and have transforms applied as part of that process, in the real world (at least the nice part of the real world, where we all wish we lived) the finished web application will be built from source control by an automated build process and then deployed, perhaps as the final step in that process.

Microsoft are very fond of people using deployment packages to deploy web applications,  and their online documentation covers using web config transforms with deployment packages in some detail (this is a good place to start). If that's what you're using you should be fine (if there are any issues with the build automation, it's worth checking out this thread on

However, if your build process simply builds the web application for XCopy deployment (which I'm certain is a very common scenario) you may be wondering how to cause the transformation to be applied, since in this case the build is not performing a "Publish" as such. Fortunately, you can handle this situation fairly easily by adding an AfterBuild step to your project file that executes TransformXml and then following the transform cleans up by deleting all every file from the output that matches the pattern "Web.*.config" (therefore leaving your output Web.config file and deleting the transform files, which you are unlikely to want to deploy to the web site). I encountered this issue myself and resolved it as described a little over a year ago, so you can find the solution described in some detail on my blog.

Download a trial of Visual Studio 2010.

About the author

Kevin Daly has been writing code professionally since 1986 and for kicks since about 1981. He has been using .NET and C# continuously since .NET 1.0 was still in beta (2001 For Those Who Came In Late). His programming interests span desktop, web and mobile development, but he is particularly interested in the XAML-based (or at least XAML-aware) technologies such as WPF, Silverlight and WinRT. He is also interested in creating legions of killer robots (although that one's been slow getting off the ground). Other examples of his views, rants and even the odd code sample can be found on his blog at He will now stop talking about himself in the third person because it's frankly a bit weird.

Getting Started with Visual Studio LightSwitch 2011

, posted: 17-Nov-2011 15:45

Microsoft Visual Studio LightSwitch 2011 is the newest edition of the Visual Studio Family. It's a simplified, self-service development tool that enables you to build business applications quickly and easily for the desktop and cloud, regardless of your development skills.

It also has Starter Kits (downloadable project templates you can customize to suit your needs) to enable the quick creation of common business apps for tasks like time tracking, customer service, and performance reviews. You can easily add more complexity as needed with the LightSwitch Extensions provided, such as components, data sources (including SharePoint 2010, SQL Server, SQL Azure, and other third party databases), and services for your app.

From a technical perspective it creates the necessary core plumbing for your business applications on top of well-known technologies like Silverlight, MVVM, RIA Services, and Entity Framework, and best practices in user experience, security and n-tiered applications.

The starting place to visit first for development content is the LightSwitch Development Center on MSDN. As you can see from the page, there are four steps to get you started:

 Download Visual Studio LightSwitch 2011

 Watch the instructional LightSwitch "How Do I?" videos

 Get essential training

 Ask questions in the LightSwitch forums

Here are a few more interesting links:

. Deploying LightSwitch Applications to Windows Azure article on the MSDN Magazine November 2011 edition
. The official LightSwitch Team Blog
. The "LightSwitch Star" Contest on CodeProject

Thiago Almeida
Technology Evangelist
Microsoft New Zealand
Blog | Twitter

About the Visual Studio blog

In the years since the hugely successful release of Visual Studio 2005, Microsoft has used developer feedback from all over the world to introduce new features in later releases.

This sponsored blog will bring Visual Studio tips and tricks from well known developers in the New Zealand tech community directly to you.

Every second day during November and December 2011 you will find something new here. Make sure you bookmark this blog or subscribe to its RSS feed.    

Join us on Twitter

Find us on Facebook


User Interface...
Windows Phone...

Other blog posts

Winners of Windows Phone compe...
Customise your Visual Studio 2...
Secure Development Tips and Te...
NuGet Package Manager extensio...
Competition: be in to win one ...
Consuming JSON web APIs with V...
Recommended documentation add-...
Test driven development in Vis...
Web.config transforms...
Getting Started with Visual St...

Recent comments

kiwiandy on Winners of Windows Phone competition announced, mo: mm the first one I try... ASB.. isnt there!?...

chiefie on Winners of Windows Phone competition announced, mo: Hmm the ASB Bank app is MIA....

Daniel Ballinger on Recommended documentation add-on for Visual Studio: Personally I don't find much value from a tool like GhostDoc if the generated do...


The Visual Studio blog is sponsored by Microsoft NZ. The blog posts are the authors' genuine accounts of their experiences with Visual Studio, Windows Phone SDK and Windows Azure Platform and are not influenced or filtered by Microsoft New Zealand in any way.