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

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

问题描述

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

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

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

这是你的 C# 代码:

And this is your C# code:

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

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

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天全站免登陆