Closed bernatagulloesbrina closed 9 months ago
Hi Bernat.
It is possible to check the version at runtime, using something like:
Info(typeof(Table).Assembly.GetName().Version.ToString());
This contains the full version number of the currently running Tabular Editor build. If you just need to know whether it's 2 or 3, use:
var isTabularEditor3 = typeof(Table).Assembly.GetName().Version.Major == 3;
However, in some cases, the script cannot be compiled unless it was written for a specific version of Tabular Editor. The good news is that both TE2 and TE3 scripts support preprocessor directives, but the bad news is that, neither TE2 nor TE3 defines a conditional symbol that you can use in the directive.
I will make sure to add the symbols "TE2" and "TE3", in the next update of both applications, so that you can use conditional compilation like the following, going forward:
#if TE2
Info("This code is only ever compiled when the script is running in Tabular Editor 2");
#else
Info("This code is only ever compiled when the script is running in Tabular Editor 3");
#endif
Will also add symbols for specific minor versions, i.e.: TE2_7
, TE2_7_OR_GREATER
, TE_3_9_OR_GREATER
, etc., which will let you write scripts that gracefully handle situations where a specific version is required:
#if TE_3_9_OR_GREATER
// ... code that relies on functionality introduced in Tabular Editor 3.9.0 ...
#else
Error("This script requires Tabular Editor 3.9 (or newer) to be able to run.");
#endif
Awesome! Thank you
El dj., 3 d’ag. 2023, 10:58, Daniel Otykier @.***> va escriure:
Hi Bernat.
It is possible to check the version at runtime, using something like:
Info(typeof(Table).Assembly.GetName().Version.ToString());
[image: image] https://user-images.githubusercontent.com/8976200/258056392-e9d47117-8a02-4c28-b9c2-b019886ffa9b.png
This contains the full version number of the currently running Tabular Editor build. If you just need to know whether it's 2 or 3, use:
var isTabularEditor3 = typeof(Table).Assembly.GetName().Version.Major == 3;
However, in some cases, the script cannot be compiled unless it was written for a specific version of Tabular Editor. The good news is that both TE2 and TE3 scripts support preprocessor directives https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives, but the bad news is that, neither TE2 nor TE3 defines a conditional symbol that you can use in the directive.
I will make sure to add the symbols "TE2" and "TE3", in the next update of both applications, so that you can use conditional compilation like the following, going forward:
if TE2
Info("This code is only ever compiled when the script is running in Tabular Editor 2");
else
Info("This code is only ever compiled when the script is running in Tabular Editor 3");
endif
Will also add symbols for specific minor versions, i.e.: TE2_7, TE2_7_OR_GREATER, TE_3_9_OR_GREATER, etc.
— Reply to this email directly, view it on GitHub https://github.com/TabularEditor/TabularEditor3/issues/969#issuecomment-1663571921, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUUXHPUVGQR7AUNKLCMBIDXTNR3PANCNFSM6AAAAAA3BQTVAM . You are receiving this because you authored the thread.Message ID: @.***>
Hi Bernat. As of 3.10.0 we now have support for preprocessor symbols in TE3 (will add them to TE2 soon!).
But for now, a script such as the following should work in both TE2 and TE3:
#if TE3
Info("This only gets compiled in TE3");
#else
Info("This only gets compiled in TE2");
#endif
More info: https://docs.tabulareditor.com/te3/features/csharp-scripts.html#compatibility
Is your feature request related to a problem? Please describe. Sometimes is tricky to make fully compatible scripts so it would be nice to conditionally execute different parts of the code if the application executing is TE2 or TE3
Describe the solution you'd like Some method or system variable that I could check to determine the application version (2 or 3)
Describe alternatives you've considered When creating a calc table with an expression is easy to check the application because in TE2 it does not have columns, but in other cases I'm not sure how to go about this problem