namespace name `UnityEditor' could not be found

hi , I hope find solution to my problem here.

I have this code for build menu of assetBundle options

using UnityEngine;
using UnityEditor;

public class ExportAssetBundles : MonoBehaviour {
    [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
    static void ExportResource () {
        // Bring up save panel
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection.
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
            Selection.objects = selection;
        }
    }
    [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
    static void ExportResourceNoTrack () {
        // Bring up save panel
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection.
            BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
        }
    }
}

the problem happen while build app game it show me this error

Assets/Scripts/menuAssets.cs(7,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

and this also

Error building Player because scripts had compiler errors

Check this: "UnityEditor" namespace not found... - Unity Answers

when i move the script file into the editor folder, it fixed.

I got this error when I tried to build with custom attributes and property drawers, which uses UnityEditor.

Using preprocessor fixed it for me, probably the same reason as when moved to editor folder. Is one better than other?

#if UNITY_EDITOR
//--code--
#endif

Delete unwanted resources and especially scripts those are not associated with any GameObject component or not linked with other classes in object form or move ur scripts into “editor” folder, it really solved my problem

I had this issue inside a third party asset and I got around it by adding a reference to the UnityEditor.dll in the project file.