简体   繁体   中英

Visual Studio 2012 Website “Add References” not remember added references

We've recently updated our solution to .NET 4.5.

I'm attempting to use the "MembershipUser" class which used to be in System.Web.Security. From what I've read, it's moved to System.Web.ApplicationServices. Our solution has many C# projects and 2 websites. So I right click on the website in question, go to "Add Reference", go to Assemblies > Framework and then click the checkbox next to System.Web.ApplicationServices. It adds the following line to my Web.Config:

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

OK, great. I then go to the page I need to use MembershipUser in, and MembershipUser still errors out (type or namespace not found). So I right click on the site again to ensure I've added the reference correctly, and there is no check next to System.Web.ApplicationServices.

So it's there in the Web.Config, and I can call it in a Using statement, but I can't get the MembershipUser class to register.

Have I missed something in attempting to add this reference?

OK, so I think I got this. Part of the problem was in our Web.config as it would seem.

I changed the CompilerVersions for c# and vb to 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>

Additionally, our compilation target framework was not specifying 4.0.

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

Upon building the site now, MembershipUser now shows up as I'd expect it to. Huzzah.

Also, the System.Web.ApplicationServices is now checked in the "Add References" dialogue.

This upgrade to 4.5 from 2.0 has not been going well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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