[英]Targeted .NET framework for the project depends on Visual Studio version?
I have a funny situation where the C# project targets version of .NET framework depending on Visual Studio version rather than depending on selected .NET target version in Application tab of project's properties.我有一个有趣的情况,C# 项目根据 Visual Studio 版本而不是根据项目属性的“应用程序”选项卡中选定的 .NET 目标版本来定位 .NET 框架的版本。
I had VS2013 premium, update 4, installed and the given project targets .NET 3.5.我安装了 VS2013 premium、update 4,并且给定的项目面向 .NET 3.5。
Afterwards I've installed VS2015 Enterprise edition and opened solution with the given project with VS2015.之后我安装了 VS2015 企业版并使用 VS2015 打开了给定项目的解决方案。 Resharper suggested use of nameof() operator (which is .NET 6.0 feature) and this compiled, but when I open given solution in VS2013 it doesn't compile anymore.
Resharper 建议使用 nameof() 运算符(这是 .NET 6.0 功能)并进行编译,但是当我在 VS2013 中打开给定的解决方案时,它不再编译。
Here's the screenshot of Application tab for the given project:这是给定项目的应用程序选项卡的屏幕截图:
Here's the code snippet from the project when I open it in VS2015:这是我在 VS2015 中打开项目时的代码片段:
Which compiles successfully.哪个编译成功。
And here's the code snippet from the project when I open it in VS20103:这是我在 VS20103 中打开项目时的代码片段:
Which doesn't compile.哪个不编译。
Any clues about this?有任何线索吗?
UPDATE:更新:
To rephrase my question.重新表述我的问题。 Why does the given project (that targets .NET 3.5) compile at all in VS2015 even though I've used .NET 6.0 feature (nameof() operator)?
即使我使用了 .NET 6.0 功能(nameof() 运算符),为什么给定的项目(针对 .NET 3.5)在 VS2015 中完全编译?
This is normal behaviour.这是正常行为。 If you try to compile something .NET 4.0 specific in VS 2005, you will get the same result.
如果您尝试在 VS 2005 中编译特定于 .NET 4.0 的内容,您将获得相同的结果。 Using a certain VS version you can only develop using up to a certain .NET version.
使用你一定VS版本只能通过发展达到一定的.NET版本。
If I remember correctly:如果我没记错的话:
VS 2005 - .NET 2.0
VS 2008 - .NET 3.5
VS 2010 - .NET 4.0
VS 2013 - .NET 4.5
Update: The .NET version is indeed not relevant in this case, as the nameof
operator is a feature of the Roslyn compiler.更新:在这种情况下,.NET 版本确实不相关,因为
nameof
运算符是 Roslyn 编译器的一个功能。 Nothing more, nothing less.不多也不少。 The VS 2013 definitely uses a different one (at least a compiler which does not cover up with C# 6), therefore it does not compile.
VS 2013 肯定使用了不同的(至少是一个没有覆盖 C# 6 的编译器),因此它不能编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.