Professional Visual Studio
Tips, Tricks, and Best Practices for professional .net developers

Today I spent some time repaving my computer with the PDC build of Windows 7.  Whilst it’s probably a long way out I thought I would see just how far Microsoft is along with the next version of Windows.  After all, the reports I’ve been hearing have been very positive about it and to be honest, it can’t be much worse than Vista.

I encountered a couple of minor issues early on but nothing that was insurmountable.  When it came to installing Visual Studio 2008 the core product installed fine but SP1 kept on failing – I tried a couple of times thinking it was caused by me doing other things whilst the install was progressing. 

I took a quick look at the error log and noticed it failing on one assembly to do with Visual Studio Tools for Office. 

image

Drilling into the VSTO specific log I was able to pull out the knowledge base number, ie KB949258.

MSI (s) (F0:5C) [18:27:43:876]: Windows Installer installed an update. Product Name: Visual Studio Tools for the Office system 3.0 Runtime. Product Version: 9.0.30729. Product Language: 0. Manufacturer: Microsoft Corporation. Update Name: KB949258. Installation success or error status: 1603. 

This meant I was able to look up the individual update - Microsoft Visual Studio Tools for the Microsoft Office System (version 3.0 Runtime) Service Pack 1 (x86).  Downloading and installing this before SP1 of Visual Studio 2008 enabled the installation to progress nicely.

Do you want to integrate Virtual Earth into your website but are daunted by the prospect of using the javascript object?  Well as part of the Windows Live Tools for Visual Studio there is an ASP.NET Virtual Earth control that you can drag onto your aspx page, set properties add event handlers, all without writing a line of javascript.

To get started you will of course need to download and install the Windows Live Tools for Visual Studio.  The November CTP is currently available for download.

Once you have installed the tools you will notice that there are some additional toolbox items in a tab entitled Virtual Earth:

image

Select the Map and drag it onto your aspx page.  Note that you will also need a ScriptManager control as the Virtual Earth ASP.NET control uses this to communicate with the server so that you can wire up events.

image

As you can see you can set properties on this control such as the Zoom level, whether Traffic information is displayed and even whether the scale is in Miles or Kms.  What’s even better about this control is if you select the Event tab in the properties window you will see that there is a list of server side events that you can wire up.

image

Here you can see I’ve added an event handler for the ServerClick event.  The Server prefix is there to indicate that the event is raised server side. Here is some code that adds a polygon shape to the map when the map is clicked.

using System.Collections.Generic;
using Microsoft.Live.ServerControls.VE;

namespace VESampleApp
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Map1_ServerClick(object sender,
                                        MapEventArgs e)
        {
            Shape s = new Shape(ShapeType.Polygon, new List<LatLongWithAltitude>(){
                                                        new LatLongWithAltitude(20,20),
                                                        new LatLongWithAltitude(20,25),
                                                        new LatLongWithAltitude(25,25),
                                                        new LatLongWithAltitude(25,20)
            });
            s.HideIcon();
            this.Map1.AddShape(s);
        }
    }
}

Kevin Hoffman has a very quick overview of getting started with the Live Framework SDK and Tools for Visual Studio. I just wanted to go through the process in a little more detail to point some things out along the way.  The first thing you will need to do is to get yourself signed up to the Live Framework CTP.  This can be done via the Microsoft Connect website – there currently seems to be a waiting list for this which Microsoft will hopefully open up as they get closer to release for the Live Framework.

Once you are on the CTP program you need to install the following components:

You will also need to complete the registration process by going to the Azure Services Developer Portal.  If you don’t already have an Azure account you may be prompted to agree to the services terms and conditions after signing in with your Live Id.  Once in, you will need to go to the Account tab where you can reclaim the token you would have been assigned by entering the CTP program – this will enable you to create Live Framework projects.

Now that you are ready, let’s begin by creating your first Silverlight Mesh-enabled Web Application.  You can do this by opening Visual Studio 2008 and selecting File>>New>>Project.  In the New Project dialog you will see that there is now a tree item for Live Framework where there are some templates for creating Mesh applications. 

image

Here we are selecting the Silverlight application and of course we are doing the canonical Hello [World] Mesh application. Upon selecting Ok you will see that two projects are created.  One is the actual Silverlight application, whilst the other is used for packaging and deploying to the Azure platform ready for debugging – yes, that’s right you can debug your application whilst it is running in the cloud.

image

Here we have only slightly modified the text in the created TextBlock but other than that there have been no other changes.  Without doing anything further we can go ahead and hit F5 to begin debugging the application in the cloud.  When you do this you will notice the following dialog appear.

image

These three steps will take a couple of minutes but luckily only need to be done the first time you are debugging your application.

