title: MSBuild Validating Properties
body: <p>I'm working on a reusable MSBuild Target that will be consumed by several other tasks. This target requires that several properties be defined. What's the best way to validate that properties are defined, throwing an Error if the are not?</p>
  
  <p>Two attempts that I <em>almost</em> like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
    &lt;Project ToolsVersion="3.5" DefaultTarget="Release" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
  
    &lt;Target Name="Release"&gt;
      &lt;Error
        Text="Property PropA required"
        Condition="'$(PropA)' == ''"/&gt;
      &lt;Error
        Text="Property PropB required"
        Condition="'$(PropB)' == ''"/&gt;
  
      &lt;!-- The body of the task --&gt;
  
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>Here's an attempt at batching. It's ugly because of the extra "Name" parameter. Is it possible to use the Include attribute instead?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Project ToolsVersion="3.5" DefaultTarget="Release" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;Target Name="Release"&gt;
      &lt;!-- MSBuild BuildInParallel="true" Projects="@(ProjectsToBuild)"/ --&gt;
      &lt;ItemGroup&gt;
        &lt;RequiredProperty Include="PropA"&gt;&lt;Name&gt;PropA&lt;/Name&gt;&lt;/RequiredProperty&gt;
        &lt;RequiredProperty Include="PropB"&gt;&lt;Name&gt;PropB&lt;/Name&gt;&lt;/RequiredProperty&gt;
        &lt;RequiredProperty Include="PropC"&gt;&lt;Name&gt;PropC&lt;/Name&gt;&lt;/RequiredProperty&gt;
      &lt;/ItemGroup&gt;
  
      &lt;Error
        Text="Property %(RequiredProperty.Name) required"
        Condition="'$(%(RequiredProperty.Name))' == ''" /&gt;
  
    &lt;/Target&gt;
  
  &lt;/Project&gt;
  </code></pre>