BuildPipeline.BuildPlayer and UNITY_EDITOR incompatibility

I have a conditonal compilation like this:

#if UNITY_EDITOR
	url = "file:///my_folder/myfile.txt";
#elif UNITY_WEBPLAYER
	url = "my_folder/myfile.txt";
#else
	url = "http://mysite.com/my_folder/myfile.txt";
#endif

It works well when I compile it using the Unity Build Setting window, but when I compile it using “BuildPipeline.BuildPlayer” it keeps UNITY_EDITOR on, compiling the wrong code segment.
It kind of make sense as long I’m actually in the editor, but I’m looking for a workaround.

Any ideas?

Ugly solution:

if (Application.platform.ToString().Contains("Editor")) {
    url = "file:///my_folder/myfile.txt";
} else {
    #if UNITY_WEBPLAYER
        url = "my_folder/myfile.txt";
    #else
        url = "http://mysite.com/my_folder/myfile.txt";
    #endif
}