Мой проект EF находится в одном проекте, а мой ASP. NET Базовый проект в другом проекте,
D: \ AspProjects \ DatabaseHafez> <=== Моя модель EF находится в этой папке </p>
D: \ AspProjects \ Hafez> <=== my as pnet core 3 находится в этой папке </p>
, поэтому у каждого проекта есть одна папка bin.
Конструктор ниже (ConfigurationBuilder) должен иметь путь к appsettings. json файл для чтения строки соединений. Поэтому ниже указан этот путь =>
D: \ AspProjects \ DatabaseHafez \ bin \ Debug \ netcoreapp3.1 \ appsettings. json
но мой appsettins. json файл в моем основном проекте asp. net, поэтому после сборки будет скопирован в выходную папку =>
D: \ AspProjects \ Hafez \ bin \ Debug \ netcoreapp3.1 \ appsettings. json
так Как я могу найти путь к выходной папке?
public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
AppDbContext IDesignTimeDbContextFactory<AppDbContext>.CreateDbContext(string[] args)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
IConfigurationRoot configuration = builder.Build();
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
var context = new AppDbContext(optionsBuilder.Options);
context.Database.EnsureCreated();
return context;
}
}
Теперь я хочу добавить миграции, но я получаю ошибка
D:\AspProjects\DatabaseHafez>dotnet ef migrations add changed98112601
Build started...
Build succeeded.
System.IO.FileNotFoundException: файл конфигурации 'appsettings. json' не найден и не является обязательным , Физический путь: 'D: \ AspProjects \ DatabaseHafez \ bin \ Debug \ netcoreapp3.1 \ appsettings. json'.
в Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException (информация об ExceptionDispatchInfo)
в Microsoft.Extensions.Configuration.FileConfigurationProvider.Load (логическая перезагрузка)
в Microsoft.Extensions.Configuration.FileConfigurationProvider.Load ()
в Microsoft.Extensions.Configuration.Configuration Root .. ctor (IList 1 providers)<br>
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()<br>
at DatabaseHafez.AppDbContextFactory.Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory<DatabaseHafez.AppDbContext>.CreateDbContext(String[] args) in D:\AspProjects\DatabaseHafez\AppDbContextFactory.cs:line 27<br>
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContextFromFactory(Type factory)<br>
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_1.<FindContextTypes>b__9()<br>
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func
1 factory)
в Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext (String contextType)
в Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration (строковое имя, строковое значение outputDir, строковый контекст Microsoft, в строковом контексте) .EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl (Строковое имя, String outputDir, String contextType) в Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration. <> C__DisplayClass0_0. <. Ctor> bign0. rationExecutor.OperationBase. <> c__DisplayClass3_0`1.b__0 () в Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute (действие action)
Файл конфигурации 'appsettings. json' не найден и является не обязательно. Физический путь: «D: \ AspProjects \ DatabaseHafez \ bin \ Debug \ netcoreapp3.1 \ appsettings. json».
Теперь я хочу узнать, как найти папку bin
моего ASP. NET Базового проекта?