Where can I find the console or debug output from code executed in the package manager window?

Solution 1:

A quick hack I use to be able to quickly find a value in my Seed method is simply to throw an exception with a value I care about, e.g.

throw new Exception(yourValue);

This errors out the Seed, but my exception/value appears in my package manager console.

Solution 2:

Where can I find that output?

Sorry, but the quick answer is basically nowhere.

To be precise at least not in the package manager console.

Debug.WriteLine("Debug Test");
Trace.WriteLine("Trace Test");

You can see the output of the Debug... and Trace... methods if you attach another Visual Studio to debug the Visual Studio instance which is running the update-database command. Then in the debuggin VS you can see the output in the Output Window.

Console.WriteLine("Console Test");

You can see the output of the Console... methods if you run the migrations with the migrate.exe command line tool which comes with EF:

enter image description here

How do I output back to the package manager window?

I have here also bad news, after a quick "reflectoring": with the current implementation of the EF migrations it's not supported to display custom information during execution of the update-database (or any other command).

Solution 3:

Running a SQL print command will write to the Package Manager Console. Here is a helper method that I use:

    /// <summary>
    /// write a message to the Package Manager Console
    /// </summary>
    public void Debug(string s, params object[] args)
    {
        var fullString = string.Format(s, args).Replace("'", "''");
        Sql(string.Format("print '{0}'", fullString));
    }