如何执行基于所述框架不同的动作? (ASP.NET 5) [英] How to execute different actions based on the framework? (ASP.NET 5)

查看:78
本文介绍了如何执行基于所述框架不同的动作? (ASP.NET 5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有迁移从.NET框架,新的.NET核心C#应用程序,因为你想拥有它的一些新功能。

Suppose that you have to migrate a C# application from the .NET framework to the new .NET Core, because you want to have some of it new capabilities.

您有您的code基地,而你想在同一时间得到充分的工作部分,因为这将是一个大量的工作迁移的一次。其主要思想是要的完全核心的在未来。

You have your code base and you want to get fully working parts at a time, since it will be a lot of work migrating all at once. The main idea is to be fully core in a future.

我的问题是:


  • 有没有一种方法来检查功能,为present在一个框架,而不是在其他?或框架基础上执行不同的操作?

推荐答案

由于有详细的此处。有编译器指令(#如果)来检查对应于两个框架的符号。而且还可以同时针对框架。

As is detailed here. There are compiler directives (#if) to check for symbols that correspond to the two frameworks. And it is also possible to target both frameworks.

如果比如你有一个使用了不能作为.NET的核心部分资源$ C ​​$ C,你可以环绕他们在一个条件编译指令。

If for instance you have code that uses resources that are not available as part of .NET Core, you can surround them in a conditional compilation directive.

编译器指令的用法示例...

Usage example of the compiler directives...

#if DNX451
    // Do something
#elif DNXCORE50
    // Do something
#else
#error No implementation for this target
# endif

其中, DNX451 重新presents .NET Framework和 DNXCORE50 重新presents .NET核心

Where DNX451 represents the .NET Framework and DNXCORE50 represents .NET Core.

看他们在行动对这部影片在36分钟

这篇关于如何执行基于所述框架不同的动作? (ASP.NET 5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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