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