2016-02-28 27 views
0

我有一個自定義的pubxml文件,其中包含一個執行PowerShell腳本的目標。這個powershell命令在我的網站部署之前成功運行。如何將pubxml文件中的PowerShell錯誤重定向到錯誤窗口

如果在powershell腳本中發生錯誤,輸出將被放入輸出窗口,但構建繼續,最終的消息將爲Publish:1成功。如果我的PowerShell腳本錯誤,我該如何停止發佈?

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<PropertyGroup> 
    <PipelineDependsOn> 
     CopyConfigFiles; 
     $(PipelineDependsOn); 
    </PipelineDependsOn> 
    <WebPublishMethod>FileSystem</WebPublishMethod> 
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> 
    <LastUsedPlatform>Any CPU</LastUsedPlatform> 
    <SiteUrlToLaunchAfterPublish /> 
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> 
    <ExcludeApp_Data>False</ExcludeApp_Data> 
    <publishUrl></publishUrl> 
    <DeleteExistingFiles>False</DeleteExistingFiles> 
</PropertyGroup> 
<Target Name="CopyConfigFiles"> 
    <Message Text="********************************** Deploying Config Files ***********************************" Importance="high"/> 
    <Exec Command="powershell.exe -ExecutionPolicy ByPass -File &quot;$(SolutionDir)/Config/CopyConfigFiles.ps1&quot; -ConfigSource &quot;$(SolutionDir)/Config/&quot;"/> 
</Target> 

回答

0

很明顯!

如果您的powershell腳本返回退出代碼,則該錯誤將阻止發佈。簡單地捕捉你的PowerShell異常並返回退出命令:

Try 
{ 
    # Script goes here 
} 
Catch 
{ 
    # Custom output or choice of error code number goes here 
    exit 1 
} 
相關問題