本文介绍了如何在网站ascx.cs文件中添加对System.Data.DataSetExtensions的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在处理一个Web站点项目,并尝试引用System.Data.DataSetExtensions. (使用Web应用程序会更好;但是,技术主管有其原因.)

We're working with a Web Site project and trying to reference System.Data.DataSetExtensions. (Using a Web Application would be better; the technical lead, though, has her reasons.)

这是我们尝试过的:

  1. 找到组装路径.
  2. 打开Visual Studio命令提示符并运行sn.exe -T "full\path.dll"
  3. 基于公钥令牌将以下内容添加到web.config.

web.config> system.web>

web.config > system.web >

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <!-- Other assemblied omitted -->
    <add assembly="System.Data.DataSetExtensions, 
        Version=4.0.0.0, 
        Culture=neutral, 
        PublicKeyToken=B77A5C561934E089" />
  </assemblies>
</compilation>

完整路径为C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll

尽管如此,当我们在文件后面的代码中添加using System.Data.DataSetExtensions时,msbuild仍然会抱怨.是什么赋予了?我们该如何解决呢?

Despite this, msbuild still complains when we add using System.Data.DataSetExtensions to a code behind file. What gives? How do we solve this?

推荐答案

简短回答

问题在于我们的using语句.因此,有两个要求.

Short Answer

The problem was our using statement. So, there were two requirements.

    web.config文件中的
  1. 参考System.Data.DataSetExtensions. (有关查找完整程序集名称的信息,请参见下文.)
  2. 在C#文件中为System.Data添加using语句.
  1. Reference System.Data.DataSetExtensions in the web.config file. (See below for finding the full assembly name.)
  2. Add a using statement for System.Data in the C# file.

问题是我们的using语句用于System.Data.DataSetExtensions.

The problem was that our using statement was for System.Data.DataSetExtensions.

Rick Strahl解释,默认情况下,ASP.NET包括:

Rick Strahl explains that by default ASP.NET includes:

  • bin路径中的所有程序集
  • web.config <compilation>部分中的所有基于GAC的程序集引用
  • all assemblies in the bin path
  • any GAC-based assembly references in the web.config <compilation> section

此外,我们能够从Visual Studio命令提示符查询GAC,如下所示:

Further, we were able to query to GAC from a Visual Studio Command Prompt as follows:

> gacutil /l System.Data.DataSetExtensions

Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.17929
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
  System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL

Number of items = 2

这确认我们想要的程序集在GAC中.它还在web.config文件中列出了需要引用的程序集的全名.

This confirmed that the assembly we wanted was in the GAC. It also listed the full name of the assembly that we needed to reference in the web.config file.

这篇关于如何在网站ascx.cs文件中添加对System.Data.DataSetExtensions的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 11:49