简体   繁体   English

如何知道.NETCore/.NET5 或旧框架是否运行.fsx 脚本?

[英]How to know if .fsx script being run by .NETCore/.NET5 or by legacy framework?

My.fsx scripts are kind of old so they only work with .NET4.x, which means I need to run them with the fsharpi command in macOS. My.fsx 脚本有点旧,所以它们只适用于 .NET4.x,这意味着我需要在 macOS 中使用fsharpi命令运行它们。

Now I'm thinking to start migrating them to dotnet fsi ;现在我正在考虑开始将它们迁移到dotnet fsi however, ideally I can find a way to run them in both ways for a while, in a transition period.但是,理想情况下,我可以找到一种方法在过渡期内以两种方式运行它们一段时间。

So I was hoping that, inside them, I could do some kind of conditional code like this:所以我希望,在它们里面,我可以做一些这样的条件代码:

#if NET5_0
System.Console.WriteLine "we're running in dotnet fsi, yay"
#else
System.Console.WriteLine "we're running with fsharpi, legacy"
#endif

But it doesn't work, surprisingly (and I say surprisingly because the define NET5_0 is being mentioned in many documentation pages. Any other idea of how I could detect this?但它不起作用,令人惊讶的是(我说令人惊讶的是因为在许多文档页面中都提到了定义NET5_0 。关于我如何检测到这一点的任何其他想法?

I think System.Environment.Version will give you the info you need:我认为System.Environment.Version会给你你需要的信息:

if System.Environment.Version.Major >= 5 then
    System.Console.WriteLine "we're running in dotnet fsi, yay"
else
    System.Console.WriteLine "we're running with fsharpi, legacy"

It looks like NET5_0 is only defined for C#.看起来NET5_0只为 C# 定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使 .net5 C#9 默认目标框架 VS2019 - how can i make .net5 C#9 default targeted framework VS2019 使用 targetFramework=".NETCore5.0" 生成 NuGet,无法在 .net5 C# 项目中使用它 - Generate NuGet with targetFramework=".NETCore5.0", using it in .net5 C# project not possible 下面的多级继承如何在 .Net5 中工作? - How is the below multilevel inheritance working in .Net5? 如何在.NET Core 1.0中使用Entity Framework运行sql脚本? - How to run sql script with Entity Framework in .NET Core 1.0? 如何通过脚本运行ASP.NET Framework项目? - How to run an ASP.NET Framework project from a script? 既然 .NET Framework 的那一部分可以在 Mac 和 Linux 上运行,我们如何知道 .NET 应用程序是否会在 Windows 之外运行? - Now that part of the .NET Framework runs on Mac and Linux, how can we know if a .NET app will run outside of Windows? 在应用程序启动之前运行数据库迁移(.NET5、EF 核心 5) - Run database migration before app start (.NET5, EF core 5) 将 .net 核心与旧的 .net 框架 dll 一起使用 - Use .net core with legacy .net framework dlls 任何人都知道Inno Setup的可靠.NET Framework 2.0安装程序脚本吗? - Anyone know of a solid .NET Framework 2.0 installer script for Inno Setup? 如何在 ubuntu 上运行 .NET Framework 4 - How to run .NET Framework 4 on ubuntu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM