How to create prefabs from Editor scripts?

I want to have a custom menu item that creates a prefab for me. I tried doing this:

public class ImportAnimations : ScriptableWizard {

    public Texture2D spritesheet;
    public TextAsset spritedoc;

    [MenuItem("Custom/Animations/ImportAnimations...")]
    static void CreateWizard()
    {
        ScriptableWizard.DisplayWizard("Import Animations from:", typeof(ImportAnimations), "Import");  
    }

    void OnWizardCreate()
    {
        GameObject go = new GameObject("TestAsset");
        go.AddComponent(typeof(Animation));
        go.SetActiveRecursively(false);
        AssetDatabase.CreateAsset(go, "Assets/Prefabs/TestAsset.prefab");
        GameObject.DestroyImmediate(go);
    }
}

This creates the prefab, but it also keeps the GameObject in the scene. If I delete the GameObject the prefab will be empty (the Animation component is lost). If I delete the prefab from my project folder before deleting the GameObject in my scene Unity crashes. (reported bug) Is there another way to do this? Or is it just a bug? (using b7)

After searching a bit more I found this answer which solved my problem:

http://answers.unity3d.com/questions/1125/how-do-i-programmatically-assign-a-gameobject-to-a-prefab

Keeping the question here, so the next one who's as dumb as I will have a better chance of finding the right answer.

This way works.

// Create some asset folders.
AssetDatabase.CreateFolder("Assets/Meshes", "MyMeshes");
AssetDatabase.CreateFolder("Assets/Prefabs", "MyPrefabs");

// The paths to the mesh/prefab assets.
string meshPath = "Assets/Meshes/MyMeshes/MyMesh01.mesh";
string prefabPath = "Assets/Prefabs/MyPrefabs/MyPrefab01.prefab";

// Delete the assets if they already exist.
AssetDatabase.DeleteAsset(meshPath);
AssetDatabase.DeleteAsset(prefabPath);

// Create the mesh somehow.
Mesh mesh = GetMyMesh();

// Save the mesh as an asset.
AssetDatabase.CreateAsset(mesh, meshPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

// Create a transform somehow, using the mesh that was previously saved.
Transform trans = GetMyTransform(mesh);

// Save the transform's GameObject as a prefab asset.
PrefabUtility.CreatePrefab(prefabPath, trans.gameObject);