发布/部署期间EF Core RC2迁移失败

时间:2016-06-08 08:09:06

标签: asp.net asp.net-core entity-framework-core webdeploy ef-migrations

为小型测试ASP.NET Core MVC项目运行发布时,我遇到一些自动运行针对实时数据库的迁移的困难。

如果我同时发布设置/数据库/默认连接/在运行时使用此连接字符串并且未选中设置/数据库/实体框架迁移/ ApplicationDbContext ,则该网站会发布很好,但正如预期的那样,数据库保持不变。

如果我使用设置/数据库/默认连接/在运行时使用此连接字符串进行发布,则会将我的整个开发数据库复制到实时服务器,包括所有数据。绝对不是我需要的。

如果我发布了设置/数据库/实体框架迁移/ ApplicationDbContext ,则会收到以下错误:

Configuring the following project for use with IIS: 'C:\Users\User\AppData\Local\Temp\PublishTemp\TestProject57'
Updating web.config at 'C:\Users\User\AppData\Local\Temp\PublishTemp\TestProject57\web.config'
Configuring project completed successfully
publish: Published to C:\Users\User\AppData\Local\Temp\PublishTemp\TestProject57
Published 1/1 projects successfully
Publishing with publish method [MSDeploy]
Executing command ["C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:manifest='C:\Users\User\AppData\Local\Temp\PublishTemp\obj\SourceManifest.xml' -dest:manifest='C:\Users\User\AppData\Local\Temp\PublishTemp\obj\DestManifest.xml',ComputerName='https://xxx:8172/msdeploy.axd',UserName='xxx',Password='{PASSWORD-REMOVED-FROM-LOG}',IncludeAcls='False',AuthType='Basic' -verb:sync -enablerule:AppOffline -retryAttempts:20 -allowUntrusted]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error : Error: (08/06/2016 08:29:36) An error occurred when the request was processed on the remote computer.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error : Error: Could not find a part of the path 'C:\Users\User\AppData\Local\Temp\PublishTemp\obj\TestProject.Models.Database.ApplicationDbContext.sql'.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.NativeMethods.RaiseIOExceptionFromErrorCode(Win32ErrorCode errorCode, String maybeFullPath)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.FileStreamEx.CreateInstance(String path, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, Nullable`1 fileLength)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.ReadWriteScriptFileProvider.GetFileStream()
Info: Using ID 'xxx' for connections to the remote server.
Info: Adding child sitemanifest (C:\Users\User\AppData\Local\Temp\PublishTemp\obj\TestProject.Models.Database.ApplicationDbContext.sql).
Info: Using ID 'xxx' for connections to the remote server.
Info: Updating file (TestProject\web.config).
Info: Updating file (TestProject\wwwroot\css\site.min.css).
Info: Adding child sitemanifest (C:\Users\User\AppData\Local\Temp\PublishTemp\obj\TestProject.Models.Database.ApplicationDbContext.sql).
Info: Adding database (sitemanifest/dbFullSql[@path='C:\Users\User\AppData\Local\Temp\PublishTemp\obj\TestProject.Models.Database.ApplicationDbContext.sql']/sqlScript)

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.ReadWriteScriptFileProvider.Add(DeploymentObject source, Boolean whatIf)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentObject.AddChild(DeploymentObject source, Int32 position, DeploymentSyncContext syncContext)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentSyncContext.HandleAddChild(DeploymentObject destParent, DeploymentObject sourceObject, Int32 position)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentSyncContext.SyncChildrenOrder(DeploymentObject dest, DeploymentObject source)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentSyncContext.HandleAddChild(DeploymentObject destParent, DeploymentObject sourceObject, Int32 position)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentSyncContext.SyncChildrenOrder(DeploymentObject dest, DeploymentObject source)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentSyncContext.ProcessSync(DeploymentObject destinationObject, DeploymentObject sourceObject)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentObject.SyncToInternal(DeploymentObject destObject, DeploymentSyncOptions syncOptions, PayloadTable payloadTable, ContentRootTable contentRootTable, Nullable`1 syncPassId, String syncSessionId)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error :    at Microsoft.Web.Deployment.DeploymentAgent.HandleSync(DeploymentAgentAsyncData asyncData, Nullable`1 passId, String user, String siteName)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(406,5): Error : Error count: 1.

1>Publish failed due to build errors. Check the error list for more details.

如果点击发布对话框的预览标签下的实体框架迁移下的预览迁移,一切都会完美运行,复制生成的SQL迁移然后针对服务器手动运行它。此外,一旦正确应用了迁移,应用程序本身就可以完美运行 - 失败的时刻特别是当发布过程尝试应用迁移时。

我的连接字符串也是相同的,因为开发和实时都有一个具有相同名称的数据库并使用集成安全性,因为在我手动运行迁移后网站正常工作,必须正确配置。

我真正想做的是在运行设置/数据库/实体框架迁移/ ApplicationDbContext 的情况下查看错误的底部,因为我很确定这是我的选项想。这个错误听起来像是在尝试使用我的开发机器本地路径在服务器上运行SQL文件,但我很难过。

1 个答案:

答案 0 :(得分:1)

这是使用EF迁移进行发布的preview1工具中的一个问题。这已得到修复 - https://github.com/aspnet/vsweb-publish/commit/b46d54f74d7298e65dde1622bda340af3b23713f

要解决此问题: 1.将工具更新为Preview2版本。如果您已经有publishprofile和ps1文件,请删除ps1文件并发布。这将降低ps1的新版本。 https://go.microsoft.com/fwlink/?LinkId=817245 2.复制此文件的内容 https://raw.githubusercontent.com/aspnet/vsweb-publish/master/publish-module.psm1到C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Web Tools \ Publish \ Scripts \ 1.1.0 \ publish-module.psm1 (基于安装的工具,它将是1.1.0或1.2.0。)

这应该可以解决问题。 详细介绍使用EF迁移将ASP.NET核心应用程序发布到App Service https://dotnetpublish.wordpress.com/2016/07/05/publish-an-asp-net-core-web-app-with-ef-migrations-to-azure-appservice/