2016-02-28 44 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 
} 
相关问题