TFSBuild - 数据库部署 - 存在文件锁定冲突

发布于 2024-12-10 14:31:46 字数 1740 浏览 0 评论 0原文

我继承了一个系统,该系统需要将 dbschema 部署到多个数据库(每个客户端一个),并设置每晚构建以将更改部署到我的开发层(下面的示例)。大约 50% 的情况下它工作得很好,但另外 50% 的情况下我会在构建过程中的某个地方遇到错误:

“d:\builds{Project}\Dev Nightly Database Update\BuildType\TFSBuild.proj”(EndToEndIteration 目标)(1) -> “d:\builds{Project}\Dev Nightly Database Update\Sources\Database\Database.dbproj”(重建;部署目标)(3:18) -> (DspDeploy 目标)-> C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTask​​s.targets(120,5):错误 MSB4018:“SqlDeployTask”任务意外失败。 [d:\builds{Project}\Dev Nightly Database Update\Sources\Database\Database.dbproj] C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTask​​s.targets(120,5):错误 MSB4018:存在文件锁定冲突。关闭所有使用该数据库文件的外部应用程序。 [d:\builds{Project}\Dev Nightly Database Update\Sources\Database\Database.dbproj]

我环顾四周,但没有找到任何真正的解决方案。我认为我收到错误是因为在下一次迭代启动时 msbuild 仍在使用 dbproj 文件。我尝试将睡眠任务作为最后的努力,但这根本没有帮助。

还有其他建议吗?

<Target Name="Client DB Deploy" Outputs="%(Database.Name)">
<MSBuild Projects="$(SolutionRoot)\Database\Database.dbproj"
   Properties="Configuration=Default; OutDir=$(BinariesRoot)\$(Configuration)\;  
          DeployToDatabase=True;TargetDatabase=%(Database.Name);
          TargetConnectionString=Data Source=$(DatabaseServer)%3BIntegrated Security=True;
          AlwaysCreateNewDatabase=False;BlockIncrementalDeploymentIfDataLoss=False"
   Targets="Rebuild;Deploy"  />
<Copy SourceFiles="$(OutDir)..\Database.sql" DestinationFolder="$(OutDir)_SetupPackages\_Database\%(Database.Name)" />
<SleepTask Timeout="10000" /> <!--sleep the build to try and avoid file locks we get in the loop-->

I have inherited a system that requires a dbschema to be deployed to multiple databases (one per client) and set up a nightly build to deploy changes to my dev tier (sample below). About 50% of the time it works great, but the other 50% I get an error somewhere in the middle of the build:

"d:\builds{Project}\Dev Nightly Database Update\BuildType\TFSBuild.proj" (EndToEndIteration target) (1) ->
"d:\builds{Project}\Dev Nightly Database Update\Sources\Database\Database.dbproj" (Rebuild;Deploy target) (3:18) ->
(DspDeploy target) ->
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): error MSB4018: The "SqlDeployTask" task failed unexpectedly. [d:\builds{Project}\Dev Nightly Database Update\Sources\Database\Database.dbproj]
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): error MSB4018: There is a file locking violation. Close any external application that uses the database file. [d:\builds{Project}\Dev Nightly Database Update\Sources\Database\Database.dbproj]

I have looked around but not found any real solutions. I assume that I am getting the error because msbuild is still using the dbproj file when the next iteration starts up. I tried putting a Sleep task in as a last ditch effort but that hasn't helped at all.

Any other suggestions?

<Target Name="Client DB Deploy" Outputs="%(Database.Name)">
<MSBuild Projects="$(SolutionRoot)\Database\Database.dbproj"
   Properties="Configuration=Default; OutDir=$(BinariesRoot)\$(Configuration)\;  
          DeployToDatabase=True;TargetDatabase=%(Database.Name);
          TargetConnectionString=Data Source=$(DatabaseServer)%3BIntegrated Security=True;
          AlwaysCreateNewDatabase=False;BlockIncrementalDeploymentIfDataLoss=False"
   Targets="Rebuild;Deploy"  />
<Copy SourceFiles="$(OutDir)..\Database.sql" DestinationFolder="$(OutDir)_SetupPackages\_Database\%(Database.Name)" />
<SleepTask Timeout="10000" /> <!--sleep the build to try and avoid file locks we get in the loop-->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光是把杀猪刀 2024-12-17 14:31:46

尝试添加 MSBuild 任务参数 RunEachTargetSeparately="True" 或 UnloadProjectsOnCompletion="True"。请参阅 http://msdn.microsoft.com/en-us/library/z7f65y0d。 ASPX

Try to add MSBuild task parameters RunEachTargetSeparately="True" or UnloadProjectsOnCompletion="True". See http://msdn.microsoft.com/en-us/library/z7f65y0d.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文