Joh*_*n C 4 build-process entity-framework visual-studio nuget
我的具体问题是如何在Entity Framework的构建过程中自动执行"添加迁移".在研究这个问题时,似乎最常见的方法是自动化这些步骤
这个初始方法基于我自己的研究和这个问题,最终在Add-Migration背后的powershell脚本需要相当多的设置才能运行.Visual Studio在创建程序包管理器控制台并使DTE对象可用时自动执行该设置.我宁愿不尝试在Visual Studio之外复制该设置.
解决方案的一个可能途径是未解决的堆栈溢出问题
在研究NuGet API时,它似乎没有"发送此文本,它将像在控制台中键入的那样运行".我不清楚Visual Studio与NuGet之间的界限,所以我不确定这是否会存在.
我能够通过软件包管理器控制台中的"$ dte.Windows"命令找到"Pacakage Manager Console",但在VS 2013窗口中,该集合为我提供了"Microsoft.VisualStudio.Platform.WindowManagement.DTE"对象. .WindowBase".如果有一种方式填充文本,我想我需要把它变成一个NuGetConsole.Implementation.PowerConsoleToolWindow"通过查看源代码我不清楚文本是如何填充但我不熟悉我的内容我看到了.
最糟糕的情况是,我会回过头来尝试按照这个问题来填充密钥,但是不愿意这样做,因为这会使构建过程周围的自动化大大复杂化.
所有这些都说,
感谢您提出任何建议,建议,帮助,非滥用,
约翰
对我有用的方法是从EntityFramework.Powershell项目中的AddMigrationCommand.cs开始跟踪实体框架代码,找到EntityFramework项目的钩子,然后使这些钩子工作,这样就没有Powershell依赖.
你可以得到像......
public static void RunIt(EnvDTE.Project project, Type dbContext, Assembly migrationAssembly, string migrationDirectory,
string migrationsNamespace, string contextKey, string migrationName)
{
DbMigrationsConfiguration migrationsConfiguration = new DbMigrationsConfiguration();
migrationsConfiguration.AutomaticMigrationDataLossAllowed = false;
migrationsConfiguration.AutomaticMigrationsEnabled = false;
migrationsConfiguration.CodeGenerator = new CSharpMigrationCodeGenerator(); //same as default
migrationsConfiguration.ContextType = dbContext; //data
migrationsConfiguration.ContextKey = contextKey;
migrationsConfiguration.MigrationsAssembly = migrationAssembly;
migrationsConfiguration.MigrationsDirectory = migrationDirectory;
migrationsConfiguration.MigrationsNamespace = migrationsNamespace;
System.Data.Entity.Infrastructure.DbConnectionInfo dbi = new System.Data.Entity.Infrastructure.DbConnectionInfo("DataContext");
migrationsConfiguration.TargetDatabase = dbi;
MigrationScaffolder ms = new MigrationScaffolder(migrationsConfiguration);
ScaffoldedMigration sf = ms.Scaffold(migrationName, false);
}
Run Code Online (Sandbox Code Playgroud)
您可以使用此问题到达dte对象,并从那里找到要传递给调用的项目对象.
| 归档时间: |
|
| 查看次数: |
3908 次 |
| 最近记录: |