title: How to add and compile for custom 'Platform' switch for visual studio projects?
body: <p>We are looking to provide two <strong>custom Platform switches</strong> (the <strong>platform dropdown</strong> in the configuration manager) for our projects <strong>in Visual Studio</strong>. </p>
  
  <p>For example one for 'Desktop' and one for 'Web'. The target build tasks then compile the code in a custom way based on the platform switch. We don't want to add to the Debug Release switch because we would need those for each Desktop and Web platforms.</p>
  
  <p>We found one way to attempt this, is to modify the .csproj file to add something like this</p>
  
  <pre><code>&lt;Platform Condition=" '$(Platform)' == '' "&gt;Desktop&lt;/Platform&gt;
  </code></pre>
  
  <p>and add propertygroups like,</p>
  
  <pre><code>    &lt;PropertyGroup Condition=" '$(Platform)' == 'Web' "&gt;
          &lt;DefineConstants&gt;/define Web&lt;/DefineConstants&gt;
          &lt;PlatformTarget&gt;Web&lt;/PlatformTarget&gt;
        &lt;/PropertyGroup&gt;
        &lt;PropertyGroup Condition=" '$(Platform)' == 'Desktop' "&gt;
          &lt;DefineConstants&gt;/define Desktop&lt;/DefineConstants&gt;
          &lt;PlatformTarget&gt;Desktop&lt;/PlatformTarget&gt;
        &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>But still this doesn't work, and compiler throws an error</p>
  
  <p><em>Invalid option 'Desktop' for /platform; must be anycpu, x86, Itanium or x64</em></p>
  
  <p>So does it have to be one of those options and can't we add our custom platforms?</p>
  
  <p>Has anyone been able to do this? any pointers would be helpful.</p>
  
  <p>Update: Using DebugDesktop and ReleaseDesktop will make it more complicated for users. Because 'desktop' and 'web' are actually platforms and also there is ability to add new platforms in the dropdown (i.e. ), I believe 'platform' switch should be used for the exact same purpose.</p>