Apr 14 2008

Using Visual Studio 2005 with .NET Framework 3.5

Category: Programmingavinashsing @ 5:30 am

If you want to try out the new features available in .NET 3.5, then the first thing you should do is download the 3.5 Framework from Microsoft using the link below:

Download .NET Framework 3.5

This will install everything you need to get started. Once you’ve run the setup, you can launch Visual Studio 2005 and create a new website project. To test that you are able to run C# 3.0 codes which is available in .NET Framework 3.5, go to the code behind of the Default.aspx page and insert the following codes:

 

1 using System;

2 using System.Data;

3 using System.Configuration;

4 using System.Web;

5 using System.Web.Security;

6 using System.Web.UI;

7 using System.Web.UI.WebControls;

8 using System.Web.UI.WebControls.WebParts;

9 using System.Web.UI.HtmlControls;

10

11 public partial class _Default : System.Web.UI.Page

12 {

13 protected void Page_Load(object sender, EventArgs e)

14 {

15 var _tempVar = 4;

16 Response.Write(“Values of temp var: “ + _tempVar.ToString());

17 }

18 }

If you try to compile the website, you will get an error because Visual Studio 2005 will not use .NET Framework 3.5 by default.

 

20 Error 63 The type or namespace name ‘var’ could not be found (are you missing a using directive or an assembly reference?) C:\Av\Web35\Default.aspx.cs 15 9 C:\Av\Web35\

To be able to take advantage of .NET 3.5 with Visual Studio 2005, you will need to add a web.config file (if you do not have one alreadyin your project) and replace the content with the following:

 

    1 <?xml version=1.0?>

    2 <configuration>

    3   <configSections>

    4     <sectionGroup name=system.web.extensions type=System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35>

    5       <sectionGroup name=scripting type=System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35>

    6         <section name=scriptResourceHandler type=System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 requirePermission=false allowDefinition=MachineToApplication/>

    7         <sectionGroup name=webServices type=System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35>

    8           <section name=jsonSerialization type=System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 requirePermission=false allowDefinition=Everywhere/>

    9           <section name=profileService type=System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 requirePermission=false allowDefinition=MachineToApplication/>

   10           <section name=authenticationService type=System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 requirePermission=false allowDefinition=MachineToApplication/>

   11           <section name=roleService type=System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 requirePermission=false allowDefinition=MachineToApplication/>

   12         </sectionGroup>

   13       </sectionGroup>

   14     </sectionGroup>

   15   </configSections>

   16

   17   <appSettings/>

   18   <connectionStrings/>

   19

   20   <system.web>

   21     <compilation debug=false strict=false explicit=true>

   22       <assemblies>

   23         <add assembly=System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089/>

   24         <add assembly=System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   25         <add assembly=System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089/>

   26         <add assembly=System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089/>

   27       </assemblies>

   28     </compilation>

   29

   30     <pages>

   31       <namespaces>

   32         <clear/>

   33         <add namespace=System/>

   34         <add namespace=System.Collections/>

   35         <add namespace=System.Collections.Generic/>

   36         <add namespace=System.Collections.Specialized/>

   37         <add namespace=System.Configuration/>

   38         <add namespace=System.Text/>

   39         <add namespace=System.Text.RegularExpressions/>

   40         <add namespace=System.Linq/>

   41         <add namespace=System.Xml.Linq/>

   42         <add namespace=System.Web/>

   43         <add namespace=System.Web.Caching/>

   44         <add namespace=System.Web.SessionState/>

   45         <add namespace=System.Web.Security/>

   46         <add namespace=System.Web.Profile/>

   47         <add namespace=System.Web.UI/>

   48         <add namespace=System.Web.UI.WebControls/>

   49         <add namespace=System.Web.UI.WebControls.WebParts/>

   50         <add namespace=System.Web.UI.HtmlControls/>

   51       </namespaces>

   52

   53       <controls>

   54         <add tagPrefix=asp namespace=System.Web.UI assembly=System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   55         <add tagPrefix=asp namespace=System.Web.UI.WebControls assembly=System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   56       </controls>

   57     </pages>

   58

   59     <authentication mode=Windows/>

   60

   61     <httpHandlers>

   62       <remove verb=* path=*.asmx/>

   63       <add verb=* path=*.asmx validate=false type=System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   64       <add verb=* path=*_AppService.axd validate=false type=System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   65       <add verb=GET,HEAD path=ScriptResource.axd validate=false type=System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   66     </httpHandlers>

   67

   68     <httpModules>

   69       <add name=ScriptModule type=System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   70     </httpModules>

   71   </system.web>

   72

   73   <system.codedom>

   74     <compilers>

   75       <compiler language=c#;cs;csharp extension=.cs type=Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 warningLevel=4>

   76         <providerOption name=CompilerVersion value=v3.5/>

   77         <providerOption name=WarnAsError value=false/>

   78       </compiler>

   79       <compiler language=vb;vbs;visualbasic;vbscript extension=.vb type=Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 warningLevel=4>

   80         <providerOption name=CompilerVersion value=v3.5/>

   81         <providerOption name=OptionInfer value=true/>

   82         <providerOption name=WarnAsError value=false/>

   83       </compiler>

   84     </compilers>

   85   </system.codedom>

   86

   87   <system.webServer>

   88     <validation validateIntegratedModeConfiguration=false/>

   89     <modules>

   90       <remove name=ScriptModule/>

   91       <add name=ScriptModule preCondition=managedHandler type=System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   92     </modules>

   93     <handlers>

   94       <remove name=WebServiceHandlerFactory-Integrated/>

   95       <remove name=ScriptHandlerFactory/>

   96       <remove name=ScriptHandlerFactoryAppServices/>

   97       <remove name=ScriptResource/>

   98       <add name=ScriptHandlerFactory verb=* path=*.asmx preCondition=integratedMode type=System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

   99       <add name=ScriptHandlerFactoryAppServices verb=* path=*_AppService.axd preCondition=integratedMode type=System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

  100       <add name=ScriptResource verb=GET,HEAD path=ScriptResource.axd preCondition=integratedMode type=System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35/>

  101     </handlers>

  102   </system.webServer>

  103

  104   <runtime>

  105     <assemblyBinding xmlns=urn:schemas-microsoft-com:asm.v1>

  106       <dependentAssembly>

  107         <assemblyIdentity name=System.Web.Extensions publicKeyToken=31bf3856ad364e35/>

  108         <bindingRedirect oldVersion=1.0.0.0-1.1.0.0 newVersion=3.5.0.0/>

  109       </dependentAssembly>

  110       <dependentAssembly>

  111         <assemblyIdentity name=System.Web.Extensions.Design publicKeyToken=31bf3856ad364e35/>

  112         <bindingRedirect oldVersion=1.0.0.0-1.1.0.0 newVersion=3.5.0.0/>

  113       </dependentAssembly>

  114     </assemblyBinding>

  115   </runtime>

  116 </configuration>

This is the default web.config that is created in Visual Studio 2008 and it will compile your website without any errors. However the only problem you will encounter with using Visual Studio 2005 with .NET Framework 3.5 is that you are not able to use intellisense for the features which are new in .net 3.5 since the Visual Studio 2005 IDE does not support that!

Leave a Reply