热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

VS2012RC中引用TPL数据流和TPL的问题-ProblemswithreferencestoTPLDataflowandTPLinVS2012RC

IjustupgradedVisualStudio11BetatothenewVisualStudio2012RCandhaveproblemsreferencing

I just upgraded Visual Studio 11 Beta to the new Visual Studio 2012 RC and have problems referencing TPL Dataflow.

我刚刚将Visual Studio 11 Beta升级到新的Visual Studio 2012 RC,并且在引用TPL Dataflow时遇到了问题。

First, I tried to reference Dataflow as I did previously, by adding a reference from the framework. But when I try to do that, I get an error box:

首先,我尝试通过添加框架中的引用,像之前一样引用Dataflow。但是当我尝试这样做时,我得到一个错误框:

A reference to 'System.Threading.Tasks.Dataflow' could not be added.

无法添加对“System.Threading.Tasks.Dataflow”的引用。

and then the whole Visual Studio freezes.

然后整个Visual Studio冻结。

After reading MEF and TPL Dataflow NuGet Packages for .NET Framework 4.5 RC, I assumed the version of Dataflow that showed in the references list was some kind of artifact of the previous installation. So, I tried using Dataflow from NuGet, which seemed to work, until I actually tried to compile my code, because I got an error:

在阅读了用于.NET Framework 4.5 RC的MEF和TPL Dataflow NuGet包之后,我假设在引用列表中显示的Dataflow版本是先前安装的某种工件。所以,我尝试使用NuGet的Dataflow,这似乎有效,直到我真的尝试编译我的代码,因为我收到了一个错误:

The type 'System.Threading.Tasks.Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

类型'System.Threading.Tasks.Task'在未引用的程序集中定义。您必须添加对程序集'System.Threading.Tasks,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用。

This is confusing, because Task is in mscorlib, no other references should be necessary. But there is a reference assembly called System.Threading.Tasks in the references list, so I tried to add that. Unfortunately, a familiar error showed:

这很令人困惑,因为Task在mscorlib中,不需要其他引用。但是在引用列表中有一个名为System.Threading.Tasks的引用程序集,所以我尝试添加它。不幸的是,一个熟悉的错误表明

A reference to 'System.Threading.Tasks' could not be added.

无法添加对“System.Threading.Tasks”的引用。

and then Visual Studio froze again.

然后Visual Studio再次冻结。

Am I doing something wrong? How can I use TPL Dataflow with VS 2012 RC?

难道我做错了什么?如何在VS 2012 RC中使用TPL Dataflow?

2 个解决方案

#1


24  

Try to "Add Reference" the System.Threading.Tasks.dll explicitly from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5. Alternatively you can use C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades directory.

尝试从C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ .NETCore \ v4.5中显式“添加引用”System.Threading.Tasks.dll。或者,您可以使用C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.5 \ Facades目录。

UPDATED: I examined the problem more after reading of the answer about removing the reference to System.Runtime and I can add the following: The reference to System.Runtime will be added because of the error in the currect version of NuGet package Microsoft.Tpl.Dataflow.4.5.1-rc. If one add the reference to the same System.Threading.Tasks.Dataflow.dll directly in Visual Studio no System.Runtime reference will be added and no problem exist.

更新:我在阅读了关于删除对System.Runtime的引用的答案后更多地检查了问题,我可以添加以下内容:由于NuGet包的当前版本中的错误,Microsoft.Tpl将添加对System.Runtime的引用.Dataflow.4.5.1-RC。如果在Visual Studio中直接添加对同一System.Threading.Tasks.Dataflow.dll的引用,则不会添加System.Runtime引用,也不存在任何问题。

Using NuGet Package Explorer one can download the original Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg from the "NuGet official package source". At the end of the Package Matadata one will see

使用NuGet Package Explorer,可以从“NuGet官方软件包源”下载原始的Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg。在包数据元结束时,您将看到

enter image description here

One can modify the metadata (press Ctrl-K) and remove the reference:

可以修改元数据(按Ctrl-K)并删除引用:

enter image description here