1.You will need to go back to the Azure Services Developer Portal (this can be done by clicking the link).  There you will need to hit the New Project link.

image

Then select the Live Framework CTP project type.  If this is disabled then you haven’t got a valid token registered against your Live Id account.

image

Next, fill in the details about your project

image 

Select Mesh-enabled Web application, and hit Create to complete the project creation wizard.

image

2. Now, return to the dialog in Visual  Studio and hit the “Copy full path of HelloSilverlightMesh.zip to clipboard” link.  This is the local path for the compressed file that you need to upload to the cloud that represents your application.

Return to the Azure Services Developer Portal where you should still have the project you just created visible.

image

Select the Upload Package button, then hit the browse button.  When prompted for a file to upload, just paste (Ctrl-V) the path from the clipboard and press Ok.

image 

With a file select, hit the Deploy button to upload the application to the cloud.

image

I’ve experienced some issues at this point where it hasn’t accepted the application the first time I’ve attempted to upload it.  You may need to retry this step a couple of times. Once it has been done successfully you will notice that the project information page has been updated to include additional information.  This includes the Application Self Link which is required in the third step.

image

Select the Application Self Link url and copy (Ctrl-C) into the clipboard.

3.Paste the url into the textbox in the Visual Studio dialog

image 

Click Ok to proceed with application deployment.

Once deployment has been completed you will notice that a new Internet Explorer window appears with your Live Desktop (you may be prompted to Sign In).  Open on your Live Desktop should be your newly created application.

image

Notice that there is an application icon on the desktop so that you can restart your application at a later stage.

