opello.{com,net,org}

Visual Studio 2010 Project Upgrades

Sunday, August 22, 2010 categories: .net, code, error, irc, side projects, svn, visual studio

Yesterday afternoon I was playing around with this program I wrote for my Dad while I was in college so that he could crop and upload photos for eBay auctions. Visual Studio 2003 was the tool of choice, using C# and targeting the 1.1 CLR. Development on the tool was pretty light, and I moved on to Visual Studio 2005, and had to make a change to the program. I spent quite a bit of time working with Visual Studio 2005, but still wanted to target the 1.1 CLR.

This led me to MSBee, which is a set of msbuild targets that let you build against the 1.1 CLR in Visual Studio 2005. Which worked well enough, until I wanted to move to Visual Studio 2008. So to simplify things there, I moved to the 2.0 CLR. I removed the MSBee modifications to the project file, and got things working. Moving to the 2.0 CLR wasn't too messy, as it had been widely deployed through Windows Update. However, now one of my Dad's friends was also using the program. Field trip! Apply updates, and copy over the new version -- oh and solve random other computer issues. Yay.

And here we are, all caught up to yesterday. Finally getting around to Visual Studio 2010, and figured the "eBay Images" tool was as good a project as any to start with. Opened fine, built and even ran the first time. Great! I fixed a bug I had remembered my Dad telling me about. Rebuilt, and ran.

vs2010-error

I am a bit of a regular in the ##csharp channel on freenode, so I thought that was as good a place as any to ask. It's a pretty quiet place at 1:30am CDT. But by 2am someone had suggested that I might be referencing some 3.5 or 4.0 assemblies. Quick to check as I'm only referencing 5 assemblies -- nope. Then I thought I should open the .exe up in Reflector to see what it reported. Which listed two versions of mscorlib.dll as dependencies, 2.0 and 4.0. This seemed quite strange, and was where I fell asleep in my chair thinking about it, and woke up at 5am to actually go to bed -- not really thinking about this problem any more.

After waking up rested and refreshed, at 10am, I took another crack at the problem. Some more conversation in ##csharp, the suggestion was that the compile was bad and the only resolution was to reinstall the various framework version that I had installed (which would entail reinstalling 1.1, 2.0, 3.5, 4.0 and all updates for each -- not something I was interested in doing).

Some lucky googling led me to this Microsoft Connect post, which described exactly what I was seeing. One of the detailed comments talked about the ToolsVersion attribute of the Project node in the .csproj file.

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="2.0">

The ToolsVersion set to 2.0 is apparently a problem. Changing that to 4.0 made everything quite happy, as the workaround from the Microsoft Connect post suggested (I didn't notice the Workarounds tab until after reading all of the replies).

And tada, everything is working again!

https://code.opello.org/svn/ebayimages/ if you want to look at my very ugly, needs to be rewritten, source code. Which certainly doesn't cover the entire history of the program, but it's an ongoing effort.