如何在Visual Studio中的.NET Core项目的目标框架之间切换 [英] How to switch between target frameworks for .NET Core projects in Visual Studio

查看:785
本文介绍了如何在Visual Studio中的.NET Core项目的目标框架之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个.NET Core项目,如下所示:

Say you have a .NET Core project that looks like this:

"frameworks": {
    "net40": {},
    "dotnet5.1": {}
}

这是您的C#代码:

public class Foo
{
    public static void Blah()
    {
#if DOTNET5_1
        DoSomething();
#elif NET40
        DoSomethingElse();
#endif
    }
}

现在,在Visual Studio中当您查看 .cs 文件时, #if 部分之一将显示为灰色- DoSomething DoSomethingElse 。这是它在我的笔记本电脑上的显示方式:

Now, in Visual Studio when you view the .cs file, one of the #if sections will be grayed out- either DoSomething or DoSomethingElse. Here's how it shows up on my laptop:

是否有可能让VS在目标平台之间切换上下文,所以您可以查看将为特定平台编译的内容?例如,在实际构建解决方案之前,我可能希望检查每个框架是否有任何弯曲的红色线条。

Is it possible to get VS to 'switch context' between target platforms, so you can view what would be compiled for a particular platform? For example, I might want to check for any red squiggly lines for each framework before actually building the solution.

任何帮助将不胜感激,谢谢!

Any help would be appreciated, thanks!

推荐答案

在编辑器顶部应该是导航栏。导航栏左侧是一个下拉菜单,您可以从中选择上下文。

At the top of your editor should be the navigation bar. Left in the navigation bar is a dropdown menu that lets you select the context.

如果隐藏了导航栏,可以通过进入工具>选项>文本来启用它。编辑器> C#,然后选中导航栏复选框。

If the navigation bar is hidden, you can enable it by going into Tools > Options > Text Editor > C# and check the navigation bar checkbox.

这篇关于如何在Visual Studio中的.NET Core项目的目标框架之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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