0
votes

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.

C:\Windows\sysWOW64\WindowsPowerShell\v1.0\$\AHLTAPrint\AWP 2.x.

Here is the error I'm getting:

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()

Here is my NAnt Target:

  <target name="SourceControl.GetLatestFromLabel">
    <property name="Private.SourceCodeFoldersfolders" value="$/AHLTAPrint/AWP 2.x" />
    <property name="Private.SourceCodeFoldersDelimiter" value="|" />

    <echo message="NewFolderVersion = ${NewFolderVersion}" />

    <tfsgetfromlabel tfsfolders ="${Private.SourceCodeFoldersfolders}"
                     labelname="${NewFolderVersion}"
                     folderdelimiter="${Private.SourceCodeFoldersDelimiter}">
      <connectioninformation refid="TFSConnection" />
    </tfsgetfromlabel>

  </target>

This is the ExecuteTask portion of the Custom Task:

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 < 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);
                    }
                }
            }
        }
    }
}

Any idea what's going on or how I can correct this?

1
Beatcracker Thank you for editing this. I tried to fix it but didn't know how and could not see the underlying code surrounding it.GhostHunterJim

1 Answers

0
votes

Resolved this by adding -workingdirectory parameter to Start-Process command-line. Script was being called from a different directory