MenuItem checkboxes disappearing on compile

Whenever my scripts get compiled (any time I make any changes) all of my custom menu items with checks get turned off. I tried updating them in a static constructor, but that never gets called. How can I get them to remain as they are?

public const string clientMenu = "Build/Client";
public const string serverMenu = "Build/Server";

static BuildEditor()
{
    EditorApplication.delayCall += Update;
}
static void Update()
{
    foreach (BuildTargetGroup buildTarget in System.Enum.GetValues(typeof(BuildTargetGroup)))
    {
        if (buildTarget == 0 || buildTarget == (BuildTargetGroup)5 || buildTarget == (BuildTargetGroup)6 || buildTarget == (BuildTargetGroup)15 || buildTarget == (BuildTargetGroup)16)
        {
            continue;
        }
        if (PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTarget).Contains("SERVER"))
        {
            Debug.Log("is server");
            Menu.SetChecked(serverMenu, true);
            Menu.SetChecked(clientMenu, false);
            break;
        }
        else
        {
            Debug.Log("is client");
            Menu.SetChecked(serverMenu, false);
            Menu.SetChecked(clientMenu, true);
            break;
        }
    }
}

[MenuItem(serverMenu)]
public static void ChangeToServer()
{
    if (Menu.GetChecked(serverMenu))
    {
        return;
    }
    Menu.SetChecked(serverMenu, true);
    Menu.SetChecked(clientMenu, false);
    foreach (BuildTargetGroup buildTarget in System.Enum.GetValues(typeof(BuildTargetGroup)))
    {
        if (buildTarget == 0 || buildTarget == (BuildTargetGroup)5 || buildTarget == (BuildTargetGroup)6 || buildTarget == (BuildTargetGroup)15 || buildTarget == (BuildTargetGroup)16)
        {
            continue;
        }
        PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTarget, PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTarget).Replace("SERVER", string.Empty) + ";SERVER");
    }
}

[MenuItem(clientMenu)]
public static void ChangeToClient()
{
    if (Menu.GetChecked(clientMenu))
    {
        return;
    }
    Menu.SetChecked(serverMenu, false);
    Menu.SetChecked(clientMenu, true);
    foreach (BuildTargetGroup buildTarget in System.Enum.GetValues(typeof(BuildTargetGroup)))
    {
        if (buildTarget == 0 || buildTarget == (BuildTargetGroup)5 || buildTarget == (BuildTargetGroup)6 || buildTarget == (BuildTargetGroup)15 || buildTarget == (BuildTargetGroup)16)
        {
            continue;
        }
        PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTarget, PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTarget).Replace("SERVER", string.Empty));
    }
}

well… i found the way for this case.

if you save a boolean flag about the checked state of the menu item(ex. EditorPref.SetInt()…etc), you can call a method before selecting the parent menuItem(ex. Build as your case).

in order to this way, you should make a method with the MenuItem attribute that the isValidateFunction property is true.

this validate function should be always return true. and you can write the code that load the flag saved and set Menu.SetChecked() to the flag saved;