Slides available from 2011 Day of .NET presentations

by brad 6. August 2011 11:09

I’ve posted my slides from this year’s Day of .NET.

Also, be sure to review my presentations at the Day of .NET website.  Unless you didn’t like them.

Tags:

TFS Team Build 2010: Only deploying if unit tests pass

by brad 14. July 2011 16:33

This post describes the process that we use on our current ASP.NET MVC application to deploy our database and web application to a development environment as part of the nightly build.  We use Team Foundation Server (TFS) 2010.

What we tried first

When we first set this up, we did it by passing in a bizarre and poorly documented string of MSBuild arguments as part of our build process.  This approach is described by this stackoverflow questionand this PDF talk.

Here you can see the MSBuild arguments in our build definition.  The arguments will vary depending on your own setup so I won’t copy all of our arguments in.

image

This worked great …. except that it deployed our application even if tests failed since it’s part of the build process.  When the code was compiled, the application was deployed.  This was problematic since it meant a broken version of the site was deployed to the development environment in the unlikely event that the nightly build broke. 

The new approach

To get around this, we had to change our build process to run the deployment only if the tests passed.  This meant customizing a build process template. 

image

Editing the build process template

Every build definition is based on a build process template.  By default, they’re based on “DefaultTemplate.xaml”. The build process templates are stored in a folder called “BuildProcessTemplates” that lives in the root of your source control folder.  There are three in there with each new project

  • DefaultTemplate.xaml
  • LabDefaultTemplate.xaml
  • UpgradeTemplate.xaml

Our previous build was using DefaultTemplate.xaml so we made a copy of that one.  Editing the file opens up the Windows Workflow designer surface.

image

To get something to run only if tests pass, you’ll be interested in opening up the following sections of the template.  Be prepared, because you’re going to have to dig deep.  It can help a little to double-click each section – this will make the designer zoom to that section and hide all the others.

  • Run On Agent
  • Try Compile, Test, and Associate Changesets and Work Items
  • Sequence
  • Compile, Test, and Associate Changesets and Work Items
  • Try Compile and Test
  • Compile and Test

Here’s what it will look like when you get Compile and Test opened.

image

Adding a new action to the build template

Notice the conditional “If TestStatus = Unknown”.  This evaluates to true if the tests pass or if there are no tests.  In our case, this was exactly what we’re looking for.  We wanted to deploy our application if the tests pass and not do anything if the tests failed.

I copied the “If TestStatus = Unknown” action and made another one just like it as a starting point for our custom build action.  You can see it in the picture below.  It’s prefixed with “(CUSTOM)” to make it easily distinguished from the regular build stuff.image

In this conditional, we added three steps.  Two to deploy the database and one to deploy the application. 

image

The database deployment is just an executable that runs our DDL scripts and then uses EF to fill up the database with its initial data. Nothing fancy.

The “Deploy to DEV site” action is an MSBUILD action that has all of the goofy parameters that were previously part of our build parameters (See “What we tried first” above.).  When this runs, the code gets compiled again and the application is deployed.

image

Future improvement

One thing that’s not ideal about this approach is that the code is compiled twice.  It’s compiled once as part of the normal build and then it’s compiled once more when we run our custom workflow action.  Ideally, we would call webdeploy manually instead of calling it through MSBUILD.  This would deploy the application without building it again.  But that’s a problem for another day.

More resources

Tags: ,

Register Now for the 2011 St Louis Day of .NET

by brad 24. June 2011 13:44

Early-bird registrations are still open for the 2011 St Louis Day of .NET.  Registration price goes up by $75 if you wait until July. 

I’m presenting two sessions this year:

The Tasty Flavors of Entity Framework 4.1

The shiniest, newest version of Entity Framework 4.1 is a dramatic addition to the world of data-access in the Microsoft stack. This presentation will cover the three tasty flavors that EF 4.1 comes in: Database-first, model-first, and the exciting new code-first.

JavaScript is not C#