As Kevin points out, where this becomes really cool is that this application can be synchronized to your desktop.  To do this you unfortunately need to uninstall the publically available Live Mesh client.  Once you have done this, go to the Mesh CTP Live Desktop (https://developer.mesh-ctp.com/) and click on Add Device – from here you can download the LiveFrameworkClient installer.  This is essentially Live Mesh but is only enabled for application synchronisation.

After installing the Live Framework Client you will of course be prompted to sign in. As with the Live Mesh Client you will have to enrol your computer into the (developer) mesh, which will in turn synchronise the Silverlight Hello Mesh application to your desktop.

image

Double-clicking this icon, like any other icon, opens the application.  Despite being a Silverlight application it runs outside the browser with the familiar Live Mesh information tab alongside it.

image

This is the start of interesting times for application developers.  I think that the Live Framework and other services offered by the Azure Platform will significantly change the way we architect applications into the future.

The October edition of the Win a copy of Professional Visual Studio 2008 competition has now closed and our winners have been drawn. I am pleased to announce the winners for this month are Tomasz Smykowski from Poland and Simon Andersson from Sweden. Congratulations to you both.

Everyone else has another chance of winning one of the 6 remaining books starting right now. To enter the competition you need to either:

  • Write a comment on any post (it doesn’t have to be this one); or
  • Link to this blog from your own website/blog (We accept trackbacks, or you can let us know about the link via email).

At the end of November we will draw two new winners at random from those who participated during this month.

The competition is open to everyone. If you are lucky enough to be drawn as a winner, we will contact you via email before announcing the winners. Winners will need to provide us with their name, telephone number, and shipping address.

This competition has been made possible due to the generosity of our publisher, Wiley Publishing.

Good luck!

We’re very pleased to make announce that you can now download a free chapter from our book, Professional Visual Studio 2008. Based on popular request, we have decided to release Chapter 32: ASP.NET Web Applications. This is one of my favourite chapters from the book and, at 42 pages long, it also happens to be the largest.

Download the free sample chapter [PDF 2.6Mb]

Web Application vs Web Site Projects Designing Web Forms

This free chapter covers the following:

  • Web Application vs. Web Site Projects
  • Creating Web Projects (Both Web Site and Web Application projects)
  • Designing Web Forms (The HTML Designer, CSS Tools, Validation Tools)
  • Web Controls (Navigation, User Authentication, Data Components, Web Parts)
  • Master Pages (Including Nested Master Pages)
  • Rich Client-Side Development (JavaScript, ASP.NET AJAX, AJAX Control Extenders)
  • ASP.NET Web Site Administration (Security, Application Settings)

Also don’t forget that today is the last day to enter our monthly competition for your chance to win your very own copy of Professional Visual Studio 2008.

I just noticed that the first CTP is now available for download.

The September edition of the Win a copy of Professional Visual Studio 2008 competition has now closed and our winners have been drawn. So without further ado, I am pleased to announce the winners are Jay Parzych from Connecticut and Harvey Green from Western Australia. Congratulations to you both.

As for everyone else who entered, don’t despair, the October edition of the competition begins right now, so you still have a chance of winning one of the 8 remaining books.

As with last month, to be in the running you need to either:

  • Write a comment on any post (it doesn’t have to be this one); or
  • Link to this blog from your own website/blog (We accept trackbacks, or you can let us know about the link via email).

At the end of October we will draw two new winners at random from those who participated during this month.

This competition is open to everyone. If you are lucky enough to be drawn as a winner, we will contact you via email before announcing the winners. Winners will need to provide us with their name, telephone number, and shipping address.

This competition has been made possible due to the generosity of our publisher, Wiley Publishing.

Good luck!

We’re quickly approaching the last of the Debugger attributes in the System.Diagnostics namespace. After this week there are only two more to go, but don’t despair, because I’ve saved the best till last. However for now let’s take a look at the DebuggerNonUserCode and DebuggerStepperBoundary attributes.

The DebuggerNonUserCode attribute has the same effect as using both the DebuggerHidden and DebuggerStepThrough attributes at the same time. In the default Visual Studio configuration, code marked with this attribute will appear as external code in the call stack as shown below. As with the DebuggerStepThrough attribute, breakpoints cannot be set in blocks of code marked with this attribute. Stepping through code will step into any code called by that block of code in the same way it does for the DebuggerHidden attribute.

Call stack showing the effect of the DebuggerNonUserCode attribute

Code that is marked with the DebuggerNonUserCode attribute will be visible in the call stack if you disable the Just My Code option under Tools->Options->Debugger->Enable Just My Code (Managed Only).

DebuggerStepperBoundary is probably the most obscure of all of the Debugger attributes, as it only comes into effect under quite specific conditions. It is used to avoid a misleading debugging experience that can occur when a context switch is made on a thread within the boundaries of the DebuggerNonUserCode attribute. It is entirely possible in this scenario that the next user-supplied code module stepped into may not actually relate to the code that was in the process of being debugged. To avoid this undesirable situation, the DebuggerStepperBoundary, when encountered under this scenario, will escape from stepping through code to running code.

As with all of the debugger attributes, both the DebuggerNonUserCode and DebuggerStepperBoundary attributes are ignored by the CLR and as such have no affect during normal execution. So you do not need to worry about any implications of leaving any of these attributes in place in production code.

We have 10 copies of our book, Professional Visual Studio 2008, to give away. Rather than hand them all out at once, we’ve decided to spread things out a little, and give away 2 books per month for the next 5 months.

To be in the running you need to either:

At the end of each month we will draw two winners at random from those who participated during that month.

This competition is open to everyone (regardless of where you reside). If you are lucky enough to be drawn as a winner, we will contact you via email before announcing the winners. Winners will need to provide us with their name, telephone number, and shipping address.

This competition has been made possible due to the generosity of our publisher, Wiley Publishing.

Good luck!

The DebuggerStepThrough attribute is another of the debugger attributes that should be used carefully and only on well-tested code. Like the DebuggerHidden attribute, when the DebuggerStepThrough attribute is applied to a piece of code, that code is stepped over during debugging.

Similar to the DebuggerHidden attribute, breakpoints cannot be set within a block of code marked with the DebuggerStepThrough attribute. However, within the call stack the attributed code will be marked as external code. For example, consider the following code snippet where the DebuggerStepThrough attribute has been set on HiddenMethod:

private void ClickHandler(object sender, EventArgs e)
{
   HiddenMethod();
}

[DebuggerStepThrough()]
public void HiddenMethod()
{
   Console.WriteLine("Can't set a breakpoint here");
   NotSoHiddenMethod();
}

public void NotSoHiddenMethod()
{
   Console.WriteLine("Can set a breakpoint here!");
}

If you run this code with a breakpoint set in NotSoHiddenMethod, the call stack will appear as shown below:

Call stack showing the effect of the DebuggerStepThrough attribute

Visual Studio 2008 supports the Just My Code option, configurable from the Debugging node in the Options dialog (select Tools > Options). Unchecking this option makes all code contained within your application appear in the call stack, as shown below. This includes designer and other generated code that you might not want to debug. Once this option is unchecked, breakpoints can also be set in blocks of code marked with this attribute.

Call stack showing the effect of the DebuggerStepThrough attribute combined with the Just My Code setting

DebuggerStepThrough is very useful when working with code that calls a lot of properties, for example, if you are calling a method that passes in a large number of properties as parameters. If you add the DebuggerStepThrough attribute to all the properties, and then you won’t step into all of the properties when debugging the method call.

Next Page »


About this site

Professional Visual Studio aims to provide tips and tricks, traps to avoid, and industry best practices from experienced .NET developers on using Visual Studio in the most effective way possible.

Copyright © 2007-2009 David Gardner, Keyvan Nayyeri, and Nick Randolph. All rights reserved.
Blog | Archives | Books | About | Contact