c# - TFS 构建 CopyDirectory 错误不停止构建

标签 c# asp.net build tfs build-management

我的构建模板中有一个 CopyDirectory 步骤,我假设如果它找到一个不存在的目录,它会抛出错误。但是,它只是发出警告,并且构建本身被标记为成功。

我尝试将它包裹在 try/catch block 中,并手动执行“抛出”异常步骤,但仍然无效。我试图将 buildStatus 设置为失败,但这也不起作用。还有其他方法可以实现吗?如果任何复制目录失败,我不希望构建成功。

编辑:

这是复制目录所在的片段。我正在遍历服务器列表并复制一堆目录。

<ForEach x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="ForEach`1_4" Values="[SCCDServers]">
                <ActivityAction x:TypeArguments="x:String">
                  <ActivityAction.Argument>
                    <DelegateInArgument x:TypeArguments="x:String" Name="server" />
                  </ActivityAction.Argument>
                  <Sequence sap2010:WorkflowViewState.IdRef="Sequence_37">
                    <mtbwa:CopyDirectory Destination="[server]" DisplayName="Copy Code Files" sap2010:WorkflowViewState.IdRef="CopyDirectory_14" Source="[BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCWebOutputFolder]" />
                    <mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_16" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[&quot;Code Files copied to &quot; &amp; server]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
                    <mtbwa:CopyDirectory Destination="[server]" DisplayName="Copy Config Files" sap2010:WorkflowViewState.IdRef="CopyDirectory_15" Source="[BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCConfigSourceFolder &amp; &quot;\&quot; &amp; SCCDServerRole]" />
                    <mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_17" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[&quot;Config Files copied to &quot; &amp; server &amp; Environment.NewLine &amp; &quot;Copied from: &quot; &amp; BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCConfigSourceFolder &amp; &quot;\&quot; &amp; SCCDServerRole]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
                    <mtbwa:CopyDirectory Destination="[server]" DisplayName="Copy Sitecore Files" sap2010:WorkflowViewState.IdRef="CopyDirectory_16" Source="[BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCSitecoreFilesSourceFolder]" />
                    <mtbwa:WriteBuildMessage sap2010:WorkflowViewState.IdRef="WriteBuildMessage_18" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[&quot;Sitecore Files copied to &quot; &amp; server &amp; Environment.NewLine &amp; &quot;Copied from: &quot; &amp; BuildDetail.DropLocation &amp; &quot;\_PublishedWebsites\&quot; &amp; SCSitecoreFilesSourceFolder]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
                  </Sequence>
                </ActivityAction>
              </ForEach>

最佳答案

CopyDirectory 确实有一个错误,它只会在源目录不存在时发出警告。它还存在长路径问题(>248 个字符)。

可能的解决方法:

  1. 使用InvokeCommand,运行Robocopy.exe(优于xcopy)并检查其结果代码。
  2. 如果您必须使用 CopyDirectory,请自行检查源目录是否存在。

关于c# - TFS 构建 CopyDirectory 错误不停止构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796008/

相关文章:

c# - 隐藏页面 url asp.net

c# - 如何在不同层次的多态类之间保持一对一的关系?

c# - 检测 TextBox 中的 Tab 键按下

c# - 插件和工作流的抽象类

asp.net - 将 asp.net.mvc 添加到 ASP.NET : Controllers folder

react-native - 在react-native运行android时生成错误

android - 使用gradle构建android项目失败

c# - ASP.net 处理程序和通用处理程序之间的区别

asp.net - 如何更改 ASP.NET 标识中的错误消息

c++ - 从文件中读取 SCons 环境设置