After that one can save the modified file Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg in some directory. After adding new location (the local directory) in the list of NuGet sources (see here or here) one will be able to add new package from the local source (don't forget to choose to display all packages inclusive pre-release see the picture below):

之后,可以将修改后的文件Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg保存在某个目录中。在NuGet源列表中添加新位置(本地目录)后(请参阅此处或此处),可以从本地源添加新包(不要忘记选择显示包含预发布的所有包,请参阅图片如下):

enter image description here

The modified Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg will not add System.Runtime and the project will be compiled without errors.

修改后的Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg将不会添加System.Runtime,并且将编译项目而不会出现错误。

So the bug exist not in Visual Studio 2012 RC and even not in Microsoft.Tpl.Dataflow.dll. The bug is just in the metadata of the pre-release version of Microsoft.Tpl.Dataflow NuGet package available currently on "NuGet official package source".

因此,该错误不存在于Visual Studio 2012 RC中,甚至不存在于Microsoft.Tpl.Dataflow.dll中。该错误只是目前在“NuGet官方软件包源”上提供的Microsoft.Tpl.Dataflow NuGet软件包的预发行版本的元数据中。

You can post the bug report to the autors so that the package will be fixed.

您可以将错误报告发布到autors,以便修复包。

UPDATED 2: Even if my answer are already marked as solved and the bounty awarded the problem still not go from my head. In reality I see two opened problems:

更新2:即使我的答案已经标记为已经解决并且奖励问题仍未解决问题。实际上,我看到两个未解决的问题:

  1. Why the existence of unused assembly System.Runtime can produce the error during the builging of the project.
  2. 为什么存在未使用的程序集System.Runtime会在项目构建期间产生错误。

  3. I see some general problems in the way how Uninstall or Update of NuGet packages works (see details later).
  4. 我看到NuGet包的卸载或更新如何工作的一些常见问题(稍后详见)。

Let us we accept just the fact that the first problem exist independent from the reason. The second problem make me restlessness. I see the real problem here. Everybody can make the following experiment to understand me better:

让我们接受第一个问题独立存在的事实。第二个问题让我烦躁不安。我在这里看到了真正的问题。每个人都可以做以下实验来更好地了解我:

  1. Create a new empty console application in Visual Studio 2012 RC.
  2. 在Visual Studio 2012 RC中创建一个新的空控制台应用程序。

  3. Verify that the project has no reference to System.Runtime.
  4. 验证项目是否没有对System.Runtime的引用。

  5. Open "Package Manager Console" from "Tools" / "Library Package Manager".
  6. 从“工具”/“库包管理器”中打开“包管理器控制台”。

  7. Execute the command "Install-Package Microsoft.Tpl.Dataflow -Pre" in the "Package Manager Console".
  8. 在“程序包管理器控制台”中执行命令“Install-Package Microsoft.Tpl.Dataflow -Pre”。

  9. Verify that both System.Runtime and System.Threading.Tasks.Dataflow are included in the list of References of the project.
  10. 验证System.Runtime和System.Threading.Tasks.Dataflow都包含在项目的引用列表中。

  11. Execute the command "Uninstall-Package Microsoft.Tpl.Dataflow" in the "Package Manager Console".
  12. 在“程序包管理器控制台”中执行命令“Uninstall-Package Microsoft.Tpl.Dataflow”。

  13. Verify that System.Threading.Tasks.Dataflow are removed from the list of References of the project, but System.Runtime is still in the list of references.
  14. 验证是否从项目的引用列表中删除了System.Threading.Tasks.Dataflow,但System.Runtime仍在引用列表中。

I made one more experiment and I changed the version of modified Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg, where I removed the reference to System.Runtime, from 4.5.1-rc to 4.5.1-rc1 and saved it locally (it will be saved under Microsoft.Tpl.Dataflow.4.5.1-rc1.nupkg). After that I could see "new" version in the list of Updates to my project:

我又做了一个实验,我更改了修改后的Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg的版本,在那里我删除了对System.Runtime的引用,从4.5.1-rc到4.5.1-rc1并保存它本地(它将保存在Microsoft.Tpl.Dataflow.4.5.1-rc1.nupkg下)。之后我可以在项目的更新列表中看到“新”版本:

enter image description here

If I install the Update the reference to System.Runtime will be also not removed.

如果我安装更新,则也不会删除对System.Runtime的引用。

So the current implementation of "Update" and "Uninstall" of NuGet has the bug or general design problem. If we added a package to our project and make some updates of the project we will get references of all dependent assemblies of all old versions. The old references, added by NuGet from old versions of the package, will be not removed during Uninstall or Update. First of all it's not good itself to have garbage in the project references, but because of existence the first problem (error during compilation if the reference to unreferenced System.Runtime exist) the problem will be even more serious.

因此,NuGet的“更新”和“卸载”的当前实现具有错误或一般设计问题。如果我们在项目中添加了一个包并对项目进行了一些更新,我们将获得所有旧版本的所有依赖程序集的引用。 NuGet从旧版本的软件包添加的旧引用在卸载或更新期间不会被删除。首先,在项目引用中存在垃圾本身并不好,但由于存在第一个问题(如果存在对未引用的System.Runtime的引用,编译期间的错误)问题将更加严重。

So if nothing will be changed in NuGet the update to the next version of Microsoft.Tpl.Dataflow will not solve the problem for the users who installed Microsoft.Tpl.Dataflow in version 4.5.1 (or probably early version). All users will have to remove the reference to System.Runtime manually. I think that it's real NuGet problem which have to be solved by NuGet developers. I will post the description of the problem to http://nuget.org/ later.

因此,如果在NuGet中没有任何更改,则对下一版本的Microsoft.Tpl.Dataflow的更新将无法解决在4.5.1版(或可能是早期版本)中安装Microsoft.Tpl.Dataflow的用户的问题。所有用户都必须手动删除对System.Runtime的引用。我认为这是真正的NuGet问题,必须由NuGet开发人员解决。我稍后会将问题的描述发布到http://nuget.org/。

The bug report which I posted to NuGet can be found here (sorry for not perfect formatting of the text).

我发布到NuGet的错误报告可以在这里找到(抱歉没有完美的文本格式)。

#2


2  

According to Alok Shriram from MS, the solution is to remove the reference to System.Runtime, and that this will be fixed in the next release.

根据MS的Alok Shriram的说法,解决方案是删除对System.Runtime的引用,并且这将在下一个版本中修复。

I can confirm that removing the reference actually fixes the issue.

我可以确认删除引用实际上解决了问题。


推荐阅读
  • PatchODAX8: ... [详细]
  • 本文介绍了三种方法来实现在Win7系统中显示桌面的快捷方式,包括使用任务栏快速启动栏、运行命令和自己创建快捷方式的方法。具体操作步骤详细说明,并提供了保存图标的路径,方便以后使用。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • Windows7 64位系统安装PLSQL Developer的步骤和注意事项
    本文介绍了在Windows7 64位系统上安装PLSQL Developer的步骤和注意事项。首先下载并安装PLSQL Developer,注意不要安装在默认目录下。然后下载Windows 32位的oracle instant client,并解压到指定路径。最后,按照自己的喜好对解压后的文件进行命名和压缩。 ... [详细]
  • PG12新增的VACUUM命令的SKIP_LOCKED选项
    PG12版本的VACUUM命令新增了SKIP_LOCKED选项,该选项使得vacuum命令在遇到被lock住的table时可以跳过并被视为成功执行。之前的版本中,vacuum命令会一直处于等待状态。本文还提到了PostgreSQL 12.1版本的相关信息。 ... [详细]
  • Question该提问来源于开源项目:react-native-device-info/react-native-device-info ... [详细]
  • 三、查看Linux版本查看系统版本信息的命令:lsb_release-a[root@localhost~]#lsb_release-aLSBVersion::co ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • OCI连接MySQL_PLSQL Developer连接远程数据库OCI客户端安装方法
    本文介绍了使用OCI客户端连接MySQL和PLSQL Developer连接远程数据库的安装方法,避免了在本地安装Oracle数据库或类似的开发套件的麻烦,同时解决了PLSQL Dev连接远程Oracle时的配置问题。 ... [详细]
  • Python中sys模块的功能及用法详解
    本文详细介绍了Python中sys模块的功能及用法,包括对解释器参数和功能的访问、命令行参数列表、字节顺序指示符、编译模块名称等。同时还介绍了sys模块中的新功能和call_tracing函数的用法。推荐学习《Python教程》以深入了解。 ... [详细]
  • 在加载一个第三方厂商的dll文件时,提示“找不到指定模块,加载失败”。由于缺乏必要的技术支持,百思不得期间。后来发现一个有用的工具 ... [详细]
  • Mono为何能跨平台
    概念JIT编译(JITcompilation),运行时需要代码时,将Microsoft中间语言(MSIL)转换为机器码的编译。CLR(CommonLa ... [详细]
  • 以管理员身份打开命令行粘贴上面 ... [详细]
  • 线程漫谈——线程基础
    本系列意在记录Windwos线程的相关知识点,包括线程基础、线程调度、线程同步、TLS、线程池等。进程与线程理解线程是至关重要的,每个进程至少有一个线程,进程是线程的容器,线程才是真正的执行体,线程必 ... [详细]
author-avatar
被爱的善良的小鸽_212
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有