github twitter email rss

Enable Code First Migrations check box is hidden from Publishing Wizard

15 Nov 2012

I’ve been really excited with the new Windows Azure Websites recently. As a long time AppHarbor user, deploying ASP.NET MVC app to the cloud via a git push is extremely nice.

Something strange happened to me on my last project though. After creating a basic working prototype of the app I was ready to deploy the application. Since it’s a small prototype for now I was using the Visual Studio Publishing Wizard.

I had enable migrations on the project, created some models and my DbContext class, everything was working nicely. On the Publishing Wizard I was seeing this:

without-code-first

The Enable Code First Migrations check box was not present, and my DbContext class was not displayed. The wizard should look like this:

with-code-first

After a couple of time (hours?) of digging, I finally find where the thing is configured.

publish-settings

Manually editing the pubxml file to make the check box appear

You can enable that check box by editing the Properties\YourProject - WebDeploy.pubxml look for the PublishDatabaseSettings

    <PublishDatabaseSettings>  
      <Objects xmlns="">  
        <ObjectGroup Name="Namespace.Models.YourDBClass" Order="1" Enabled="True">  
          <Destination Path="your-connection-string-goes-here" />  
          <Object Type="DbCodeFirst">  
            <Source Path="DBMigration" DbContext="Namespace.Models.YourDBClass, AssamblyName" MigrationConfiguration="Namespace.Migrations.Configuration, Assambly" Origin="Convention" />  
          </Object>  
        </ObjectGroup>  
      </Objects>  
    </PublishDatabaseSettings>

Change Namespace.Models.YourDBClass by your class that inherits DbContext, change Namespace.Migratins.Configuration to fit your migration configuration namespace and Assambly with your Assambly name.

Save and open the publish wizard you will have that check box.

I’ve took the VS Publishing Wizard from that stackoverflow question I’ve answered.

Technorati Tags: Windows Azure,Publishing Wizard,EF Code First Migrations


Back to posts