EF Core RC2迁移在发布/部署期间失败(EF Core RC2 migrations failing during publish/deployment)

编程入门 行业动态 更新时间:2024-10-27 23:30:36
EF Core RC2迁移在发布/部署期间失败(EF Core RC2 migrations failing during publish/deployment)

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

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

如果我使用Settings / Databases / Default Connection /在运行时检查时使用此连接字符串,那么它似乎将我的整个开发数据库复制到实时服务器,包括所有数据。 绝对不是我需要的。

如果我发布了Settings / Databases / Entity Framework Migrations / 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迁移,然后针对服务器手动运行它。 此外,一旦正确应用了迁移,应用程序本身就可以完美运行 - 故障点特别是在发布过程尝试应用迁移时。

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

我真正想做的是在选中Settings / Databases / Entity Framework Migrations / ApplicationDbContext时运行错误的底部,因为我很确定这是我想要的选项。 该错误听起来像是在尝试使用我的开发机器本地路径在服务器上运行SQL文件,但我很难过。

When running a publish for a small test ASP.NET Core MVC project I am having some difficulties automatically running migrations against the live database.

If I publish with both Settings / Databases / Default Connection / Use this connection string at runtime and Settings / Databases / Entity Framework Migrations / ApplicationDbContext unchecked then the site publishes fine, but the database is, as expected, left untouched.

If I publish with Settings / Databases / Default Connection / Use this connection string at runtime checked then it seems to copy my entire development database to the live server, including all of the data. Definitely not what I need.

If I publish with Settings / Databases / Entity Framework Migrations / ApplicationDbContext checked then I receive the following error:

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.

Everything works perfectly if I click Preview Migration under Entity Framework Migrations on the Preview tab of the publish dialog, copy the generated SQL migration and then run it manually against the server. Also, once the migrations have been correctly applied, the application itself runs flawlessly - the point of failure is specifically when the publish process attempts to apply the migrations.

My connection strings are also identical, as both development and live have a database with identical names and use integrated security, which as the site works after I manually run the migrations, must be configured correctly.

What I'd really like to do is get to the bottom of the error when running with Settings / Databases / Entity Framework Migrations / ApplicationDbContext checked, as I'm pretty sure that's the option I want. The error sounds like it's trying to run a SQL file on the server with a path local to my development machine, but I'm stumped.

最满意答案

这是使用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到天青-AppService服务/

This was an issue in the preview1 tooling for Publishing with EF Migrations. This has been fixed - https://github.com/aspnet/vsweb-publish/commit/b46d54f74d7298e65dde1622bda340af3b23713f

To fix this issue: 1. Either update the tooling to Preview2 version. if you already have the publishprofile and ps1 file, delete the ps1 file and publish. This will bring down the newer version of ps1. https://go.microsoft.com/fwlink/?LinkId=817245 2. Copy the contents of this file https://raw.githubusercontent.com/aspnet/vsweb-publish/master/publish-module.psm1 to C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.1.0\publish-module.psm1 (it would be 1.1.0 or 1.2.0 based on the tooling installed.).

This should fix the issue. Detailed walk through of publishing an ASP.NET core app to App Service with EF migration https://dotnetpublish.wordpress.com/2016/07/05/publish-an-asp-net-core-web-app-with-ef-migrations-to-azure-appservice/

更多推荐

本文发布于:2023-07-14 13:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Core   EF   migrations   deployment   publish

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!