title: Unable To Set Application Property Using MSbuild.exe
body: <p>If I go to Project-&gt;MyApp-&gt;Properties-&gt;Settings and enter Name like WhichApp of type string and enter the Scope as Application and Value of PCB. When I show the value in
  my main form using <code>MessageBox.Show(Properties.Settings.Default.WhichApp);</code> I see a message box showing &quot;PCB&quot;.</p>
  <p>But if I try to set the property using MSBuild.exe -property:WhichApp=SUB when I view the property value I still see &quot;PCB&quot;.</p>
  <p>How can I call the MSBuild.exe compiler tool to set the property at build time?</p>
  <p>I tried used External Tools in Visual Studio..</p>
  <p>Title: Set Property</p>
  <p>Command: C:\Program Files(x86)\Microsoft Visual Studio\2017\WDExpress\MSBuild\15.0\Bin\MSBuild.exe</p>
  <p>Arguments: -property:WhichApp=SUB</p>
  <p>Initial Directory: $(ProjectDir)</p>
  <p>---- WHAT I'M TRY TO ACCOMPLISH IN LOAD() METHOD OF MAIN FORM ----</p>
  <pre><code>if (Properties.Settings.Default.PCAppConfig == &quot;PCB&quot;)
  {
  // create new PCB form
  // PCBForm.ShowDialog();
  }
  else if (Properties.Settings.Default.PCAppConfig == &quot;SUB&quot;)
  {
    // create new SUB form
    // SUBForm.ShowDialog();
  }
  </code></pre>
  <p>--- In solution by jtijn, I tried this to add another property called VersionNum but fails... ---</p>
  <pre><code>&lt;Target Name=&quot;BeforeBuild&quot;&gt;
     &lt;PropertyGroup&gt;
       &lt;!--Default value.--&gt;
       &lt;PcAppConfig Condition=&quot;'$(PcAppConfig)' == ''&quot;&gt;PCB&lt;/PcAppConfig&gt;
       &lt;VersionNum Condition=&quot;'$(VersionNum)' == ''&quot;&gt;1.0.0.66&lt;/VersionNum&gt;
       &lt;!--The source code.--&gt;
       &lt;TheSourceCode&gt;internal static class PcAppConfig{ public static readonly string value = &quot;$(PcAppConfig)&quot;%3B%0A }internal static class VersionNum{ public static readonly string value = &quot;$(VersionNum)&quot;%3B&lt;/TheSourceCode&gt;
     &lt;/PropertyGroup&gt;
     &lt;!--Get current source so we can only create it again when needed, to avoid being recompiled.--&gt;
     &lt;ReadLinesFromFile File=&quot;PcAppConfig.cs&quot; ContinueOnError=&quot;True&quot;&gt;
       &lt;Output TaskParameter=&quot;Lines&quot; ItemName=&quot;CurrentSourceCode&quot; /&gt;
     &lt;/ReadLinesFromFile&gt;
     &lt;!--Write source, if needed.--&gt;
     &lt;WriteLinesToFile File=&quot;PcAppConfig.cs&quot; Overwrite=&quot;True&quot; Lines=&quot;$(TheSourceCode)&quot; Condition=&quot;'@(CurrentSourceCode)' != '$(TheSourceCode)'&quot; /&gt;
   &lt;/Target&gt;
  </code></pre>
  <p>--- Doesn't compile when values are changed, Fails to create setup files ...
  My arguments to MSBuild.exe</p>
  <pre><code>SelectApp.csproj.user /p:PcAppConfig=SUB /p:VersionNum=1.0.0.67
  </code></pre>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;Project ToolsVersion=&quot;Current&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
      &lt;ItemGroup&gt;
          &lt;Compile Update=&quot;Form1.cs&quot;&gt;
              &lt;SubType&gt;Form&lt;/SubType&gt;
          &lt;/Compile&gt;
      &lt;/ItemGroup&gt;
  &lt;Target Name=&quot;BeforeBuild&quot;&gt;
      &lt;PropertyGroup&gt;
          &lt;!--Default value.--&gt;
          &lt;PcAppConfig Condition=&quot;'$(PcAppConfig)' == ''&quot;&gt;PCB&lt;/PcAppConfig&gt;
          &lt;VersionNum Condition=&quot;'$(VersionNum)' == ''&quot;&gt;1.0.0.66&lt;/VersionNum&gt;
          &lt;!--The source code.--&gt;
          &lt;TheSourceCode&gt;internal static class PCAppConfig{ public static readonly string value = &quot;$(PcAppConfig)&quot;%3B }%0Ainternal static class VersionNum{ public static readonly string value = &quot;$(VersionNum)&quot;%3B }&lt;/TheSourceCode&gt;
      &lt;/PropertyGroup&gt;
      &lt;!--Get current source so we can only create it again when needed, to avoid being recompiled.--&gt;
      &lt;ReadLinesFromFile File=&quot;PcAppConfig.cs&quot; ContinueOnError=&quot;True&quot;&gt;
          &lt;Output TaskParameter=&quot;Lines&quot; ItemName=&quot;CurrentSourceCode&quot; /&gt;
      &lt;/ReadLinesFromFile&gt;
      &lt;!--Write source, if needed.--&gt;
      &lt;WriteLinesToFile File=&quot;PcAppConfig.cs&quot; Overwrite=&quot;True&quot; Lines=&quot;$(TheSourceCode)&quot; Condition=&quot;'@(CurrentSourceCode)' != '$(TheSourceCode)'&quot; /&gt;
      &lt;ItemGroup&gt;
          &lt;Compile Update=&quot;PcAppConfig.cs&quot;&gt;
              &lt;SubType&gt;Component&lt;/SubType&gt;
          &lt;/Compile&gt;
      &lt;/ItemGroup&gt;
  &lt;/Target&gt;
  &lt;Target Name=&quot;AfterCompile&quot;&gt;
  &lt;Exec Command=&quot;&amp;quot;$(ProgramFiles)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.com&amp;quot; C:\DummyApps\SelectApp\PCBSetup\PCBSetup.vdproj /build &amp;quot;Debug|AnyCPU&amp;quot;&quot;/&gt;
  &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>