0

I have a custom pubxml file which contains a Target that executes a powershell script. This powershell command successfully runs before my site is deployed.

If an error occurs in the powershell script, the output is put in the Output window, but the build continues and the final message will be Publish: 1 succeeded. How can I stop the publish if my powershell script errors?

<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>

1 Answer 1

0

It's obvious!

If your powershell script returns an exit code, the error will prevent the publish. Simply catch your powershell exceptions and return the exit command:

Try
{
    # Script goes here
}
Catch
{
   # Custom output or choice of error code number goes here
   exit 1
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.