title: Set a global property inside MSbuild target
body: <p>I have a MSBuild project where I need to  perform different prepare operations ,build some solutions from a list ,perform some final operations.
  If a solution fails –send an email (write a message)about this .
  If at least one solution failed –the whole process is considered as failed and I send an email (write a message) about this.
  In order to achieve this I use target batching on SolutionsToBuild item group .
  I check the result of each compilation and store it in CurrentSolutionBuildResult .
  Then my idea is to have a global property BuildSucceded with default value set to true.
  In case a solution fails inside the target BuildAllSolutions–I set this property to false so at the end of the target MainTarget I can check it and write the message with build failure or build success.
  Unfortunately at the end of the main target I get the message:</p>
  
  <p>After building all the solutions -BuildSucceded is:'true'
    Build successful!</p>
  
  <p>Although I expected to have this property set to false as it was done in each iteration for target BuildAllSolutions:</p>
  
  <p>Build for C:\SampleSolution\SampleSolution3.sln failed!
     BuildSucceded in target BuildAllSolutions is:'false'</p>
  
  <p>After searching on this site I found the reason:
  <a href="https://stackoverflow.com/questions/7534390/msbuild-property-scope">MSBuild Property Scope</a>
  but still do not know how to solve this issue (marking the whole process as failed or successful) as I cannot use DependsOnTargets workaround (I want BuildAllSolutions target not to be executed at the beginning but after some other operations are performed).
  Below is the code ,maybe someone could advise me how to achieve what I need…
  Thanks</p>
  
  <pre><code>&lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"  ToolsVersion="4.0" DefaultTargets="MainTarget"&gt;
  &lt;PropertyGroup&gt;
    &lt;BuildSucceded&gt;true&lt;/BuildSucceded&gt;
  &lt;/PropertyGroup&gt;
  
  &lt;ItemGroup&gt;
    &lt;SolutionsToBuild Include="C:\SampleSolution\SampleSolution1.sln" /&gt;
    &lt;SolutionsToBuild Include="C:\SampleSolution\SampleSolution2.sln" /&gt;
    &lt;SolutionsToBuild Include="C:\SampleSolution\SampleSolution3.sln" /&gt;
  &lt;/ItemGroup&gt;
  
   &lt;Target Name="BuildAllSolutions" Outputs="%(SolutionsToBuild.Identity)"&gt;
     &lt;Message Text="Building solution '%(SolutionsToBuild.Identity) " /&gt;
  
    &lt;MSBuild Projects="%(SolutionsToBuild.Identity) " Properties="Configuration=Debug" ContinueOnError="ErrorAndContinue"/&gt;
  
     &lt;PropertyGroup&gt;
       &lt;CurrentSolutionBuildResult&gt;$(MSBuildLastTaskResult)&lt;/CurrentSolutionBuildResult&gt;
       &lt;BuildSucceded Condition="'$(CurrentSolutionBuildResult)' == 'false' " &gt;false&lt;/BuildSucceded&gt;
     &lt;/PropertyGroup&gt;
  
     &lt;Message Text="Build for %(SolutionsToBuild.Identity) failed!" Condition="'$(CurrentSolutionBuildResult)' == 'false'"/&gt;
     &lt;Message Text="Build for %(SolutionsToBuild.Identity) succeded!" Condition="'$(CurrentSolutionBuildResult)' != 'false'"/&gt;
  
     &lt;Message Text=" BuildSucceded in target BuildAllSolutions is:'$(BuildSucceded)'"/&gt;
  
  
   &lt;/Target&gt;
  
  
    &lt;Target Name="MainTarget" &gt;
  
    &lt;Message Text="Different start operations in MainTarget" /&gt;
  
    &lt;Message Text=" Before building all the solutions -BuildSucceded is:'$(BuildSucceded)'"/&gt;   
  
    &lt;CallTarget Targets="BuildAllSolutions"  ContinueOnError="ErrorAndContinue" /&gt;
  
     &lt;Message Text="Different end operations in MainTarget" /&gt;
  
    &lt;Message Text=" After building all the solutions -BuildSucceded is:'$(BuildSucceded)'"/&gt;
    &lt;Message Text=" Build successful!" Condition=" '$(BuildSucceded)' != 'false' "/&gt;
    &lt;Message Text=" Build failed!" Condition=" '$(BuildSucceded)' == 'false' "/&gt;
  
  
    &lt;/Target&gt;
  
  &lt;/Project&gt;
  </code></pre>