I know this question is years out of date, but I’ve just run into a situation where AssetDatabase.Refresh() and AssetDatabase.ImportAsset() don’t seem to cause a recompile.
I’m using some editor scripts to keep multiple copies of several of the .asset files in the ProjectSettingsFolder - this allows me to have multiple build configurations set up with different scripting defines, different scenes, etc.
Each build configuration has its own copies of the .asset files stored in a folder and I copy them over the ones in the main ProjectSettings folder to change build configuration.
Normally if you edit the scripting defines in the player settings inspector this triggers a recompile, but this doesn’t seem to happen if you copy a new ProjectSettings.asset file over the main one from script.
AssetDatabase.Refresh() and ImportAsset() also didn’t seem to help.
Whilst messing about with some other editor code recently I noticed that when a script execution order is changed this forces a recompile of all scripts, so I’m using this snippet of code to force a recompile of all scripts after I change the settings file and it seems to work reliably (N.B. this will only work in editor code)
MonoScript cMonoScript = MonoImporter.GetAllRuntimeMonoScripts()[ 0 ];
MonoImporter.SetExecutionOrder( cMonoScript, MonoImporter.GetExecutionOrder( cMonoScript ) );
As you can see it makes a change that doesn’t change anything, but this seems to trigger a complete recompile of all scripts
Hope this helps someone
Update (November 2016):
Apparently MonoImporter is now undocumented so this technique may stop working soon.
Another way to force a recompile manually is to change the scripting define symbols (in the player settings window) to a new value.
It is possible to set this from script using PlayerSettings.SetScriptingDefineSymbolsForGroup() and one of the plugins I bought off the asset store seems to use this method to force a recompile but I’ve yet to need to try it so I can’t offer sourcecode.
The one thing to mention to anyone thinking of trying this is that I would assume the editor only triggers a recompile if the symbols you pass are different to the ones already set…
Update (June 2018):
The MonoImporter method no longer seems to work.
I’m now using PlayerSettings.SetScriptingDefineSymbolsForGroup() as mentioned above.
The code I have adds a dummy symbol to the end of the symbols which has a number in it - e.g. “_dummy_0”.
Each time I need to force it again I parse the symbol string to find the number on the end, remove the existing symbol and add a new one with a number one higher (which wraps back to 0 eventually).
FWIW you could just use 2 different unique symbols and swap which you use each time which would be simpler but I’ve written the code now