简体   繁体   English

如何将System.Data.DataSetExtensions的引用添加到Web站点ascx.cs文件?

[英]How to add a reference to System.Data.DataSetExtensions to a Web Site ascx.cs file?

We're working with a Web Site project and trying to reference System.Data.DataSetExtensions . 我们正在使用Web站点项目并尝试引用System.Data.DataSetExtensions (Using a Web Application would be better; the technical lead, though, has her reasons.) (使用Web应用程序会更好;但技术主管有她的理由。)

Here is what we have tried: 这是我们尝试过的:

  1. Find the assembly path. 找到装配路径。
  2. Open a Visual Studio Command Prompt and run sn.exe -T "full\\path.dll" 打开Visual Studio命令提示符并运行sn.exe -T "full\\path.dll"
  3. Add the following to the web.config based on the Public key token. 根据公钥标记将以下内容添加到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>

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

Despite this, msbuild still complains when we add using System.Data.DataSetExtensions to a code behind file. 尽管如此,当我们将using System.Data.DataSetExtensions添加到代码隐藏文件时,msbuild仍然会抱怨。 What gives? 是什么赋予了? How do we solve this? 我们如何解决这个问题?

Short Answer 简答

The problem was our using statement. 问题是我们的using声明。 So, there were two requirements. 所以,有两个要求。

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

The problem was that our using statement was for System.Data.DataSetExtensions . 问题是我们的using语句用于System.Data.DataSetExtensions

Explanation 说明

Rick Strahl explains that by default ASP.NET includes: Rick Strahl解释说默认情况下ASP.NET包括:

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

Further, we were able to query to GAC from a Visual Studio Command Prompt as follows: 此外,我们能够从Visual Studio命令提示符查询GAC,如下所示:

> 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

This confirmed that the assembly we wanted was in the GAC. 这证实了我们想要的程序集在GAC中。 It also listed the full name of the assembly that we needed to reference in the web.config file. 它还列出了我们需要在web.config文件中引用的程序集的全名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM