No Free Time

July 17, 2008

Howto: Only include part of a project workspace in a TFS 2008 Team Build

Filed under: .net, CI, tfs — Tags: , , — andrewmyhre @ 12:56 am

I’m working on a website with a large design aspect, so we have a lot of .psd files (about 200mb) kicking about the place. We want them source controlled, so they live in the TFS 2008 team project folder in source control. But then our Team Build includes them when downloading the source files, so that quickly fills up our build server’s drive and makes a single build take up to 11 minutes, which is far too long for a basic eCommerce website.

So I trimmed these files from our build process. Here’s what I did:

  1. Copy the .psd files and any other files that aren’t required for a build into a seperate folder in the root of the team project. (All our website/source files are in another folder called ‘Current’, as in the ‘current version’, as opposed to ‘Phase 1′, ‘Phase 2′)
  2. In Team Explorer, right click the build you want to edit and selected Edit Build Definition…
  3. In the Workspace tab, enter the path within source control where you want to start downloading files from. In our case I chose the $/[project]/Current folder, so the /PSDs folder will be ignored and not downloaded.

Now, thanks to the above steps my build history folders are 1/10th the size they were to begin with, and the build process takes less than half the time!

July 13, 2008

Enabling WCF in IIS 7 on Vista

Filed under: .net, iis7, silverlight — Tags: , , , — andrewmyhre @ 3:54 am

I created a Silverlight-enabled WCF service which worked perfectly when running my Silverlight app from Visual Studio, but as soon as I deployed to IIS 7 on my machine and opened it outside of VS I received the following error:

