『天道酬勤』


宠辱不惊,看庭前花开花落.去留无意,望天外云卷云舒.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[原][译]Using VS 2008 to target ASP.NET AJAX 1.0

Posted on 2007-11-03 08:36  咣咣咣  阅读(924)  评论(0编辑  收藏  举报

原文地址:http://blogs.msdn.com/webdevtools/archive/2007/07/30/using-vs-2008-to-target-asp-net-ajax-1-0.aspx

在以前,按我描述的步骤你可以升级你已有的基于 ASP.NET AJAX 1.0 的网站到 AJAX .NET Framework 3.5.然而,你可能仍需要继续已有的 AJAX 1.0 开发,甚至是创建一个新的 AJAX 1.0 网站.幸运的是,Visual Studio 2008支持多定向,允许你这么干.使用 Visual Studio 2008 你仍然可以继续做 .NET Framework 2.0 (和 AJAX 1.0) 程序和网站.这样你就可以应用 vs 2008 的新行性:所见即所得设计界面,CSS设计器,JS智能提示和JS调试来进行开发.如果你决定在以后使用 AJAX 3.5,下面的步骤你能在 VS 2008 中使用已有的 ASP.NET AJAX 1.0 或创建一个新的 ASP.NET AJAX 1.0 应用.你能很简单的跟着这些起步骤来做.

先决条件:

 

  • 1.下载并安装 Microsoft Visual Studio 2008 Beta 2
  • 2.安完以后,你要执行这个 脚本 来确保你安装 .NET Framework 3.5 Beta 2 不影响 ASP.NET AJAX 1.0 应用.你要在安装完 VS 2008 Beta2 以后马上做这 步.
  • 3.下载并安装 ASP.NET AJAX 1.0.
  • 4.Apply the following workaround to fix a known issue with Visual Studio’s Multitargeting support for AJAX 1.0. Note that this workaround will *not* be required for the VS 2008 RTM release:

 

为 AJAX 1.0 构建支持 VS 2008 Beta 2 多定向的工作区

 

1. 在系统里找到这个文件夹:
\Program Files\Reference Assemblies\Microsoft\Framework\v3.5

2. 在这里创建一个文件夹,名为“Backup”

3. 做一个备份,把下面这两个文件复制到新的“Backup”文件夹,然后在\Program Files\Reference Assemblies\Microsoft\Framework\v3.5
 删除这两个文件.

 

System.Web.Extensions.dll

System.Web.Extensions.Design.dll

注意: 这个工作区会有对 VS 2008 的 Web Application Projects 有下面这两个副作用.

Creating a new 3.5 Web Application Project has a "broken" reference to System.Web.Extensions 0.0.0.0 in the client references list (Project Properties > References). If you build the project, you will encounter this error: The referenced assembly "D:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll" was not found. If this assembly is produced by another one of your projects, please make sure to build that project before building this one. In order to correct this, you need to manually remove this reference, then Browse... to the location of the System.Web.Extensions 3.5 backup you made in step 3 above to add the reference back to the project.

 

When upgrading a Web Application Project that uses AJAX 1.0 to .NET Framework 3.5, VS doesn't remove the reference to System.Web.Extensions 1.0.6 in the client references list (Project Properties > References). You need to manually remove this reference and then Browse... to the location of the System.Web.Extensions 3.5 backup you made in step 3 above to add the reference back to the project.

 

第一步: 在 VS 2008 创建或打开你的 AJAX 1.0 网站或WEB应用程序

 

在 VS 2008 创建或打开你的 AJAX 1.0 网站或WEB应用程序:

 

如果你想要创建一个新的 AJAX 1.0 网站或WEB应用程序,跟着下面这些步骤:

 

  • 1.在菜单里,选"新网站"->“ASP.NET 网站”
    • a.创建WEB应用程序选"新项目"->“ASP.NET Web 应用程序”
  • 2.在这个对话框的右上角,选择 Framework 的版本为 2.0

 

New Website Dialog 2.0

 

    • a.注意在 Visual Web Developer Express 中,这里没有下拉列表供选择.Instead you must create the project first and then downgrade the Target Framework to 2.o in the Website Property Pages dialog (under the Build tab).注:没用过 Web Developer Express 不会翻译.

 

  • 2.复制ASP.NET AJAX 1.0 Web.config 到你项目的根文件夹
  • 3.在下面的每二步和第三步中添加 AJAX 1.0 控件到工具箱中

 

对已有的 AJAX 1.0 网站 or Web 应用程序:

 

如果你对已有的构建于 VS 2005 的 ASP.NET AJAX 1.0 网站或 Web 应用程序项目在 Visual Studio 2008 中继续工作,做下面这些:

 

  • 1. 首先,把你的项目备份一下,然后打开 Microsoft Visual Studio 2008 Beta 2.
  • 2. 在文件菜单里,选择"打开网站…" 来打开你的网站文件或IIS的虚拟目录.
    • a. 如果你打开 Web 应用程序, 选择 “打开项目…”,通过项目文件打开它.跟着 Visual Studio 转换向导转成 VS 2008 格式.
  • 3. 现在 Visual Studio 2008 提示升级网站或 WEB 应用程序, 选择 “否” 保持目标是 .Net Framework 2.0.

 

Framework Version Prompt (No)

 

第二步: 在 VS 2008 工具箱中安装 ASP.NET AJAX 1.0 控件

 

默认情况下, Visual Studio 2008 不能在工具箱中显示 ASP.NET AJAX 1.0 控件在 .NET Framework 2.0 中(这是因为 AJAX 1.0 在 VS 2008 中是分开下载的, 并且 AJAX 1.0 安装包只能添加模版/控件给 VS 2005).为了在 VS 2008 中建造可用的 AJAX 1.0 控件,你需要在工具箱的面版上使用以下步骤:

 

  • 1. 在项目中打开 Web 窗体文件 (.aspx 文件)
  • 2. 右键点工具箱并选择"添加选项卡"
  • 3. 起一个名, 例如 “AJAX Extensions 1.0”
  • 4. 在新选项卡的下面右键选择 “选择项…”

 

Toolbox Choose Items AJAX 1.0

 

  • 5. 在选择工具箱对话框, 点"浏览"按钮
  • 6. 选择目录: \Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025, 找到 System.Web.Extensions.dll, 点"打开"按钮

 

Toolbox Choose Items Dialog Browse AJAX 1.0

 

  • 7. 你应该能看到工具箱对话框中被选中的控件. 点"确定"添加到工具箱中.

 

Toolbox Choose Items Dialog AJAX 1.0

 

在确定这个对话框以后, ASP.NET AJAX 1.0 控件就会出现在你的工具箱中. 当你把鼠标悬停在控件上面的时候,你可以看到控件版本是 1.0.61025.0.

 

 

重要提示: 这些控件也将会显示在 .NET Framework 3.5 的项目录, 不要用这些控件构建 .NET Framework 3.5 的应用(用应该用 AJAX Extensions ..NET Framework 3.5).

 

Toolbox AJAX 1.0 Tooltip


第三步(可选): 下载并给 VS 2008 安装 ASP.NET AJAX Toolkit Controls

 

如果你应用到 ASP.NET AJAX Control Toolkit,你需要类似的步骤在 VS 2008 上安装 ASP.NET AJAX Toolkit controls. 如果你已经下载了 ASP.NET AJAX Toolkit controls ,你可以跳到第4步.

 

  • 1. 点这个链接: ASP.NET AJAX Toolkit Release page
  • 2. 下载最后一个版本的 .NET Framework version 2.0 ASP.NET AJAX Toolkit controls (选第一个):
    • a. AjaxControlToolkit-NoSource.zip
    • b. AjaxControlToolkit.zip(含源码)
  • 3. 解压到同名文件夹中
  • 4. 在 Visual Studio 2008 中,打开 WEB 窗体 (.aspx 文件)
  • 5. 右键在工具箱中点 “添加选项卡”
  • 6. 起个名,如 “AJAX Toolkit 1.0”
  • 7. 在新选项卡的下面右键选择 “选择项…”
  • 8. 在选择工具箱对话框, 点"浏览"按钮
  • 9. 选择目录: \AjaxControlToolkit\SampleWebSite\Bin, 找到 AjaxControlToolkit.dll, 点"打开"按钮
  • 10. 在确定这个对话框以后, ASP.NET AJAX 1.0 控件就会出现在你的工具箱中.

 

重要提示: 这些控件也将会显示在 .NET Framework 3.5 的项目录, 不要用这些控件构建 .NET Framework 3.5 的应用(用应该用 AJAX Extensions ..NET Framework 3.5).

结论

现在你能在 Visual Studio 2008 中构建 .NET Framework 2.0 + AJAX 1.0 Web 应用程序 . When you close and re-open your project in Visual Studio, you will not be prompted to upgrade it again, although you can upgrade to .NET Framework 3.5 at any time by following these steps. Additionally, there are many great new features of Visual Studio 2008 Beta 2 that you can use to develop your AJAX 1.0 application (see the links at the top of this post), although there are few caveats about developing AJAX 1.0 applications in Visual Studio 2008 that are worth calling out:

 

  • · The AJAX item templates such as “AJAX Web Form” and “AJAX Master Page” not available in the Add New Item dialog of a .NET Framework 2.0 application. You can instead add a regular Web Form or Master Page template, and add the <asp:ScriptManager> control from the toolbox.
  • · JScript Intellisense always displays members from the AJAX 3.5 scripts. Although these scripts are backward-compatible with AJAX 1.0, Jscript Intellisense may display members that are unavailable in AJAX 1.0. To get AJAX 1.0-based Intellisense, you can copy the entire System.Web.Extensions folder from the AJAX 1.0 installation directory (typically under \Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\MicrosoftAjaxLibrary) and then add an explicit script reference to the 1.0 MicrosoftAjax.js script on the <asp:ScriptManager/> in your page:

 

<asp:ScriptManager ID="ScriptManager1" runat="server">

<Scripts>

<asp:ScriptReference Name="MicrosoftAjax.js"
Path="~/System.Web.Extensions/1.0.61025.0/MicrosoftAjax.js" />

</Scripts>

</asp:ScriptManager>

 

  • · Jscript Intellisense against Web Services (registered in ScriptManager) or the ProfileService (enabled in Web.config) is unavailable in an AJAX 1.0 application.
  • · Extender controls from the AJAX 1.0 Control Toolkit or other AJAX 1.0-based 3rd-party control libraries will not get the VS 2008 Extender design-time enhancements (i.e. the “Choose Extender…” smart task in Design View).
  • · You will not get intellisense for references to scripts inside third-party assemblies.