You can’t swing a stick in the ASP.NET world without hitting some JavaScript.  And even though both languages have curly braces, JavaScript is not C#. This presentation will cover common misconceptions about JavaScript, some hidden gotchas, and areas of danger for C# developers that expect JavaScript to work like C#.

Register now!

Tags: , , , ,

Even Entity Framework can’t be right all the time

by brad 23. June 2011 15:30

Here we see Entity Framework trying to come up with the singular form of the word “Movies”.  Nice try, Entity Framework.

image

Tags:

Web Standards Update for Visual Studio 2010

by brad 17. June 2011 12:18

The Web Platform and Tools team has released an update for Visual Studio that adds better support for modern HTML, JavaScript, and CSS.  With these web technologies changing faster than the Visual Studio release cycle, it’s good that the team is able to sneak out these out-of-band updates for us.

Download Web Standards Update for Visual Studio 2010

More information

Tags:

Visual Studio 2010 Extensions I Use

by brad 8. June 2011 14:09

Productivity Power Tools (Microsoft)

The Productivity Power Tools extension is a collection of handy and nifty features from the Visual Studio team.  Some of the more useful features include an improved Find experience, a new Solution Navigator, an improved Add Reference dialog, colored tabs, vertical code editor guides, and keyboard shortcuts to move lines of code up and down. 

Download Productivity Power Tools

Team Foundation Server Power Tools March 2011 (Martin Woodward)

This extension adds a variety of tools to make working with TFS a better experience.  My favorites include Alerts Explorer and Process Editor.

Download Team Foundation Server Power Tools

ReSharper

ReSharper is so great I would be angry if I had to code without it.  The one downside is that over the years I have started to get confused as to where VS stops and ReSharper starts, but that’s not a problem as long as I continue to live in the ReSharper world.  Unlike the other tools in this list, ReSharper is not free.  But it’s well worth the price.

Download ReSharper

JScript Editor Extensions (Microsoft)

The JScript Editor Extensions adds a variety of useful features for editing JavaScript in Visual Studio.  The most useful feature is outlining and code-folding, even though the VS shortcut keys for outlining are not supported.

Download JScript Editor Exensions

NuGet Package Manager (Microsoft)

NuGet is such an integral part of my day-to-day development that it’s hard to imagine it’s not just part of Visual Studio.  Hopefully it will just be part of the next version of Visual Studio.  Until then, download it second, right after ReSharper.

Download NuGet

Web Standards Update for Visual Studio 2010

The Web Platform and Tools team has released an update for Visual Studio that adds better support for modern HTML, JavaScript, and CSS.  With these web technologies changing faster than the Visual Studio release cycle, it’s good that the team is able to sneak out these out-of-band updates for us.

Download Web Standards Update for Visual Studio 2010

Tags:

Taking a break

by brad 8. December 2010 06:00

I’ve decided to put the Windows Phone 7 Tip of the Day on the back burner for a while.  As I’m sure regular subscribers have noticed, the “of the day” preposition has not been accurate lately.  I might switch to a weekly format, or try something else entirely, but for the time being, I’m just taking a break to concentrate on some higher priorities.

Tags:

WP7 Tip of the Day

WP7 Development Tip of the Day: Using ShellTileSchedule to update your app’s Live Tile background

by brad 24. November 2010 13:35

About Live Tiles

Live Tiles are called Live Tiles for good reason: they are more than just a boring picture.  You can do lots of things with live tiles, including updating the background image, changing the title, and displaying a count.

About ShellTileSchedule

This tip focuses on one way you can update your app’s live tile background: The ShellTileSchedule.  Of the two ways to update the background image, ShellTileSchedule is by far the easiest.  The other mechanism is a push notification.

To start, you need to get the background image you will use for your background on a web server.  ShellTileSchedule can only pull images off the web, not from the phone itself.  This is one of the limitations of ShellTileSchedule.  If you want to set background images to resources on the phone, look at using push notifications instead.

The Code

