TFSBuild - 数据库部署 - 存在文件锁定冲突
我继承了一个系统,该系统需要将 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.TSqlTasks.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.TSqlTasks.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加 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