I need to set a version number to be used in the AssemblyVersion attribute by several related projects.
In C# I use the following
public class Constants { public const string Version = "1.2.3.4"; }
then it can be used as follows:
[assembly:AssemblyVersion(Constants.Version)]
What would be the equivalent construct in F#. All my attempts to come up with a binding which can be accepted as an attribute argument did not work.
Global Constants. A global constant is a literal value to which you assign a name. Like a global variable, you can access the value of the global constant from any script or 4GL procedure in the application. You set the value for the global constant when you declare it.
The global keyword in Python is used to modify a global variable in a local context (as explained here). This means that if the op modifies SOME_CONSTANT within myfunc the change will affect also outside the function scope (globally).
A constant which is needed in more than one functions can be declared a global constant by declaring it a constant using the reserve word const, initializing it and placing it outside of the body of all the functions, including the main function.
Global Constants in C++ C++ global constants have static linkage. This is different than C. If you try to use a global constant in C++ in multiple files you get an unresolved external error. The compiler optimizes global constants out, leaving no space reserved for the variable.
Use the attribute Literal
:
[<Literal>] let version = "1.2.3.4" [<assembly:AssemblyVersion(version)>]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With