Answered Problem Generating -Script SQL File with Visual Web Developer 2010

  • Monday, December 05, 2011 8:13 AM
     
     
    I believe EF.Migrations is relying on a template not present in Visual Web Developer (only in Visual Studio), "General\Sql File". Any way around this?
    PM> Update-Database -TargetDatabase:"NZProduction" -Script
    Found 2 pending explicit migrations: [201112050729181_InitialMigration, 201112050738341_AddImageInMessage].
    Applying migration: 201112050729181_InitialMigration.
    Applying migration: 201112050738341_AddImageInMessage.
    System.Runtime.InteropServices.COMException (0x80004005): Template 'General\Sql File' is not valid for the selected project.
       at EnvDTE.ItemOperations.NewFile(String Item, String Name, String ViewKind)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.ShowSqlFile(String sql)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.BeginProcessing(MigratorBase migrator)
       at System.Data.Entity.Migrations.BaseMigratorCommand.BeginProcessingCore()
    • Edited by Coad Toad Monday, December 05, 2011 8:16 AM format better
    •  

All Replies

  • Monday, December 05, 2011 8:17 PM
     
     Answered Has Code

    Thank you for reporting this.

    As a workaround, you can use the API to create a script

    var configuration = new Migrations.Configuration();
    configuration.ConnectionStringName = "NZProduction";
    
    var migrator = new DbMigrator(configuration);
    var sql = new MigratorScriptingDecorator(migrator).ScriptUpdate(null, null);
    
    File.WriteAllText("Migrate.sql", sql);

     


    Brice Lambson
  • Tuesday, December 06, 2011 1:07 AM
     
     
    Thanks a ton Brice, I really appreciate the fast rev cycle on these EF.Migration previews.
  • Tuesday, December 06, 2011 1:35 AM
     
     

    BTW, for me this generates the complete migration history, it appears to ignore the current state of NZProduction (e.g. if I've applied the first two of three migrations to NZProduction already, the output SQL includes all 3 migrations, and I have to trim the first two off by hand).

    Is this expected?

  • Thursday, January 19, 2012 10:44 PM
     
     

    I've upgraded to EF 4.3 beta1, and this still seems to be an issue; including on a stock Visual Web Dveloper 2010 Express install. Any chance of resolution before EF 4.3 final? Essentially you cannot use Update-Database -Script on Web Developer 2010 Express, because it relies on a (presumably blank) template found only in Visual Studio full.

    System.Runtime.InteropServices.COMException (0x80004005): Template 'General\Text File' is not valid for the selected project.

       at EnvDTE.ItemOperations.NewFile(String Item, String Name, String ViewKind)

       at System.Data.Entity.Migrations.Extensions.ItemOperationsExtensions.NewSqlFile(ItemOperations itemOperations, String contents)

       at System.Data.Entity.Migrations.MigrationsCommands.UpdateDatabase(String sourceMigration, String targetMigration, Boolean script, Boolean force)

       at UpdateDatabase(Object , Object[] )

       at System.Management.Automation.MethodInformation.Invoke(Object target, Object[] arguments)

       at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments)

    Template 'General\Text File' is not valid for the selected project.