title: How to "Get Latest From Label" when using Nant with PowerShell?
body: <p>I'm writing a PowerShell v5 script to launch our automated NAnt-based build process. I also have a Custom Task (GetLatestFromLabel) written in C#. When I run the build in a DOS command window the build completes successfully however when I run the build process from my PowerShell v5 script it seems to be prepending a local Windows file path to the TFS Sourcecode location. </p>
  
  <p><code>C:\Windows\sysWOW64\WindowsPowerShell\v1.0\$\AHLTAPrint\AWP 2.x.</code></p>
  
  <p>Here is the error I'm getting:</p>
  
  <pre><code>SourceControl.GetLatestFromLabel:
  
       [echo] NewFolderVersion = 2.0.0.2
  
  BUILD FAILED
  
  INTERNAL ERROR
  
  Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException: There is no working folder mapping for C:\Windows\sysWOW64\WindowsPowerShell\v1.0\$\AHLTAPrint\AWP 2.x.
     at Microsoft.TeamFoundation.VersionControl.Client.Client.GetLocalWorkspace(String localPath, Boolean throwIfNotFound)
     at AHLTA.NAnt.TFS.Tasks.GetFromLabelTask.ExecuteTask() in c:\Workspaces\Ahltaprint\Build\NAnt.Extensions.Extended\AHLTA.NAnt.TFS.Tasks\Tasks\GetFromLabelTask.cs:line 66
     at NAnt.Core.Task.Execute()
     at NAnt.Core.Target.Execute()
     at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
     at NAnt.Core.Task.Execute()
     at NAnt.Core.Target.Execute()
     at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
     at NAnt.Core.Project.Execute()
     at NAnt.Core.Project.Run()
  </code></pre>
  
  <p>Here is my NAnt Target:</p>
  
  <pre><code>  &lt;target name="SourceControl.GetLatestFromLabel"&gt;
      &lt;property name="Private.SourceCodeFoldersfolders" value="$/AHLTAPrint/AWP 2.x" /&gt;
      &lt;property name="Private.SourceCodeFoldersDelimiter" value="|" /&gt;
  
      &lt;echo message="NewFolderVersion = ${NewFolderVersion}" /&gt;
  
      &lt;tfsgetfromlabel tfsfolders ="${Private.SourceCodeFoldersfolders}"
                       labelname="${NewFolderVersion}"
                       folderdelimiter="${Private.SourceCodeFoldersDelimiter}"&gt;
        &lt;connectioninformation refid="TFSConnection" /&gt;
      &lt;/tfsgetfromlabel&gt;
  
    &lt;/target&gt;
  </code></pre>
  
  <p>This is the ExecuteTask portion of the Custom Task:</p>
  
  <pre><code>protected override void ExecuteTask()
  {
      VersionControlServer vcs = base.TheConnectionInformation.GetVersionControlServer();
      if (vcs != null)
      {
          if (String.IsNullOrEmpty(TheFolderDelimiter))
          {
              /*** Only one folder ***/
              if (!String.IsNullOrEmpty(TheTFSFolders))
              {
                  LabelVersionSpec version = new LabelVersionSpec(TheLabelName);
                  Workspace ws = vcs.GetWorkspace(TheTFSFolders);
                  if (ws != null)
                  {
                      string[] items = { TheTFSFolders };
                      GetStatus gs = ws.Get(items, version, RecursionType.Full, GetOptions.Overwrite | GetOptions.GetAll);
                  }
              }
          }
          else
          {
              // multiple folders in a string
              string[] folders = TheTFSFolders.Split(TheFolderDelimiter.ToCharArray());
  
              LabelVersionSpec version = new LabelVersionSpec(TheLabelName);
              for (int i = 0; i &lt; folders.Length; ++i)
              {
                  if (!String.IsNullOrEmpty(folders[i]))
                  {
                      Workspace ws = vcs.GetWorkspace(folders[i]);
                      if (ws != null)
                      {
                          string[] items = { folders[i] };
                          Console.WriteLine("Getting Latest Code in " + items[0].ToString() + " From Label " + version.Label);
                          GetStatus gs = ws.Get(items, version, RecursionType.Full, GetOptions.Overwrite | GetOptions.GetAll);
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Any idea what's going on or how I can correct this?</p>