19

ビルド サーバーとして VSTS を使用しています。ビルド中に bin フォルダーの内容をターゲットのルートにコピーし、カスタム ファイルを別のフォルダーからこのターゲットにコピーしたいと考えています。MSDNは、ミニマッチ パターンを使用することを提案していますが、サブディレクトリ構造のファイルをコピーしています。構造の復元には興味がありません。

たとえば、次のフォルダー構造を取得しています。

Project
    MyProjectFiles
    bin
        x86 (it's build configuration)
            Project.exe
    Other project files
    Project.sln
SomeScrips
    script1.ps1

しかし、私はこのフォルダ構造を受け取りたい:

Project.exe
SomeScripts
    script.ps1

要件に使用できるミニマッチ パターンはどれですか?

4

7 に答える 7

4

新しい Web ベースのビルド システムを使用すると、1 つのステップで複数のパターンを使用できます。したがって、あなたのケースでは次のようなことができます:

Project\bin\x86\Release\project.exe
SomeScripts\**\*

または、ビルド ステップでも使用する変数 (例: BuildPlatform/ ) にビルド プラットフォームと構成がある場合は、それらをパターンで使用できます。BuildConfiguration

Project\bin\$(BuildPlatform)\$(BuildConfiguration)\project.exe
SomeScripts\**\*

project.exeを構造ではなくルートに配置する場合は、最初に を使用して目的の構造にファイルをステージングする必要がありますCopy Task$(Build.StagingDirectory)これのターゲットとして使用できます。その後、コピー ルートとして Publish タスクを使用し、$(Build.StagingDirectory)このルートからドロップにすべてを公開します。

于 2016-01-04T09:19:36.330 に答える
2

ビルド サーバーで使用する PowerShell スクリプトが必要な場合は、(少なくとも、私のビルド サーバーでは ;)) 動作するサンプルを次に示します。

param
(
    [string] $buildConfiguration = "Debug",
    [string] $outputFolder = $PSScriptRoot + "\[BuildOutput]\"
)

Write-Output "Copying all build output to folder '$outputFolder'..."

$includeWildcards = @("*.dll","*.exe","*.pdb","*.sql")
$excludeWildcards = @("*.vshost.*")

# create target folder if not existing, or, delete all files if existing
if(-not (Test-Path -LiteralPath $outputFolder)) {
    New-Item -ItemType Directory -Force -Path $outputFolder | Out-Null

    # exit if target folder (still) does not exist
    if(-not (Test-Path -LiteralPath $outputFolder)) {
        Write-Error "Output folder '$outputFolder' could not be created."
        Exit 1
    }
} else {
    Get-ChildItem -LiteralPath $outputFolder -Include * -Recurse -File | foreach {
        $_.Delete()
    }
    Get-ChildItem -LiteralPath $outputFolder -Include * -Recurse -Directory | foreach {
        $_.Delete()
    }
}

# find all output files (only when in their own project directory)
$files = @(Get-ChildItem ".\" -Include $includeWildcards -Recurse -File |
    Where-Object {(
        $_.DirectoryName -inotmatch '\\obj\\' -and
        $_.DirectoryName -inotmatch '\\*Test*\\' -and
        $_.DirectoryName -ilike "*\" + $_.BaseName + "\*" -and
        $_.DirectoryName -ilike "*\" + $buildConfiguration
    )}
)

# copy output files (overwrite if destination already exists)
foreach ($file in $files) {
    Write-Output ("Copying: " + $file.FullName)
    Copy-Item $file.FullName $outputFolder -Force

    # copy all dependencies from folder (also in subfolders) to output folder as well (if not existing already)
    $dependencies = Get-ChildItem $file.DirectoryName -Include $includeWildcards -Exclude $excludeWildcards -Recurse -File
    foreach ($dependency in $dependencies) {
        $dependencyRelativePathAndFilename = $dependency.FullName.Replace($file.DirectoryName, "")
        $destinationFileName = Join-Path -Path $outputFolder -ChildPath $dependencyRelativePathAndFilename
        if (-not(Test-Path -LiteralPath $destinationFileName)) {
            Write-Output ("Copying: " + $dependencyRelativePathAndFilename + " => " + $destinationFileName)

            # create sub directory if not exists
            $destinationDirectory = Split-Path $destinationFileName -Parent
            if (-not(Test-Path -LiteralPath $destinationDirectory)) {
                New-Item -Type Directory $destinationDirectory
            }
            Copy-Item $dependency.FullName $destinationDirectory
        } else {
            Write-Debug ("Ignoring (existing destination): " + $dependency.FullName)
        }
    }
}

PowerShell ビルド ステップで使用されているスクリプトを次に示します。

TFS 2015 ビルド - 単一フォルダー ステップへの出力

于 2016-06-17T07:04:32.607 に答える
0

コピーする各ファイルのアーティファクトを作成します。次に、これらのアーティファクトの各ファイルの「ファイルのコピー」タスクを作成します。次に、ソース ツリー構造をコピーしません。

于 2017-01-09T09:33:19.637 に答える