Problems with references to TPL Dataflow and TPL in VS 2012 RC(VS 2012 RC 中引用 TPL 数据流和 TPL 的问题)
问题描述
我刚刚将 Visual Studio 11 Beta 升级到新的 Visual Studio 2012 RC,但在引用 TPL 数据流时遇到了问题.
首先,我尝试像以前一样通过从框架中添加引用来引用 Dataflow.但是当我尝试这样做时,我得到一个错误框:
<块引用>无法添加对System.Threading.Tasks.Dataflow"的引用.
然后整个 Visual Studio 冻结.
看完 或 以便包固定.
已更新 2:即使我的答案已被标记为已解决,并且授予问题的赏金仍然没有从我的脑海中消失.实际上,我看到了两个未解决的问题:
- 为什么存在未使用的程序集
System.Runtime
会在项目构建过程中产生错误. - 我发现卸载或更新 NuGet 包的工作方式存在一些一般性问题(请参阅后面的详细信息).
让我们接受这样一个事实,即第一个问题独立于原因而存在.第二个问题让我坐立不安.我在这里看到了真正的问题.大家可以做以下实验来更好地理解我:
- 在 Visual Studio 2012 RC 中创建一个新的空控制台应用程序.
- 确认项目没有引用
System.Runtime
. - 从工具"/库包管理器"打开包管理器控制台".
- 在包管理器控制台"中执行命令Install-Package Microsoft.Tpl.Dataflow -Pre".
- 验证
System.Runtime
和System.Threading.Tasks.Dataflow
是否都包含在项目的引用列表中. - 在包管理器控制台"中执行命令Uninstall-Package Microsoft.Tpl.Dataflow".
- 确认
System.Threading.Tasks.Dataflow
已从项目的 References 列表中删除,但System.Runtime
仍在列表中参考文献.
我又做了一个实验,修改了Microsoft.Tpl.Dataflow.4.5.1-rc.nupkg
的版本,去掉了对System.Runtime
的引用code>,从4.5.1-rc
到4.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:
- Why the existence of unused assembly
System.Runtime
can produce the error during the builging of the project. - 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:
- Create a new empty console application in Visual Studio 2012 RC.
- Verify that the project has no reference to
System.Runtime
. - Open "Package Manager Console" from "Tools" / "Library Package Manager".
- Execute the command "Install-Package Microsoft.Tpl.Dataflow -Pre" in the "Package Manager Console".
- Verify that both
System.Runtime
andSystem.Threading.Tasks.Dataflow
are included in the list of References of the project. - Execute the command "Uninstall-Package Microsoft.Tpl.Dataflow" in the "Package Manager Console".
- Verify that
System.Threading.Tasks.Dataflow
are removed from the list of References of the project, butSystem.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 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:VS 2012 RC 中引用 TPL 数据流和 TPL 的问题
基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01