Once you have your image on the web, setting up a schedule to update it is as simple as executing this code when your application launches

   1: var url = "http://www.codebadger.com/photoservice/random";
   2: var schedule = new ShellTileSchedule
   3:                     {
   4:                         Interval = UpdateInterval.EveryHour,
   5:                         MaxUpdateCount = 10,
   6:                         Recurrence = UpdateRecurrence.Interval,
   7:                         RemoteImageUri = 
   8:                         new Uri(url),
   9:                         StartTime = DateTime.Now
  10:                     };
  11: schedule.Start();

This will register a new update schedule with the phone.  In this particular example, we’re making a call to a pretend web service that returns a different random image every time it’s called. This provides a convenient way to get different images to the phone without code changes.

This schedule changes the image every hour and will quit updating the image after 10 updates.  If the code executes again (like when your app runs again), the count starts over.

Gotchas

  • The image will not update immediately.  Give it an hour or so before you suspect that you did something wrong.
  • The image will update both in the emulator and on the real phone, so you can test in either.
  • The image must be 80KB max and have a download time of less than 15 seconds.
  • Tiles won’t update if the phone is locked

Other Resources

More Tips

Tags:

WP7 Tip of the Day | Windows Phone

WP7 Development Tip of the Day: Live Tiles that use the system theme accent color

by brad 23. November 2010 06:00

Many of the default Windows Phone application live tile icons pick up the color of the system theme accent color.  For example, the phone app, people app, messaging app, and internet explorer use the system accent color as their background.  Here’s what the emulator looks like with the accent color set to blue and lime.

CropperCapture[6]

CropperCapture[7]

Your application icons can do this is well.  It’s as easy as saving your background image with transparency where you want the accent color to come through.  By default, the live tile icon that is created with new Visual Studio projects (Background.png) has a dull gray background that looks like this.

CropperCapture[8]

With that dull gray replaced by transparency, the system accent color comes through.  Here’s Background.png in Paint.net, with the gray deleted and white replaced with red.  In practice, red would be a very poor choice since one of the system accent colors is red.  White is probably your best bet, but I used red so we can see the contrast between the transparency and the icon’s image.

CropperCapture[4]

When run in the emulator, this icon looks like this:

CropperCapture[10]

Or this, depending on the system accent color

CropperCapture[11]

Other Resources

More Tips

Tags:

Windows Phone | WP7 Tip of the Day

WP7 Development Tip of the Day: Detecting changes to the internet connection

by brad 18. November 2010 15:42

Like the previous tip on detecting if a phone’s internet connection is available, today’s tip comes from the System.Net.NetworkInformation namespace.  The NetworkChange class has a handy event called the NetworkAddressChanged event.  This event is called when the phone gets a new IP address.

   1: public MainPage()
   2: {
   3:     InitializeComponent();
   4:     NetworkChange.NetworkAddressChanged += NetworkAddressChanged;
   5: }
   6:  
   7: static void NetworkAddressChanged(object sender, EventArgs e)
   8: {
   9:     throw new NotImplementedException();
  10: }

Since getting a new IP address is not quite the same as going online or offline, it takes a little more doing to find out if the phone’s connection status has really changed.  This is where our previous tip comes in handy.  You can use the NetworkInterface class to check if the phone has a connection.

   1: public MainPage()
   2: {
   3:     InitializeComponent();
   4:     NetworkChange.NetworkAddressChanged += NetworkAddressChanged;
   5: }
   6:  
   7: private static void NetworkAddressChanged(object sender, EventArgs e)
   8: {
   9:     if (!InternetIsAvailable())
  10:         MessageBox.Show("You just lost your internet connection.");
  11: }
  12:  
  13: private static bool InternetIsAvailable()
  14: {
  15:     return !NetworkInterface.GetIsNetworkAvailable();
  16: }

Of course, an app that pops up a message box every time the phone loses its internet connection would be madness.  But it shows the general concept

Other Resources

More Tips

Tags:

About Brad

Brad Tutterow lives in Illinois and works in Missouri. He has 12 years of experience developing web sites and Windows applications using a variety of technologies and is most excited currently about Silverlight, Windows Phone 7, Halo Reach, and Visual Studio 2010.