简体   繁体   English

项目的目标 .NET 框架取决于 Visual Studio 版本?

[英]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.

相关问题 我可以在版本4.6.2的Visual Studio项目中使用针对4.5.1 .net框架的库吗? - Can I use a library which is targeted to 4.5.1 .net framework in a visual studio project of version 4.6.2 即使更新到 .net 框架 4.7 后,Visual Studio 仍显示旧的目标 .net 框架 - Visual studio showing old targeted .net framework even after updated to .net framework 4.7 在Visual Studio中选择.Net Framework版本 - Selecting .Net Framework Version in Visual Studio 将我在Visual 2010中的项目定位到.Net 4.0,但系统仍在查找dll“ System.Core版本2.0.5.0” - Targeted my project in Visual 2010 to .Net 4.0 but the system still looks for the dll 'System.Core version 2.0.5.0' Visual Studio 安装程序项目 .NET 框架 - Visual Studio Installer Project .NET Framework Visual Studio 安装程序安装项目检测到不正确版本的 .net 框架作为依赖项 - visual studio installer setup project detecting incorrect version of .net framework as dependency 如何在 Visual Studio 2019 中创建 .NET framework 4.6 版本的 XUnit 项目? - How do I create .NET framework 4.6 version of XUnit project in Visual Studio 2019? 为 .NET Core 类库项目选择框架版本 - Visual Studio 2019 - Select framework version for .NET Core Class Library project - Visual Studio 2019 如何将 Visual Studio 2019 中的 .NET 版本更改为 .NET Framework 4.7.2? - How to change .NET version in Visual Studio 2019 to .NET Framework 4.7.2? 什么版本的 .Net 框架应该针对最终用户应用程序 - What version of .Net framework should be targeted for end user apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM