text: Q:
  
  Optionally pass argument to MSBuild from powershell
  
  In my Build.proj file, I have the following property:
  <DbName Condition="$(DbName) == ''">MyDB</DbName>
  <ConnectionString Condition="$(ConnectionString) == ''">"Data Source=localhost;Initial Catalog=$(DbName);Integrated Security=SSPI;MultipleActiveResultSets=True"</ConnectionString>
  
  I have a PowerShell function as follows:
  function Update-Database
  {
      param(
          $DbName=""
      )
      msbuild $MSBuildFile /maxcpucount /verbosity:Minimal /target:DatabaseUpdate /p:DbName=$DbName
  }
  
  Running the function in PowerShell I get the following results:
  
  Update-Database MyDB : works perfectly
  Update-Database : Fails.  MSBuild does not use the default 'MyDB' in this case.  Instead it uses ''
  
  If I modify this line:
  msbuild $MSBuildFile /maxcpucount /verbosity:Minimal /target:DatabaseUpdate /p:DbName=$DbName
  
  To this:
  msbuild $MSBuildFile /maxcpucount /verbosity:Minimal /target:DatabaseUpdate
  
  Running "UpdateDatabase" uses the default 'MyDB' and all is well.
  If I want to have the option to use the default or pass in a new value, do I have to wrap the whole msbuild... command in an if else? or is there a way to conditionally pass in the argument?
  UPDATE
  I am trying to avoid setting the default in the ps function.  Basically I want to emulate this behaviour without the if:
  function Update-Database
  {
      param(
          $DbName=""
      )
      if($DbName -eq "")
      {
          msbuild $MSBuildFile /maxcpucount /verbosity:Minimal /target:DatabaseUpdate
      }
      else
      {
          msbuild  $MSBuildFile /maxcpucount /verbosity:Minimal /target:DatabaseUpdate /p:DbName=$DbName
      }
  }
  
  A:
  
  The property you specify in the command line becomes a global property, which will take precedence over what's specified in the file. You can define a new property instead to avoid this behavior, like this:
  <_DbName>$(DbName)</DbName>
  <_DbName Condition="$(_DbName) == ''">MyDB</_DbName>
  <ConnectionString Condition="$(ConnectionString) == ''">"Data Source=localhost;Initial Catalog=$(_DbName);Integrated Security=SSPI;MultipleActiveResultSets=True"</ConnectionString>
  
  