title: How to get build to fail when running bcp from an msbuild script?
body: <p>As part of sql server 2005, there is the bulk copy command "bcp.exe" (<a href="http://msdn.microsoft.com/en-us/library/ms162802%28SQL.90%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms162802%28SQL.90%29.aspx</a>)</p>
  
  <p>We are running the bcp command from our msbuild script using the exec task.  Unfortunately, when bcp fails to load a row of data, the build still succeeds.</p>
  
  <p>I tried (per build script snippet below) specifying an error file, and checking for its existence, unfortunately that means the build always fails even if bcp completely succeeds, because it appears that bcp will always create the error file even if there are no errors.</p>
  
  <pre><code>&lt;ItemGroup&gt;
    &lt;bcpFiles Include="$(DataPath)\*.txt" /&gt;
  &lt;/ItemGroup&gt;
  &lt;Delete Files="BcpErrors.txt" /&gt;
  &lt;Message Text="bcp $(DatabaseName).dbo.%(bcpFiles.FileName) in %(bcpFiles.FullPath) -eBcpErrors.txt -c -E -q -t&amp;quot;`&amp;quot; -r&amp;quot;`\n&amp;quot; $(bcpConnectionString)" /&gt;
  &lt;Exec Command="bcp $(DatabaseName).dbo.%(bcpFiles.FileName) in %(bcpFiles.FullPath) -eBcpErrors.txt -c -E -q -t&amp;quot;`&amp;quot; -r&amp;quot;`\n&amp;quot; $(bcpConnectionString)" /&gt;
  &lt;Error Condition="Exists('BcpErrors.txt')" Text="One or more bcp commands contained errors." /&gt;
  </code></pre>
  
  <p>Is there any way I can get msbuild to fail the build if bcp fails to load any of the data?</p>