Variable string to custom menu item

I have a custom menu item to display the currently installed version of our SDK. Currently, it’s being hardcoded such as the following:

 [MenuItem("SDK/Version: 2.1.2", false, 15)]
        static void init(){}

However, I’d like it to be read from a text file (which gets updated automatically by a separate process). So, it should look something like this:

string version = "SDK/Version: " + GetVersion() //reads the version from a text file
  [MenuItem(version, false, 15)]
        static void init(){}

However, Unity doesn’t let you pass in variables as attributes and has to be a constant. How can I achieve this?

Thanks!

What you want cannot be done. The data you pass to the attribute constructor (the string value) is compiled into the DLL; you cannot execute code during compilation to achieve that.

A workaround for this is to use code generation - generate this class somehow at compile time so it’s up to date with the information you have stored in your file.

Thanks for the response! How do I generate this class at compile time? Any example code you can point me to? I haven’t done such a thing before. Thanks for the help.