About the author

Steven Harmansteven harman :: makes sweet software with computers!

For recent posts and more about me, scroll to the bottom.

Sponsors

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!

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!

Solution Files in Explorer 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?

Comparing the project files 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!

Technorati Tags: , , , ,

What others are saying.

# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Dan Hounshell
Sep 28, 2007
Awesome tip.

But did you actually write "Now to get me some of that JavaScript Intellisense goodness, giddy-up and good luck!"

Giddy-up? Really!?!? Ha ha ha - I sprayed my monitor with Sam Adams.
# Multi-targeting VS2005 and VS2008 Web Application Projects - A Gotcha
Gravatar DotNetKicks.com
Sep 28, 2007
You've been kicked (a good thing) - Trackback from DotNetKicks.com
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Steven Harman
Sep 29, 2007
@dan, are you not a Seinfeld fan?

Oh, and what kind of Sammy where you enjoying? I'm a big fan of their Oktoberfest and also their Winter brew.
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Scott
Sep 30, 2007
It's great to see Subtext up on VS2008, now when do we get to start using some of the new language features?

This is a great tip about multi-targeting and how to solve one of the problems it can create.
# Links of the week #5 (week 39/07)
Gravatar Bite my bytes
Sep 30, 2007
Links of the week #5 (week 39/07)
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Dan Hounshell
Oct 01, 2007
Oh that's where that quote came from. I knew I recognized it. I just couldn't place it.

Sam Adams Lite at the time, but I do love their Octoberfest and Winter brews as well. I had some Octoberfest last night at dinner. Their seasonal brews are awesome. I think of all the ones that I have tried there has been only one that I didn't really care for.
# Setting Visual Studio Split View Defaults
Gravatar StevenHarman.net
Oct 27, 2007
Setting Visual Studio Split View Defaults
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar bastian
Nov 10, 2007
I haven't tried it myself, but I guess this would work too:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(Solutions.VSVersion)\WebApplications\Microsoft.WebApplication.targets"

You know, DRY. ;)
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Erik Wynne Stepp
Nov 23, 2007
Bastian, I had the same idea so I tried it.

Unfortunately, that doesn't work in VS2005. The property doesn't evaluate to anything, so VS can't find "$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v\WebApplications\Microsoft.WebApplication.targets"

The code above should fail under VS2005, too, except that the Condition attribute seems to be ignored, so the hard-coded v8.0 works fine.
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Rams
Nov 28, 2007
Thank you for the tip. You made my day!
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Kevin Zink
Jan 26, 2008
Hey guys,

Sorry I seemed to have posted a bunch of blank comments, although I'm not sure how.

I did run into a problem with this solution when deploying to a TFS 2005 build server; it doesn't seem to handle the conditional logic in the correctly. Basically, it will fail to import the .targets file and consequently NOT deploy your Web Application's files (.aspx, html, binaries, etc.)

I came up with a workaround for this case: I did not change the .csproj declarations at all (the one pointing to v9.0 is still there). Instead, I created the "v9.0" directory on my TFS 2005 build server and copied into there the .targets file from the "v8.0" directory. Seems to work great.

Here's a blog post that goes into more detail: zinknation.net/Using+Visual+Studio+2008+With+Te...
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Kevin Zink
Jan 26, 2008
Ack, apparently I suck at copy pasting. Instead of pasting in my blog post link, I pasted in an entire other comment...

*sigh*

Here is the blog post link I meant to paste in: zinknation.net/...oundation+2005+Build+Server.aspx
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Steven Harman
Jan 29, 2008
@Kevin, I went ahead and edited your comment to remove the copy/paste error.

I usually don't edit user comments as I don't believe in censorship - but I wouldn't really consider this case to be censorship. :)

Thanks for the tip!
# .NET Framework versioning, or The impact of switching from Visual Studio 2005 to 2008
With the official release of Visual Studio 2008 coming closer and its release on MSDN last november,
# .NET Framework versioning, or The impact of switching from Visual Studio 2005 to 2008
Gravatar Blog
Feb 14, 2008
With the official release of Visual Studio 2008 coming closer and its release on MSDN last november,
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar oo
Apr 02, 2008
@Kevin: don't need to copy that directory for TFS2005, simply add another conditional import:

<Import
Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" Condition="'$(Solutions.VSVersion)' == ''"/>


This works because $(Solutions.VSVersion) evaluates to empty on TFS2005.
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar Jesse
Jun 03, 2008
It deosnt seem like $(Solutions.VSVersion) is really even defined. I cant find anything confirming that this is an actual property. Were did you determine this property actually evaluates to a value?

However, this does seem to work




Since MSBuildToolsPath is a new property for msbuild 3.5 it will be defined when running vs.net 2008 but not 2005. This solution seems to work for me to open up a web project in V2.Net 2008, 2005 and succesfully build the project with TFS 2005 so that the _PublishedWebsites is properly sent to the output directory.
# re: Multi-Targeting VS2005 and VS2008 Web Application Projects, a Gotcha!
Gravatar conan
Jun 25, 2008
it's awesome !
# Interesting Finds: 2008.09.10~2008.09.14
Gravatar Community Blogs
Sep 15, 2008
.NET Closures Algorithm to Detect Blank Images Performance Analysis Reveals Char[] Array is Better than
Comments have been closed on this topic.