AbpCore 执行迁移文件生成数据库报错 Could not find root folder of the web project!
背景介绍
下载开源52abp项目(https://github.com/52ABP/LTMCompanyNameFree.YoyoCmsTemplate)进行修改项目名称
准备update-database 指令生成数据库,报错如下:
System.Exception: Could not find root folder of the web project!
at YY.Frame.AbpCore.Web.WebContentDirectoryFinder.CalculateContentRootFolder() in G:\ABP Core\Github\LTMCompanyNameFree.YoyoCmsTemplate-master(abp4.0.2)\src\aspnet-core\src\YY.Frame.AbpCore.Core\Web\WebContentFolderHelper.cs:line 46
at YY.Frame.AbpCore.EntityFrameworkCore.YoyoCmsTemplateDbContextFactory.CreateDbContext(String[] args) in G:\ABP Core\Github\LTMCompanyNameFree.YoyoCmsTemplate-master(abp4.0.2)\src\aspnet-core\src\YY.Frame.AbpCore.EntityFrameworkCore\EntityFrameworkCore\YoyoCmsTemplateDbContextFactory.cs:line 15
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not find root folder of the web project!
仔细看报错信息
调用var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());这地方抛出的
CalculateContentRootFolder
{
var coreAssemblyDirectoryPath = Path.GetDirectoryName(typeof(YoyoCmsTemplateCoreModule).GetAssembly().Location);
if (coreAssemblyDirectoryPath == null)
{
throw new Exception("Could not find location of YY.Frame.AbpCore.Core assembly!");
}
{
if (directoryInfo.Parent == null)
{
throw new Exception("Could not find content root folder!");
}
}
if (Directory.Exists(webMvcFolder))
{
return webMvcFolder;
}
if (Directory.Exists(webHostFolder))
{
return webHostFolder;
}
}
看完上面代码,把目录抛出来看看
不难发现dll都生成在netcoreapp2.1 目录下,并没有在src文件夹
解决方法把CalculateContentRootFolder方法中src目录去掉
public static string CalculateContentRootFolder() { var coreAssemblyDirectoryPath = Path.GetDirectoryName(typeof(YoyoCmsTemplateCoreModule).GetAssembly().Location); if (coreAssemblyDirectoryPath == null) { throw new Exception("Could not find location of YY.Frame.AbpCore.Core assembly!"); } var directoryInfo = new DirectoryInfo(coreAssemblyDirectoryPath); // throw new Exception(directoryInfo.FullName); while (!DirectoryContains(directoryInfo.FullName, "YY.Frame.AbpCore.sln")) { if (directoryInfo.Parent == null) { throw new Exception("Could not find content root folder!"); } directoryInfo = directoryInfo.Parent; } var webMvcFolder = Path.Combine(directoryInfo.FullName, "", "YY.Frame.AbpCore.Web.Mvc"); if (Directory.Exists(webMvcFolder)) { return webMvcFolder; } var webHostFolder = Path.Combine(directoryInfo.FullName, "", "YY.Frame.AbpCore.Web.Host"); if (Directory.Exists(webHostFolder)) { return webHostFolder; } throw new Exception("Could not find root folder of the web project!"); }
正常可以生成迁移文件
posted on 2018-12-07 14:17 Martin cheng 阅读(615) 评论(1) 编辑 收藏 举报