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;

    static void CreateWizard()
        ScriptableWizard.DisplayWizard("Import Animations from:", typeof(ImportAnimations), "Import");  

    void OnWizardCreate()
        GameObject go = new GameObject("TestAsset");
        AssetDatabase.CreateAsset(go, "Assets/Prefabs/TestAsset.prefab");

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:

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.

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

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

// 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);