Unhandled Error in Silverlight 2 Application Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast
…… (there was more

I couldn’t be sure whether this was a Silverlight or a WCF issue so I opened the SVC url in my browser and received a (405) Method Not Allowed response. I checked IIS and discovered there was no HTTP Handler set up for WCF services.

I then managed to find this very helpful post about setting up WCF HTTP Handlers in IIS 7, and the solution described worked perfectly for me. Here are the steps:

  1. Open a command prompt as administrator
  2. CD to c:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
  3. Type ServiceModelReg -i and press return
  4. A whole load of lines like “Installing: HTTP Handlers” will print out to the console. When it’s finished go into IIS 7 and open the HTTP Handlers list for your website. You should see a couple of new ones for the *.svc extension

Also, another issue I came across while trying to track down how to set these up was where people were deploying their WCF/Silverlight project to IIS 7 without updating their web.config to change the server binding reference. When you add a service reference to your Silverlight project the url is stored in the ServiceReferences.ClientConfig file, but if the WCF project is defined in the same solution then the URL will point to the local Cassini server, which means the service call will fail when you deploy the app to IIS.

One solution to the issue is to override the service URL in code, so that you don’t have to keep updating the .config file when you deploy to a web server.

July 11, 2008

How to create a default instance of a type T

Filed under: .net, c++ — Tags: , — andrewmyhre @ 4:41 am

A problem I’ve come across in the past when writing ORM solutions is when I need to create a new instance of generic type T but set to a NULL or 0 value. Value types I need to set to null but reference types I need to set to 0. How do I do the right thing? Here’s a bad way:

if (typeof(container) == typeof(int))
container = 0;
else if (typeof(container) == typeof(Customer))
container = null;

Using this method means lots of if … else if …else by checking type. How ugly! There has to be a better way, I thought. So I gave up and got on with something else.

Months later, it turns out there IS a better way: the default keyword:

t container = default(containerType);

This keyword gives you a NULL or 0 value based on the type you pass it. I don’t know whether it’s faster or more efficient, but hey, it’s a lot less code for you to write, and you can be pretty sure they’ve covered all the edge cases.

More information about the default keyword.

July 3, 2008

ASP.Net MVC: Giving MasterPages access to ViewData

Filed under: .net, mvc — Tags: , — andrewmyhre @ 6:38 pm

If you want to include ViewData in the MasterPage UI, you can.

ASP.Net MVC MasterPages are System.Web.Mvc.ViewMasterPage - this is a generic type just like System.Web.Mvc.ViewPage. So you can type it with a ViewData object, like this:

public partial class MyTemplate : ViewMasterPage<SomeViewData>

As soon as you do this you’re saying that the SomeViewData class is the only ViewData object that can be used on any page using this template. Not a problem though, just create a base ViewData class.

public class SiteWideViewData
{
}

public class PageViewData : SiteWideViewData
{
}

This of course means no more default ViewData objects and no more return View(); I found the easiest way to deal with that is to create a static property on the base ViewData:

public class SiteWideViewData
{
public static SiteWideViewData Default { get { return new SiteWideViewData(); } }
}

Now I can do this:

public ActionResult MySimpleControllerMethod()
{
return View(SiteWideViewData.Default);
}

And that seems to work okay.

June 29, 2008

ASP.Net MVC Toolkit Download

Filed under: .net, mvc — Tags: , — andrewmyhre @ 8:27 pm

Took me ages to find a link to download this sucker, so here’s the download link.

Download MVC Toolkit for MVC Preview 1

Note: As Simone noted in the comments, this toolkit is built against MVC Preview 1 and hence doesn’t work with Preview 2 or 3.

UPDATE:

I thought I needed it because there are so many MVC how-to articles referencing Preview 1, but it turns out much of the functionality is now rolled up into Preview 3. This assembly is now redundant, which is why it’s so hard to find. It’s *supposed* to be.

May 13, 2008

Where to manage the build location in TFS 2008

Filed under: .net, CI, tfs — Tags: , , — andrewmyhre @ 11:11 pm

Until now I’d been confused between the agent working directory, the build service accounts’s temp folder, and the workspace created by Team Build. Do I have to manage all three settings? Do they have to be different? Today I discovered there’s just one location I need to manage for each build agent.

In my efforts to clean up and standardise where projects are being downloaded and built on our build server I discovered that the workspaces automatically created by Team Build don’t actually determine where the build happens. This is because every time TFS performs a build it deletes and recreates a workspace for that build. The source directory path it uses comes from the Build Agent definition:

Build Agent Working Directory

C# Debug/Release and Performance

Filed under: .net, xna — Tags: , — andrewmyhre @ 3:52 am

I’ve been listening to this webcast today:

GDC 2008: Understanding XNA Framework Performance

I learned an interesting little fact:

“Debug vs Release setting in the IDE when you compile your code in Visual Studio makes almost no difference to performance… the generated code is almost the same. The C# compiler doesn’t really do any optimisation. The C# compiler just spits out IL… and at the runtime it’s the JITer that does all the optimisation. The JITer does have a Debug/Release mode and that makes a huge difference to performance. But that doesn’t key off whether you run the Debug or Release configuration of your project, that keys off whether a debugger is attached.”

Incidentally RoeCode’s XNA game engine series is now at part 18 and is looking pretty nice. I’ve totally slacked off of looking at XNA but I’m totally going to start playing with this again now.

May 9, 2008

Making Team Build and Web Deployment Projects play nice: Part 2

Filed under: .net, CI, tfs — Tags: , , — andrewmyhre @ 10:02 pm

Right, so yesterday I figured out how to make ASP.Net 2.0/3.5 Website projects work in a Team Build environment using Web Deployment Projects. Today I figured out how to get Web Application Projects to work.

The problem is explained in this thread - take a look at maharik’s post and BradleyB’s reply. maharik was having the same problem I was having, where the Web Deployment project was trying to build the wrong path. At this stage I still don’t fully understand what’s going on (why does the web deployment project need to be pointed to the compiled website?) but I know that it works.

So as background, I’m talking about a .Net 2.0 solution containing a Web Application Project, a Web Deployment Project and zero or more class libraries. The solution is part of a Team Project and I want to set up a Team Build to build the solution.

The Team Build must be set up using the Mixed Platforms as the platform (contrary to what the article I linked to yesterday said - but that article is still correct as far as Website projects are concerned). Choose a configuration (Release/Debug) and make sure your Web Deployment project is configured to build under the same configuration.

Try running the Team Build now. Everything but the WDP should build fine, and you should get errors like this:

error ASPPARSE: Could not load type 'masterpages_default'.

Now you need to follow the directions posted by BradleyB. Find the <SourceWebPhysicalPath>…</SourceWebPhysicalPath> element in your Web Deployment Project file. Comment it out and replace it with:

<SourceWebPhysicalPath Condition=”‘$(OutDir)’ != ‘$(OutputPath)’”>$(OutDir)_PublishedWebsites\WebApplication1</SourceWebPhysicalPath>
<SourceWebPhysicalPath Condition=”‘$(OutDir)’ == ‘$(OutputPath)’”>..\WebApplication1</SourceWebPhysicalPath>

Where ‘WebApplication1′ is the name of your website. Now check in the WDP file.

Now when you run the Team Build again you should find that everything runs successfully, and in your release folder there’ll be a deployment folder with the same name as your Web Deployment Project. Great! Now you can follow the last step from yesterday’s post to add the AfterCompile step to copy the website to your deployment folder.

Nice!

DDD Scotland

Filed under: .net, community — Tags: , — andrewmyhre @ 8:34 pm

This evening I head to Glasgow for Developer Day Scotland. Looking forward to it! Wondering if there’s a Twitter feed for it…

April 17, 2008

Developer day Scotland

Filed under: .net, community events — Tags: , — andrewmyhre @ 9:59 pm

Looking forward to Developer Day Scotland! Going to catch up with a few people I used to work with up there, before I fled to London with my tail between my legs.

Older Posts »

Blog at WordPress.com.