找到你要的答案

Q:How to add a reference to System.Data.DataSetExtensions to a Web Site ascx.cs file? Short Answer Explanation

Q:如何添加一个参考system.data.datasetextensions到网站ascx.cs文件吗? 简短的回答 解释

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.)

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"
  3. Add the following to the web.config based on the Public key token.

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

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

我们与一个网站项目并试图借鉴system.data.datasetextensions工作。(使用Web应用程序会更好,但技术领先,有她的理由。)

这是我们尝试过的:

  1. Find the assembly path.
  2. Open a Visual Studio Command Prompt and run sn.exe -T "full\path.dll"
  3. Add the following to the web.config based on the Public key token.

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)参考组件\微软\结构\ \ \ system.data.datasetextensions.dll。NET Framework V4.0

尽管如此,MSBuild还抱怨当我们添加到代码隐藏文件中使用system.data.datasetextensions。怎么了?我们如何解决这个问题?

answer1: 回答1:

Short Answer

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

  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.

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

Explanation

Rick Strahl explains that by default ASP.NET includes:

  • all assemblies in the bin path
  • any GAC-based assembly references in the web.config <compilation> section

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

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.

简短的回答

问题是我们的使用声明。所以,有两个要求。

  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.

问题是,我们使用的是system.data.datasetextensions声明。

解释

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

  • all assemblies in the bin path
  • any GAC-based assembly references in the web.config <compilation> section

进一步,我们可以查询到GAC从Visual Studio命令提示如下:

> 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文件参考。

c#  .net  msbuild