' ValueTuple< T1,T2& gt;#39;在' System.ValueTuple ...'中都存在和' mscorlib ...' [英] 'ValueTuple<T1, T2>' exists in both 'System.ValueTuple ...' and 'mscorlib ...'

查看:94
本文介绍了' ValueTuple< T1,T2& gt;#39;在' System.ValueTuple ...'中都存在和' mscorlib ...'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

B"H

我正在尝试使用C#7的新元组功能,并且遇到了一些问题.实际上,他们工作得很好,我不确定是什么改变使它们破裂.

I am trying to use the new Tuple features of C# 7, and running into a little bit of an issue. Actually, they were working fine, and I am not sure what changed to make them break.

我正在使用 ASP.Net 4 MVC 5 ,目标是 .net框架4.6.1

I am working with an ASP.Net 4, MVC 5, targeting .net framework 4.6.1

因此,为了使用元组,我必须使用Nuget包'System.ValueTuple'.没有它,该项目将无法编译.它工作了一段时间.今天,当我加载任何使用元组的页面时,我得到了

So in order to use tuples I had to a the Nuget Package 'System.ValueTuple'. Without it, the project won't compile. It worked fine for a while. Then today when I load any page that uses Tuples I get

编译器错误消息:CS0433:类型'ValueTuple'同时存在于'System.ValueTuple,版本= 4.0.2.0,区域性=中性,PublicKeyToken = cc7b13ffcd2ddd51'和'mscorlib,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089'

Compiler Error Message: CS0433: The type 'ValueTuple' exists in both 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

该项目可以正常编译,如果我删除了 System.ValueTuple ,则它不会编译.但是当我在网页上运行它时,会出现此错误.

The project compiles fine, and if I remove System.ValueTuple then it doesn't compile. But when I run it in a web page I get this error.

我在Google上的搜索建议将 ValueTuple 添加到 .net 4.7 中,但是我在项目的任何地方都没有引用4.7,并且我没有针对4.7进行编译.我的VS 2017甚至没有该选项.

My searches on google suggest that ValueTuple was added to .net 4.7 but I have no reference to 4.7 anywhere in my project and I am not compiling against 4.7. My VS 2017 doesn't even have that option.

谢谢

推荐答案

ASP.NET网页在运行时进行编译,而该编译将忽略VS使用的参考程序集.如果.NET 4.7在运行时可用,那么.NET 4.7的所有类型,包括其对 ValueTuple 的定义,都将与其他DLL中可能具有的其他定义一起被选取.

ASP.NET web pages are compiled at runtime, and this compilation ignores the reference assemblies that VS uses. If .NET 4.7 is available at runtime, all of .NET 4.7's types, including its definition of ValueTuple, will be picked up along with any other definition you might have from other DLLs.

如果已经安装了.NET 4.7,避免此问题的最简单方法是在开发环境中也使用.NET 4.7,或者避免运行时编译.

The easiest ways to avoid this problem if you've already installed .NET 4.7 are either to use .NET 4.7 in your development environment as well, or to avoid runtime compilation.

对于前者,您需要安装.NET 4.7目标包.它应该是Visual Studio安装程序中的一个选项.当您这样做时,可以避免 ValueTuple NuGet包,从而避免冲突.

For the former, you'd need to install the .NET 4.7 targeting pack. It should be an option in the Visual Studio installer. When you do that, you can avoid the ValueTuple NuGet package and thereby the conflict.

对于后者,您可以在发布Web项目时启用预编译.当您执行此操作时,通常在运行时进行的所有编译都将在发布期间进行,以一种受控的方式进行,而不会看到.NET 4.7的新增内容.

For the latter, you can turn on precompilation when you publish your web project. When you do this, all the compilation that normally happens at runtime instead occurs during the publishing, in a controlled way where .NET 4.7's additions won't be seen.

这篇关于' ValueTuple< T1,T2& gt;#39;在' System.ValueTuple ...'中都存在和' mscorlib ...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