From c9d0e0e0bcbb8ad63ffa7624ebddc4dfe8ee0984 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?=
 <cesar.zaragoza@outlook.com>
Date: Wed, 12 Aug 2020 20:48:07 -0700
Subject: [PATCH 1/4] Get qsc command exit code.

---
 src/QuantumSdk/Sdk/Sdk.targets | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/QuantumSdk/Sdk/Sdk.targets b/src/QuantumSdk/Sdk/Sdk.targets
index 436cd9a4ea..1cff0af87b 100644
--- a/src/QuantumSdk/Sdk/Sdk.targets
+++ b/src/QuantumSdk/Sdk/Sdk.targets
@@ -114,7 +114,10 @@
     <PropertyGroup>
       <QscCommand>$(QscExe) build --format MsBuild $(_VerbosityFlag) --response-files @(QscCommandArgsFile)</QscCommand>
     </PropertyGroup>
-    <Exec Command="$(QscCommand)" IgnoreExitCode="false" /> 
+    <Exec Command="$(QscCommand)" IgnoreExitCode="false" > 
+      <Output TaskParameter="ExitCode" PropertyName="QscExitCode"/>
+    </Exec>
+    <Message Importance="high" Text="Qsc command exit code: $(QscExitCode)"/>
   </Target>
 
   <!-- Configures the dll built by the C# compiler. This target needs to execute during the C# design time build to get accurate intellisense information for (non-generate) C# source files. -->

From 0f21f24a49a3316fab9ccf7f27eacebfb91f70c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?=
 <cesar.zaragoza@outlook.com>
Date: Thu, 13 Aug 2020 10:41:45 -0700
Subject: [PATCH 2/4] Delete bson file when qsc command fails.

---
 src/QuantumSdk/Sdk/Sdk.targets | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/QuantumSdk/Sdk/Sdk.targets b/src/QuantumSdk/Sdk/Sdk.targets
index 1cff0af87b..baa7f4b71d 100644
--- a/src/QuantumSdk/Sdk/Sdk.targets
+++ b/src/QuantumSdk/Sdk/Sdk.targets
@@ -114,10 +114,11 @@
     <PropertyGroup>
       <QscCommand>$(QscExe) build --format MsBuild $(_VerbosityFlag) --response-files @(QscCommandArgsFile)</QscCommand>
     </PropertyGroup>
-    <Exec Command="$(QscCommand)" IgnoreExitCode="false" > 
+    <Exec Command="$(QscCommand)" IgnoreExitCode="false" ContinueOnError="ErrorAndContinue"> 
       <Output TaskParameter="ExitCode" PropertyName="QscExitCode"/>
     </Exec>
     <Message Importance="high" Text="Qsc command exit code: $(QscExitCode)"/>
+    <Delete Condition="'$(QscExitCode)' != '0'" Files="$(GeneratedFilesOutputPath)$(PathCompatibleAssemblyName).bson" />
   </Target>
 
   <!-- Configures the dll built by the C# compiler. This target needs to execute during the C# design time build to get accurate intellisense information for (non-generate) C# source files. -->

From b1d6177fab946ae7a8e485b58f9b9f89bfd22b80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?=
 <cesar.zaragoza@outlook.com>
Date: Thu, 13 Aug 2020 12:37:12 -0700
Subject: [PATCH 3/4] Fail build when qsc fails.

---
 src/QuantumSdk/Sdk/Sdk.targets | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/QuantumSdk/Sdk/Sdk.targets b/src/QuantumSdk/Sdk/Sdk.targets
index baa7f4b71d..446f9b893e 100644
--- a/src/QuantumSdk/Sdk/Sdk.targets
+++ b/src/QuantumSdk/Sdk/Sdk.targets
@@ -117,8 +117,9 @@
     <Exec Command="$(QscCommand)" IgnoreExitCode="false" ContinueOnError="ErrorAndContinue"> 
       <Output TaskParameter="ExitCode" PropertyName="QscExitCode"/>
     </Exec>
-    <Message Importance="high" Text="Qsc command exit code: $(QscExitCode)"/>
+    <Message Importance="low" Text="Qsc command exit code: $(QscExitCode)"/>
     <Delete Condition="'$(QscExitCode)' != '0'" Files="$(GeneratedFilesOutputPath)$(PathCompatibleAssemblyName).bson" />
+    <Error Text="Qsc command failed with exit code: $(QscExitCode)." Condition="'$(QscExitCode)' != '0'" />
   </Target>
 
   <!-- Configures the dll built by the C# compiler. This target needs to execute during the C# design time build to get accurate intellisense information for (non-generate) C# source files. -->

From 09f8e9deea55f67947b69fa092244917d757e7fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?=
 <cesar.zaragoza@outlook.com>
Date: Mon, 17 Aug 2020 10:08:56 -0700
Subject: [PATCH 4/4] Update src/QuantumSdk/Sdk/Sdk.targets

Co-authored-by: Andres Paz <anpaz@microsoft.com>
---
 src/QuantumSdk/Sdk/Sdk.targets | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/QuantumSdk/Sdk/Sdk.targets b/src/QuantumSdk/Sdk/Sdk.targets
index 446f9b893e..3c5372b13b 100644
--- a/src/QuantumSdk/Sdk/Sdk.targets
+++ b/src/QuantumSdk/Sdk/Sdk.targets
@@ -119,7 +119,7 @@
     </Exec>
     <Message Importance="low" Text="Qsc command exit code: $(QscExitCode)"/>
     <Delete Condition="'$(QscExitCode)' != '0'" Files="$(GeneratedFilesOutputPath)$(PathCompatibleAssemblyName).bson" />
-    <Error Text="Qsc command failed with exit code: $(QscExitCode)." Condition="'$(QscExitCode)' != '0'" />
+    <Error Text="Q# compiler failed with exit code: $(QscExitCode)." Condition="'$(QscExitCode)' != '0'" />
   </Target>
 
   <!-- Configures the dll built by the C# compiler. This target needs to execute during the C# design time build to get accurate intellisense information for (non-generate) C# source files. -->
@@ -144,4 +144,3 @@
   </Target>  
 
 </Project>
-
