title: How to pass env-var to MSBuild Task and make it effective for all sub-process? (concrete code)
body: <p>I have a question about passing environment variables to <code>MSBuild</code> Task. See my code below:</p>
  <p>a.proj</p>
  <pre><code>&lt;Project xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot; 
      DefaultTargets=&quot;A1&quot;&gt;
      
      &lt;Target Name=&quot;A0&quot;&gt;
          &lt;Message Text=&quot;A0 start.&quot;/&gt;
          &lt;MSBuild Projects=&quot;b.proj&quot; Properties=&quot;myvar=000&quot; /&gt;
          &lt;Message Text=&quot;A0 end.&quot;/&gt;
      &lt;/Target&gt;
  
      &lt;Target Name=&quot;A1&quot; DependsOnTargets=&quot;A0&quot;&gt;
          &lt;Message Text=&quot;A1 start.&quot;/&gt;
          &lt;MSBuild Projects=&quot;b.proj&quot; Properties=&quot;myvar=111&quot; /&gt;
          &lt;Message Text=&quot;A1 end.&quot;/&gt;
      &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  <p>b.proj</p>
  <pre><code>&lt;Project xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
      &lt;Target Name=&quot;B&quot;&gt;
          &lt;Message Text=&quot;B start.&quot;/&gt;
          &lt;Exec command=&quot;c.bat&quot; /&gt;
      &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  <p>c.bat</p>
  <pre><code>echo [C]myvar=%myvar%
  </code></pre>
  <p>I hope that <code>c.bat</code> can see <code>myvar</code>'s value passed from <code>a.proj</code>. My code above failed to do that.</p>
  <p><a href="https://i.stack.imgur.com/Kizrd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kizrd.png" alt="enter image description here" /></a></p>
  <p>Consider(Assume) a running &lt;MSBuild&gt; Task a process on the OS, then, I'd like to pre-set environment variable <code>myvar</code> for that process, so that its subprocesses(no matter how deep) can all see <code>myvar</code>'s value.</p>
  <p>How can I achieve that? Thank you.</p>