My Visual Studio Side by Side Problem
On my new laptop I had installed VS 2008 but had not done any Web Service development - so I hadn’t yet installed IIS or registered ASP.NET.
Then I installed VS 2010 Beta 1.
A while later I began preparing samples for a course in WCF that I am teaching these days – using Visual 2008. So I installed IIS 7.0 (I am running Vista Business) and registered ASP.Net from the Visual Studio 10.0 command prompt.
I created a simple “Hello World” ASMX Web Service and a “GetData” WCF Service with VS 2008 and hosted them on Local IIS.
Neither worked.
Analysis
Of course, you should be able to run code developed with .Net 3.5 (or even .Net 1.1 for that matter) under ASP.NET 4.0 and you should also be able to host it under ASP.NET 3.5 (2.0 for all intents and purposes) if you so choose.
So why didn’t one of those happen for me?
Well, I had a number of problems – maybe not all related, but I think the essential one was that because I had run aspnet_regiis from the Visual Studio 10.0 command prompt I had installed ASP.NET 4.0 and not 2.0.
So what to do?
Solution
Well, I found I that both options are possible:
Option 1: Run the .Net 3.5 Site under ASP.NET 4.0
There are a number of things you would need to configure in the environment for this to work:
- You need to add the targetFrameworkMoniker=".NETFramework,Version=v4.0” attribute in the <compilation> element of your Web.Config (see the MSDN documentation here).
Visual Studio 2008 doesn’t know about ASP.NET 4.0, so this needs to be done manually. - You need to remove the elements in the <system.codedom> section that explicitly specify use of the compiler for .Net 3.5. Visual Studio 2008 adds these by default to its ASP.NET (ASMX) and WCF Service Web Sites.
This should work for both ASMX and WCF sites with default settings developed with Visual Studio 2008.
Option 2: Just Let Me Target ASP.NET 2.0, Thank You
When I want to run under ASP.NET 4.0 I will use Visual Studio 2010 and get the goodies that go with it. If I am developing an application with Visual Studio 2008 – why can’t I just target ASP 2.0 like I used to?
Well, of course that’s possible, but if you haven’t registered ASP.NET 2.0 with IIS like me, you need to do the following:
- From the Visual Studio 10.0 prompt run: aspnet_regiis.exe –ua to unregister all ASP.NET versions (to be safe).
- From the Visual Studio 2008 prompt run: aspnet_regiis.exe –i to register ASP.NET 2.0.
- Now you may think that thats enough – but its not. You still wont have a mapping for your “.svc” extensions to the aspnet_isapi.dll. This would normally be installed by Visual Studio 2008, but if, like me you installed IIS after installing VS 2008 it wouldnt have been able to do so. So, you need to:
- Go to Control Panel –> Adminstrative Tools –> IIS.
- Select the root node and double click on Handler Mappings in the right pane.
- Click “Add Script Map” and add a new entry with name, say, “svc-3.5”, path “*.svc”. Have the Executable point to the aspnet_isapi.dll in your .Net 2.0 directory (%WINDIR%\Microsoft.NET\Framework\v2.0.XXX).
- Oh, and there is one more thing. As I am running IIS 7.0 I needed to add an Application Pool that would run under ASP.NET 2.0. This is how:
- Go to Control Panel –> Adminstrative Tools –> IIS.
- Select the first child of the root node (Application Pools) and right click to “Add an Application Pool”.
- Configure the new App pool with: Name “ASP.NET v2.0 Classic”, .Net Framework version “.Net Framework v2.0.XX” and managed pipeline mode “Classic”. Check the “start application pool immediately” and OK.
- Select the new Application Pool and make sure its started.
Afterword
Hmmm. It looks like the second option (targeting ASP.Net 2.0/3.5) was much more of a bother than just surrendering to ASP.NET 4.0.
But in my opinion it is the preferred way. Let’s not forget, that when targeting ASP.NET 4.0 you need to make the modifications I described for every new Web Service you create in VS 2008.
Conversely, if you choose to target ASP.NET 2.0 then, in both Visual Studio 2008 and in Visual Studio 2010 Beta 1 you will be able to create ASMX and WCF services with default settings for ASP.NET 2.0/3.5 and ASP.NET 4.0 respectively. Each will “automatically” find the right Application Pool to run under.
Conclusion
You can develop and test ASMX and WCF Web Services for .Net 3.5 (and earlier) and for .Net 4.0 on the same machine with Visual Studio 2008 and Visual Studio 2010 Side by Side