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?
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。在包数据元结束时,您将看到
One can modify the metadata (press Ctrl-K) and remove the reference:
可以修改元数据(按Ctrl-K)并删除引用:
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源列表中添加新位置(本地目录)后(请参阅此处或此处),可以从本地源添加新包(不要忘记选择显示包含预发布的所有包,请参阅图片如下):
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:即使我的答案已经标记为已经解决并且奖励问题仍未解决问题。实际上,我看到两个未解决的问题:
System.Runtime
can produce the error during the builging of the project.为什么存在未使用的程序集System.Runtime会在项目构建期间产生错误。
我看到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:
让我们接受第一个问题独立存在的事实。第二个问题让我烦躁不安。我在这里看到了真正的问题。每个人都可以做以下实验来更好地了解我:
在Visual Studio 2012 RC中创建一个新的空控制台应用程序。
System.Runtime
.验证项目是否没有对System.Runtime的引用。
从“工具”/“库包管理器”中打开“包管理器控制台”。
在“程序包管理器控制台”中执行命令“Install-Package Microsoft.Tpl.Dataflow -Pre”。
System.Runtime
and System.Threading.Tasks.Dataflow
are included in the list of References of the project.验证System.Runtime和System.Threading.Tasks.Dataflow都包含在项目的引用列表中。
在“程序包管理器控制台”中执行命令“Uninstall-Package Microsoft.Tpl.Dataflow”。
System.Threading.Tasks.Dataflow
are removed from the list of References of the project, but System.Runtime
is still in the list of references.验证是否从项目的引用列表中删除了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下)。之后我可以在项目的更新列表中看到“新”版本:
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
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.
我可以确认删除引用实际上解决了问题。