私はpowershellから呼び出そうとしているメソッドを持っています.
Workspace.GetPendingChanges(string[] items)
このメソッドには複数のオーバーロードがありますが、私の人生を難しくしているものは次のとおりです。
Workspace.GetPendingChanges(string items)
Workspace.GetPendingChanges(string[] items)
Workspace.GetPendingChanges(ItemSpec[] itemspecs)
Find-Files
TFS 2015 の新しいビルド タスクのコマンドレットを使用して、ファイルのリストを取得しています。
if ($ItemSpec.Contains("*") -Or $ItemSpec.Contains("?"))
{
Write-Verbose "Pattern found in solution parameter. Calling Find-Files."
Write-Verbose "Calling Find-Files with pattern: $ItemSpec"
[string[]] $FilesToCheckin = @(Find-Files -SearchPattern $ItemSpec -RootFolder $env:BUILD_SOURCESDIRECTORY)
Write-Verbose "Found files: $FilesToCheckin"
}
else
{
Write-Verbose "No Pattern found in solution parameter."
[string[]] $FilesToCheckin = @($ItemSpec)
}
そして、私は電話します:
$pendingChanges = $provider.Workspace.GetPendingChanges( @($FilesToCheckin))
[string[]]
私が知っているキャスト強制配列表記のバージョンについて試してみまし@()
たが、find-files の結果は、正しいオーバーロードに渡される前に、常に単一の長い文字列に変換されます。
System.Management.Automation.MethodInvocationException: Exception calling "GetPendingChanges" with "1" argument(s): "TF400889: The following path contains more than the allowed 259 characters:
これが生成される「長い文字列」です
C:\TfsData\Build\_work\1\s\BuildProcessTemplates\AzureContinuousDeployment.11.xaml C:\TfsData\Build\_work\1\s\BuildProcessTemplates\DefaultTemplate.11.1.xaml C:\TfsData\Build\_work\1\s\BuildProcessTemplates\LabDefaultTemplate.11.xaml C:\TfsData\Build\_work\1\s\BuildProcessTemplates\UpgradeTemplate.xaml C:\TfsData\Build\_work\1\s\checkin-changes.ps1 C:\TfsData\Build\_work\1\s\update.txt C:\TfsData\Build\_work\1\s\updatefile.ps1.
Specify a shorter path." ---> Microsoft.TeamFoundation.InvalidPathException: TF400889: The following path contains more than the allowed 259 characters: C:\TfsData\Build\_work\1\s\BuildProcessTemplates\AzureContinuousDeployment.11.xaml C:\TfsData\Build\_work\1\s\BuildProcessTemplates\DefaultTemplate.11.1.xaml C:\TfsData\Build\_work\1\s\BuildProcessTemplates\LabDefaultTemplate.11.xaml ...
at System.IO.PathHelper.GetFullPathName()
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at Microsoft.TeamFoundation.Common.FileSpec.GetFullPathWrapper(String path)
--- End of inner exception stack trace ---
at Microsoft.TeamFoundation.Common.FileSpec.GetFullPathWrapper(String path)
at Microsoft.TeamFoundation.Common.FileSpec.GetFullPath(String path, Boolean checkForIllegalDollar)
at Microsoft.TeamFoundation.VersionControl.Common.VersionControlUtil.GetFullPath(String item, PathLength maxServerPathLength)
at Microsoft.TeamFoundation.VersionControl.Client.ItemSpec..ctor(String item, RecursionType recursionType, Int32 deletionId)
at Microsoft.TeamFoundation.VersionControl.Client.ItemSpec.FromStrings(String[] paths, RecursionType recursion)
at
これは、正しいオーバーロードを呼び出していることを示しています
Microsoft.TeamFoundation.VersionControl.Client.Workspace.GetPendingChanges(String[] items, RecursionType recursion, Boolean includeDownloadInfo)
List<string>
コマンドレットは次を返します。
protected override void ProcessRecord()
{
base.ProcessRecord();
if (!this.IncludeFiles && !this.IncludeFolders)
{
this.IncludeFiles = true;
}
List<string> sendToPipeline = FindFiles.FindMatchingFiles(this.RootFolder, this.SearchPattern, this.IncludeFiles, this.IncludeFolders);
base.WriteObject(sendToPipeline, true);
}
呼び出しからリストを確実に取得するために、Find-Files
次を追加しました。
Write-Verbose "Found files: " -Verbose
Write-Verbose $FilesToCheckin.Count -Verbose
期待どおり、7 が返されます。
私の質問
Powershell が からの結果をfind-files
に渡す前に 1 つの長い文字列に変換しないようにするにはどうすればよいGetPendingChanges
ですか?
プロジェクトはで利用可能で、壊れたコードは下部でコメントアウトされています: