One of the things I’m most excited about with Visual Studio 2008 is it’s ability to target various versions of the .net framework, a feature known as multi-targeting.
I recently rebuilt a (hand-me-down) laptop for use at developer group meetings, conferences, and coding from the couch. When building out the machine I decided to only install VS2008 and make use of multi-targeting to work on my various .net 2.0 projects... like Subtext. Today I finally got around to loading Subtext up in VS2008 and I was expecting some heartache.
But I did a little research first and luckily came across Rick’s great post explaining how VS2008 and VS2005 can be made to play nice together, allowing you to work with your projects in either IDE. The gist is, the project files (i.e.- your .csproj files) will work in either environment, but you’ll need to maintain separate solution files. Not a huge deal as most of the churn is usually in the individual project files, and not the solution.
Ok, let’s do it!
Feeling rather confident after reading Rick’s post I went ahead and fired up VS2008, opened the Subtext solution, and let the conversion wizard run. No errors, the project built successfully, and I was able to run Subtext locally. Sweet!
Next I renamed the upgraded solution to make it clear that it was for VS2008. I then restored the original solution file. Afterwards I had two distinct solution files, as pictured above.
However, when trying to open the original solution in VS2005 I was unable to load one of the project, Subtext.Web, a Web Application Project. Our CI build also started failing with the following error message:
E:\CCNET-Projects\workingFolder\Subtext1.9\SubtextSolution\Subtext.Web\Subtext.Web.csproj(2183,11): error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
What gives?
When then did a diffed the Subtext.Web.csproj file, comparing the original VS2005 version to the converted VS2008 one, most things looked OK. However, I noticed that near the bottom of the file there was a reference to a specific version of some MSBuild resources.
Since I don’t have VS2008 installed on my main dev machine, nor do we have it on the Subtext build server, the project was effectively broken.
There is a Condition attribute that we can use to get around the issue. I ended up replacing the Import element with the following two elements:
<Import
Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets"
Condition="'$(Solutions.VSVersion)' == '8.0'"/>
<Import
Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets"
Condition="'$(Solutions.VSVersion)' == '9.0'" />
With those lines in place, I am able to open, build, and run Subtext in both VS2005 and VS2008.
Now to get me some of that JavaScript Intellisense goodness, giddy-up and good luck!