VS 2012 RC 中引用 TPL 数据流和 TPL 的问题

Problems with references to TPL Dataflow and TPL in VS 2012 RC(VS 2012 RC 中引用 TPL 数据流和 TPL 的问题)
本文介绍了VS 2012 RC 中引用 TPL 数据流和 TPL 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将 Visual Studio 11 Beta 升级到新的 Visual Studio 2012 RC,但在引用 TPL 数据流时遇到了问题.

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

<块引用>

无法添加对System.Threading.Tasks.Dataflow"的引用.

然后整个 Visual Studio 冻结.

看完 或 以便包固定.

已更新 2:即使我的答案已被标记为已解决,并且授予问题的赏金仍然没有从我的脑海中消失.实际上,我看到了两个未解决的问题:

  1. 为什么存在未使用的程序集System.Runtime会在项目构建过程中产生错误.
  2. 我发现卸载或更新 NuGet 包的工作方式存在一些一般性问题(请参阅后面的详细信息).

让我们接受这样一个事实,即第一个问题独立于原因而存在.第二个问题让我坐立不安.我在这里看到了真正的问题.大家可以做以下实验来更好地理解我:

  1. 在 Visual Studio 2012 RC 中创建一个新的空控制台应用程序.
  2. 确认项目没有引用 System.Runtime.
  3. 从工具"/库包管理器"打开包管理器控制台".
  4. 在包管理器控制台"中执行命令Install-Package Microsoft.Tpl.Dataflow -Pre".
  5. 验证 System.RuntimeSystem.Threading.Tasks.Dataflow 是否都包含在项目的引用列表中.
  6. 在包管理器控制台"中执行命令Uninstall-Package Microsoft.Tpl.Dataflow".
  7. 确认 System.Threading.Tasks.Dataflow 已从项目的 References 列表中删除,System.Runtime 仍在列表中参考文献.

我又做了一个实验,修改了Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg的版本,去掉了对System.Runtime的引用code>,从4.5.1-rc4.5.1-rc1并保存在本地(会保存在Microsoft.Tpl.Dataflow.4.5.1-rc1.nupkg).之后,我可以在我的项目更新列表中看到新"版本:

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

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

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

我发布到 NuGet 的错误报告可以在 here 找到(对不起,不完美文本格式).

I just upgraded Visual Studio 11 Beta to the new Visual Studio 2012 RC and have problems referencing 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:

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

and then the whole Visual Studio freezes.

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:

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'.

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:

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

and then Visual Studio froze again.

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

解决方案

Try to "Add Reference" the System.Threading.Tasks.dll explicitly from C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5. Alternatively you can use C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5Facades directory.

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.

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

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

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):

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

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".

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

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:

  1. Why the existence of unused assembly System.Runtime can produce the error during the builging of the project.
  2. I see some general problems in the way how Uninstall or Update of NuGet packages works (see details later).

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. Verify that the project has no reference to System.Runtime.
  3. Open "Package Manager Console" from "Tools" / "Library Package Manager".
  4. Execute the command "Install-Package Microsoft.Tpl.Dataflow -Pre" in the "Package Manager Console".
  5. Verify that both System.Runtime and System.Threading.Tasks.Dataflow are included in the list of References of the project.
  6. Execute the command "Uninstall-Package Microsoft.Tpl.Dataflow" in the "Package Manager Console".
  7. 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.

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:

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

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.

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.

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

这篇关于VS 2012 RC 中引用 TPL 数据流和 TPL 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)