【问题标题】:Visual Studio 2012 Website "Add References" not remember added referencesVisual Studio 2012 网站“添加引用”不记得添加的引用
【发布时间】:2014-08-07 16:21:52
【问题描述】:

我们最近将解决方案更新为 .NET 4.5。

我正在尝试使用以前在 System.Web.Security 中的“MembershipUser”类。根据我的阅读,它已移至 System.Web.ApplicationServices。我们的解决方案有许多 C# 项目和 2 个网站。所以我右键单击有问题的网站,转到“添加引用”,转到程序集 > 框架,然后单击 System.Web.ApplicationServices 旁边的复选框。它将以下行添加到我的 Web.Config:

<add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

好的,太好了。然后我转到我需要在其中使用 MembershipUser 的页面,而 MembershipUser 仍然出错(找不到类型或命名空间)。所以我再次右键单击该站点以确保我已正确添加引用,并且 System.Web.ApplicationServices 旁边没有检查。

所以它在 Web.Config 中,我可以在 Using 语句中调用它,但我无法注册 MembershipUser 类。

我在尝试添加此参考时是否遗漏了什么?

【问题讨论】:

  • It adds the following line to my Web.Config: 我想你忘记了那行。 :)
  • 我在 the documentation 的命名空间中看不到 MembershipUser
  • @Jashaszun 谢谢你,当我走出办公室时,我意识到这一点。
  • @mason 你是对的,该页面没有列出它。但是离开这个参考link 说 MembershipUser 已经从 System.Web 移动到 System.Web.ApplicationServices。
  • @mason - 它不在 System.Web.ApplicationServices 命名空间中,它在 System.Web.ApplicationServices 程序集中,仍在 System.Web.Security 命名空间中,只是在不同的程序集中。

标签: c# asp.net visual-studio-2012 asp.net-4.5


【解决方案1】:

好的,所以我想我明白了。部分问题出在我们的 Web.config 中。

我将 c# 和 vb 的 CompilerVersions 更改为 4.0:

<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="v4.0"/>
        <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="v4.0"/>
        <providerOption name="OptionInfer" value="true"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>

另外,我们的编译目标框架没有指定 4.0。

<compilation debug="true" batch="false" batchTimeout="7200" targetFramework="4.0">

现在构建网站后,MembershipUser 现在会按我的预期显示。呵呵。

此外,System.Web.ApplicationServices 现在已在“添加引用”对话框中选中。

从 2.0 升级到 4.5 的过程并不顺利。

【讨论】:

  • 为什么要在 web.config 中指定 codedom?那应该是完全没有必要的。您可能需要 targetFramework 4.5 和 C#5
猜你喜欢
  • 2015-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多