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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{
var _tempVar = 4;
Response.Write(“Values of temp var: “ + _tempVar.ToString());
}
}

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.

1
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
xml version=“1.0“?>
< configuration >
< configSections >
< sectionGroup name=“system.web.extensions“ type=“System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “>
< sectionGroup name=“scripting“ type=“System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “>
< section name=“scriptResourceHandler“ type=“System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “ requirePermission=“false“ allowDefinition=“MachineToApplication“/>
< sectionGroup name=“webServices“ type=“System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “>
< section name=“jsonSerialization“ type=“System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “ requirePermission=“false“ allowDefinition=“Everywhere“/>
< section name=“profileService“ type=“System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “ requirePermission=“false“ allowDefinition=“MachineToApplication“/>
< section name=“authenticationService“ type=“System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “ requirePermission=“false“ allowDefinition=“MachineToApplication“/>
< section name=“roleService“ type=“System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “ requirePermission=“false“ allowDefinition=“MachineToApplication“/>
sectionGroup >
sectionGroup >
sectionGroup >
configSections >
< appSettings />
< connectionStrings />
< system.web >
< compilation debug=“false“ strict=“false“ explicit=“true“>
< assemblies >
< add assembly=“System.Core, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = B77A5C561934E089 “/>
< add assembly=“System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “/>
< add assembly=“System.Xml.Linq, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = B77A5C561934E089 “/>
< add assembly=“System.Data.DataSetExtensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = B77A5C561934E089 “/>
assemblies >
compilation >
< pages >
< namespaces >
< clear />
< add namespace=“System“/>
< add namespace=“System.Collections“/>
< add namespace=“System.Collections.Generic“/>
< add namespace=“System.Collections.Specialized“/>
< add namespace=“System.Configuration“/>
< add namespace=“System.Text“/>
< add namespace=“System.Text.RegularExpressions“/>
< add namespace=“System.Linq“/>
< add namespace=“System.Xml.Linq“/>
< add namespace=“System.Web“/>
< add namespace=“System.Web.Caching“/>
< add namespace=“System.Web.SessionState“/>
< add namespace=“System.Web.Security“/>
< add namespace=“System.Web.Profile“/>
< add namespace=“System.Web.UI“/>
< add namespace=“System.Web.UI.WebControls“/>
< add namespace=“System.Web.UI.WebControls.WebParts“/>
< add namespace=“System.Web.UI.HtmlControls“/>
namespaces >
< controls >
< add tagPrefix=“asp“ namespace=“System.Web.UI“ assembly=“System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “/>
< add tagPrefix=“asp“ namespace=“System.Web.UI.WebControls“ assembly=“System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “/>
controls >
pages >
< authentication mode=“Windows“/>
< httpHandlers >
< remove verb=“*“ path=“*.asmx“/>
< add verb=“*“ path=“*.asmx“ validate=“false“ type=“System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “/>
< 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 “/>
< 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 “/>
httpHandlers >
< httpModules >
< add name=“ScriptModule“ type=“System.Web.Handlers.ScriptModule, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “/>
httpModules >
system.web >
< system.codedom >
< compilers >
< compiler language=“c#;cs;csharp“ extension=“.cs“ type=“Microsoft.CSharp.CSharpCodeProvider,System, Version = 2 .0.0.0, Culture = neutral , PublicKeyToken = b77a5c561934e089 “ warningLevel=“4“>
< providerOption name=“CompilerVersion“ value=“v3.5“/>
< providerOption name=“WarnAsError“ value=“false“/>
compiler >
< compiler language=“vb;vbs;visualbasic;vbscript“ extension=“.vb“ type=“Microsoft.VisualBasic.VBCodeProvider, System, Version = 2 .0.0.0, Culture = neutral , PublicKeyToken = b77a5c561934e089 “ warningLevel=“4“>
< providerOption name=“CompilerVersion“ value=“v3.5“/>
< providerOption name=“OptionInfer“ value=“true“/>
< providerOption name=“WarnAsError“ value=“false“/>
compiler >
compilers >
system.codedom >
< system.webServer >
< validation validateIntegratedModeConfiguration=“false“/>
< modules >
< remove name=“ScriptModule“/>
< add name=“ScriptModule“ preCondition=“managedHandler“ type=“System.Web.Handlers.ScriptModule, System.Web.Extensions, Version = 3 .5.0.0, Culture = neutral , PublicKeyToken = 31BF3856AD364E35 “/>
modules >
< handlers >
< remove name=“WebServiceHandlerFactory-Integrated“/>
< remove name=“ScriptHandlerFactory“/>
< remove name=“ScriptHandlerFactoryAppServices“/>
< remove name=“ScriptResource“/>
< 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 “/>
< 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 “/>
< 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 “/>
handlers >
system.webServer >
< runtime >
< assemblyBinding xmlns=“urn:schemas-microsoft-com:asm.v1“>
< dependentAssembly >
< assemblyIdentity name=“System.Web.Extensions“ publicKeyToken=“31bf3856ad364e35“/>
< bindingRedirect oldVersion=“1.0.0.0-1.1.0.0“ newVersion=“3.5.0.0“/>
dependentAssembly >
< dependentAssembly >
< assemblyIdentity name=“System.Web.Extensions.Design“ publicKeyToken=“31bf3856ad364e35“/>
< bindingRedirect oldVersion=“1.0.0.0-1.1.0.0“ newVersion=“3.5.0.0“/>
dependentAssembly >
assemblyBinding >
runtime >
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!

原文地址:http://avinashsing.sunkur.com/2008/04/14/using-visual-studio-2005-with-dotnet-framework-35/