本文介绍了类型“对象"在未引用的程序集中定义(NET Standard 2.0/.NET Framework 4.6.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

不幸的是,迁移到 .NET Framework 导致所有 .NET Framework 控制台项目出现以下错误:

错误 CS0012 在未引用的程序集中定义了类型对象".您必须添加对程序集netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"的引用.

其中 Object 可以是任何东西:Enum, Task, ...

如何使用 .NET Framework (4.6.1) 引用 .NET Standard 2.0 类库而不会出现此类错误?

解决方案

尝试在 web.config 中添加对 netstandard 的引用,如下所示:

<编译调试="true" targetFramework="4.7.1"><组件><add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/></组件></编译></system.web>

I'm using the .NET Standard 2.0 preview, on which my Class Libraries are based.

After having trouble with a few NuGet packages, especially regarding archive extraction, I decided to migrate my .NET Core 2.0 Console projects back to the .NET Framework 4.6.1.

The .NET Framework 4.6.1 is supposed to implement the .NET Standard 2.0 specification - according to different sources. Especially the dotnet/standard GitHub Repo.

Unfortunately, the migration to the .NET Framework resulted in the following errrors throughout all of .NET Framework Console projects:

Where Object can be anything: Enum, Task, ...

How would I reference .NET Standard 2.0 class libraries with .NET Framework (4.6.1) without getting such errors?

解决方案

Try to add a reference to netstandard in web.config as below:

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

这篇关于类型“对象"在未引用的程序集中定义(NET Standard 2.0/.NET Framework 4.6.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:55