InvokeProcess в сборке TFS2010 не выдает ошибок при запуске sqlcmd - PullRequest
1 голос
/ 29 ноября 2011

Я использую задачу InvokeProcess для запуска SqlCmd, чтобы выполнить сценарий sql для базы данных.Тем не менее, если в сценарии sql обнаружены ошибки, ошибки не возникают, и состояние сборки не устанавливается равным false, как указано в XAML.Что может случиться?Вот фрагмент кода:

<mtbwa:InvokeProcess Arguments="[&quot;-b -S server1\dev -U sa -P password -i &quot;&quot;&quot; + SourcesDirectory + &quot;\DatabaseScripts\conversion.sql&quot;&quot;&quot;]" DisplayName="Run Conversion SQL" FileName="c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" sap:VirtualizedContainerService.HintSize="464,384" Result="[ExitCode]" WorkingDirectory="[SourcesDirectory]">
<mtbwa:InvokeProcess.ErrorDataReceived>
    <ActivityAction x:TypeArguments="x:String">
        <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="x:String" Name="errOutput" />
        </ActivityAction.Argument>
        <Sequence sap:VirtualizedContainerService.HintSize="222,208">
            <sap:WorkflowViewStateService.ViewState>
            <scg:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
            </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <mtbwa:WriteBuildError DisplayName="VSDBCMD Error" sap:VirtualizedContainerService.HintSize="200,22" Message="[errOutput]" />
            <mtbwa:SetBuildProperties DisplayName="Set build to failed" sap:VirtualizedContainerService.HintSize="200,22" PropertiesToSet="Status" Status="[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]" />
        </Sequence>
    </ActivityAction>
</mtbwa:InvokeProcess.ErrorDataReceived>
<mtbwa:InvokeProcess.OutputDataReceived>
    <ActivityAction x:TypeArguments="x:String">
        <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="x:String" Name="stdOutput" />
        </ActivityAction.Argument>
        <mtbwa:WriteBuildMessage sap:VirtualizedContainerService.HintSize="222,22" Message="[stdOutput]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
    </ActivityAction>
</mtbwa:InvokeProcess.OutputDataReceived>
<sap:WorkflowViewStateService.ViewState>
    <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsPinned">False</x:Boolean>
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
    </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>

1 Ответ

0 голосов
/ 30 ноября 2011

Оказывается, sqlcmd не возвращает коды ошибок. Я решил проанализировать выходные данные команды в поисках строки ошибки и выдать исключение, если оно было найдено. Вот фрагмент:

<mtbwa:InvokeProcess Arguments="[&quot;-b -S myServer\dev -U sa -P password -i &quot;&quot;&quot; + SourcesDirectory + &quot;\DatabaseScripts\conversion.sql&quot;&quot;&quot;]" DisplayName="Run Conversion SQL" FileName="c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" sap:VirtualizedContainerService.HintSize="464,599" Result="[ExitCode]" WorkingDirectory="[SourcesDirectory]">
<mtbwa:InvokeProcess.ErrorDataReceived>
    <ActivityAction x:TypeArguments="x:String">
    <ActivityAction.Argument>
    <DelegateInArgument x:TypeArguments="x:String" Name="errOutput" />
    </ActivityAction.Argument>
    <Sequence sap:VirtualizedContainerService.HintSize="222,208">
    <sap:WorkflowViewStateService.ViewState>
    <scg:Dictionary x:TypeArguments="x:String, x:Object">
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
    </scg:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <mtbwa:WriteBuildError DisplayName="VSDBCMD Error" sap:VirtualizedContainerService.HintSize="200,22" Message="[errOutput]" />
    <mtbwa:SetBuildProperties DisplayName="Set build to failed" sap:VirtualizedContainerService.HintSize="200,22" PropertiesToSet="Status" Status="[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]" />
    </Sequence>
    </ActivityAction>
</mtbwa:InvokeProcess.ErrorDataReceived>
<mtbwa:InvokeProcess.OutputDataReceived>
    <ActivityAction x:TypeArguments="x:String">
        <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="x:String" Name="stdOutput" />
        </ActivityAction.Argument>
        <Sequence sap:VirtualizedContainerService.HintSize="222,237">
        <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
        </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <mtbwa:WriteBuildMessage sap:VirtualizedContainerService.HintSize="200,22" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[stdOutput]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
        <If Condition="[stdOutput.Contains(&quot;The statement has been terminated.&quot;)]" sap:VirtualizedContainerService.HintSize="200,51">
        <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">False</x:Boolean>
        <x:Boolean x:Key="IsPinned">False</x:Boolean>
        </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <If.Then>
        <Sequence sap:VirtualizedContainerService.HintSize="281,208">
        <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
        </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <mtbwa:SetBuildProperties DisplayName="Set build to failed" sap:VirtualizedContainerService.HintSize="200,22" PropertiesToSet="Status" Status="[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]" />
        <Throw Exception="[New Exception(&quot;Conversion.sql failed&quot;)]" sap:VirtualizedContainerService.HintSize="200,22" />
        </Sequence>
        </If.Then>
        </If>
        </Sequence>
    </ActivityAction>
</mtbwa:InvokeProcess.OutputDataReceived>
<sap:WorkflowViewStateService.ViewState>
    <scg:Dictionary x:TypeArguments="x:String, x:Object">
    <x:Boolean x:Key="IsPinned">False</x:Boolean>
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
    </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...