![](/img/trans.png)
[英]ternary operator || Predefined type 'System.ValueTuple`3' is not defined or imported
[英]Predefined type 'System.ValueTuple`2' is not defined or imported
我有一個包含大約 20 個 C# 項目的 .NET 解決方案文件。 所有這些都針對 .NET Framework 4.6.2。 在幾個項目中,我可以輕松地編寫var t = ("hello", "world");
編譯器很高興。 但是在相同解決方案的某些項目中,編譯失敗, Predefined type System.ValueTuple`2 is not defined or imported
為完全相同的代碼段Predefined type System.ValueTuple`2 is not defined or imported
。
我已經檢查了以下幾點:
mscorlib.dll
。bin
和obj
已被刪除多次。System.ValueTuple
。ValueTuple
所有*.csproj
文件進行了文本搜索,沒有任何匹配。我知道有幾十篇文章與這個錯誤有關。 但他們中的大多數只是說:安裝 NuGet 包或更新您的 .NET Framework 版本。 不幸的是,它們似乎都沒有涵蓋我遇到的問題。 我不想安裝或升級任何東西,而是想了解這種行為。
我終於找到了罪魁禍首:有一個針對 .NET Standard 2.0 的項目。 每個引用 .NET Standard 項目的 .NET Framework 項目都會自動從 GAC 獲取對System.ValueTuple.dll
的引用(在我的例子中,這是 .NET Framework 4.7.2)。
沒有引用 .NET Standard 項目的每個項目都沒有引用。 因此,片段var t = ("hello", "world");
不能使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.