You must add a reference to assembly 'netstandard, Version=2.0.0.0

后端 未结 17 2432
遇见更好的自我
遇见更好的自我 2020-12-02 08:23

The project is an ASP.NET MVC Web App targeting the .NET Framework 4.6.1.

All of a sudden (some NuGet packages were upgraded) I started to get the following error du

相关标签:
17条回答
  • 2020-12-02 08:39

    Although this is an old thread, I had the same issue today, last week I updated some NuGet packages and although the MVC website worked OK on my dev machine when I published to the testing server it failed.

    I read numerous posts but none worked. I finally compared the DLL's in my local bin to those in the testing server and found that the netstandard.dll was not uploaded, once uploaded the website worked OK, not sure why VS2017 web deploy did not publish the DLL.

    Just something to look out for in case none of the above work for you.

    0 讨论(0)
  • 2020-12-02 08:40

    Deleting Bin and Obj folders worked for me.

    0 讨论(0)
  • 2020-12-02 08:43

    After upgrading from 4.6.1 framework to 4.7.2 we started getting this error:

    "The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ffffd51'." and ultimately the solution was to add the "netstandard" assembly reference mentioned above:

    <compilation debug="true" targetFramework="4.7.1" >
        <assemblies>
          <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, 
                PublicKeyToken=cc7b13ffcd2ffffd51"/>
        </assemblies>
      </compilation>
    
    0 讨论(0)
  • 2020-12-02 08:45

    Manually editing the .csproj file and adding the reference below worked for me.

    <Reference Include="netstandard" />
    

    Thank you to Fahad Alshaya who suggested it here.

    0 讨论(0)
  • 2020-12-02 08:46

    Those who are not having web.config file. Output Type other than web application. update the project file (.csproj) with below give code.

    It may cause due to adding/removing the .netframework in improper way or it may broke unexpected way.

      <ItemGroup>
        <Reference Include="netstandard" />
      </ItemGroup>
    

    Output Type

    • Console application
    • Class Library
    0 讨论(0)
  • 2020-12-02 08:50

    I think the solution might be this issue on GitHub:

    Try add netstandard reference in web.config like this:"

    <system.web>
      <compilation debug="true" targetFramework="4.7.1" >
        <assemblies>
          <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, 
                PublicKeyToken=cc7b13ffcd2ffffd51"/>
        </assemblies>
      </compilation>
      <httpRuntime targetFramework="4.7.1" />
    

    I realise you're using 4.6.1 but the choice of .NET 4.7.1 is significant as older Framework versions are not fully compatible with .NET Standard 2.0.

    I know this from painful experience, when I introduced .NET Standard libraries I had a lot of issues with NUGET packages and references breaking. The other change you need to consider is upgrading to PackageReferences instead of package.config files.

    See this guide and you might also want a tool to help the upgrade. It does require a late VS 15.7 version though.

    0 讨论(0)
提交回复
热议问题