默认情况下,add-migration命令尝试在以下位置创建迁移.cs文件

  • 项目根
  • 迁移

  • 我想将迁移以及其他与EF相关的代码存储在项目的\ Data文件夹中:
  • 项目根
  • 数据
  • 迁移

  • 有了这种结构,当我执行
    PM> add-migration Migration1
    

    在NuGet控制台中,我收到以下错误:

    System.IO.DirectoryNotFoundException:找不到路径“C:\ MyProjectRoot \ Migrations \ 201112171635110_Migration1.cs”的一部分。
    在System.IO .__ Error.WinIOError(Int32 errorCode,字符串mayFullPath)
    在System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限, bool(boolean) useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,字符串msgPath, bool(boolean) bFromProxy, bool(boolean) useLongPath)
    在System.IO.FileStream..ctor处(字符串路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,FileOptions选项)
    在System.IO.StreamWriter.CreateFile(字符串路径, bool(boolean) 值附加)
    在System.IO.StreamWriter..ctor处(字符串路径, bool(boolean) 值附加,编码编码,Int32 bufferSize)
    在System.IO.StreamWriter..ctor处(字符串路径, bool(boolean) 值附加,编码编码)
    在System.IO.File.InternalWriteAllText(字符串路径,字符串内容,编码编码)
    在System.IO.File.WriteAllText(字符串路径,字符串内容)

    是否可以在执行add-migration命令时指定磁盘上应创建迁移文件的位置?

    最佳答案

    在配置类构造函数中,添加以下行:

    this.MigrationsDirectory = "DirOne\\DirTwo";
    

    命名空间将继续设置为配置类本身的命名空间。要更改此设置,请添加以下行(也在配置构造函数中):
    this.MigrationsNamespace = "MyApp.DirOne.DirTwo";
    

    10-07 13:46
    查看更多