2015-07-10 177 views
1

我們必須在TFS服務器上建立兩個解決方案。一種解決方案是框架,另一種解決方案包括服務,應該爲每個項目單獨構建服務,以便稍後通過腳本部署它們。必須建立2個解決方案,每個項目一個

此外,框架程序集複製到框架解決方案中的(基礎)項目。第二個解決方案的所有項目都涉及這個「基礎」項目。

我的問題是,我不知道如何配置解決方案,項目和構建以執行上述請求。

請幫忙。

注意:我不想將每個服務項目放入msi中以便安裝它。我只想將服務從TFS服務器上的中央下拉文件夾中部署出來。

回答

1

一種選擇是舉辦自己的NuGet飼料:http://docs.nuget.org/create/hosting-your-own-nuget-feeds

通過託管自己的飼料,您可以執行自定義生成您的構建過程,更新您的飼料內的活動。

請參閱本文檔定製TFS共建活動:http://nakedalm.com/creating-a-custom-activity-for-team-foundation-build/

添加PowerShell來構建過程請參見本文檔:http://blogs.technet.com/b/heyscriptingguy/archive/2014/04/21/powershell-and-tfs-the-basics-and-beyond.aspx

通過託管自己的NuGet飼料,你必須有你的消費解決方案的能力利用你的私人礦塊飼料和包來處理依賴管理和版本。通過利用自定義構建活動,您可以通過.net或PowerShell更新您的nuget feed。您還可以通過PowerShell腳本自動執行部署。

+0

您不需要創建自定義活動來執行此操作。您只需從模板中的預定義腳本位置調用一個小PowerShell。 –

2
  1. Team Build可以在構建過程模板中構建多個解決方案。只需點擊Projects to Build後面的[...]按鈕並添加兩個解決方案。

  2. TFS重定向你的項目的輸出目錄,這可能會破壞你的腳本,複製從A到B的「基礎工程」的輸出。爲了把這個重定向設置輸出位置到AsConfigured 。

  3. 現在TFS將不知道如何將輸出複製到Binaries文件夾,該文件夾用作複製到放置位置操作的源。爲了解決這個問題,你需要編寫一個powershell腳本和configure this as a post-build script

enter image description here

創建一個腳本下降的過程是clearly documented on MSDNsample script is available from CodePlex

##----------------------------------------------------------------------- 
## <copyright file="GatherItemsForDrop.ps1">(c) http://TfsBuildExtensions.codeplex.com/. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved.</copyright> 
##----------------------------------------------------------------------- 
# Copy the binaries to the bin directory 
# so that the build server can drop them 
# to the staging location specified on the Build Defaults tab 
# 
# See 
# http://msdn.microsoft.com/en-us/library/bb778394(v=vs.120).aspx 
# http://msdn.microsoft.com/en-us/library/dd647547(v=vs.120).aspx#scripts  

# Enable -Verbose option 
[CmdletBinding()] 

# Disable parameter 
# Convenience option so you can debug this script or disable it in 
# your build definition without having to remove it from 
# the 'Post-build script path' build process parameter. 
param([switch]$Disable) 
if ($PSBoundParameters.ContainsKey('Disable')) 
{ 
    Write-Verbose "Script disabled; no actions will be taken on the files." 
} 

# This script copies the basic file types for managed code projects. 
# You can change this list to meet your needs. 
$FileTypes = $("*.exe","*.dll","*.exe.config","*.pdb") 

# Specify the sub-folders to include 
$SourceSubFolders = $("*bin*","*obj*") 

# If this script is not running on a build server, remind user to 
# set environment variables so that this script can be debugged 
if(-not $Env:TF_BUILD -and -not ($Env:TF_BUILD_SOURCESDIRECTORY -and $Env:TF_BUILD_BINARIESDIRECTORY)) 
{ 
    Write-Error "You must set the following environment variables" 
    Write-Error "to test this script interactively." 
    Write-Host '$Env:TF_BUILD_SOURCESDIRECTORY - For example, enter something like:' 
    Write-Host '$Env:TF_BUILD_SOURCESDIRECTORY = "C:\code\FabrikamTFVC\HelloWorld"' 
    Write-Host '$Env:TF_BUILD_BINARIESDIRECTORY - For example, enter something like:' 
    Write-Host '$Env:TF_BUILD_BINARIESDIRECTORY = "C:\code\bin"' 
    exit 1 
} 

# Make sure path to source code directory is available 
if (-not $Env:TF_BUILD_SOURCESDIRECTORY) 
{ 
    Write-Error ("TF_BUILD_SOURCESDIRECTORY environment variable is missing.") 
    exit 1 
} 
elseif (-not (Test-Path $Env:TF_BUILD_SOURCESDIRECTORY)) 
{ 
    Write-Error "TF_BUILD_SOURCESDIRECTORY does not exist: $Env:TF_BUILD_SOURCESDIRECTORY" 
    exit 1 
} 
Write-Verbose "TF_BUILD_SOURCESDIRECTORY: $Env:TF_BUILD_SOURCESDIRECTORY" 

# Make sure path to binary output directory is available 
if (-not $Env:TF_BUILD_BINARIESDIRECTORY) 
{ 
    Write-Error ("TF_BUILD_BINARIESDIRECTORY environment variable is missing.") 
    exit 1 
} 
if ([IO.File]::Exists($Env:TF_BUILD_BINARIESDIRECTORY)) 
{ 
    Write-Error "Cannot create output directory." 
    Write-Error "File with name $Env:TF_BUILD_BINARIESDIRECTORY already exists." 
    exit 1 
} 
Write-Verbose "TF_BUILD_BINARIESDIRECTORY: $Env:TF_BUILD_BINARIESDIRECTORY" 

# Tell user what script is about to do 
Write-Verbose "Will look for and then gather " 
Write-Verbose "$FileTypes files from" 
Write-Verbose "$Env:TF_BUILD_SOURCESDIRECTORY and copy them to " 
Write-Verbose $Env:TF_BUILD_BINARIESDIRECTORY 

# Find the files 
$files = gci $Env:TF_BUILD_SOURCESDIRECTORY -recurse -include $SourceSubFolders | 
    ?{ $_.PSIsContainer } | 
    foreach { gci -Path $_.FullName -Recurse -include $FileTypes } 
if($files) 
{ 
    Write-Verbose "Found $($files.count) files:" 

    foreach ($file in $files) { 
     Write-Verbose $file.FullName 
    } 
} 
else 
{ 
    Write-Warning "Found no files." 
} 

# If binary output directory exists, make sure it is empty 
# If it does not exist, create one 
# (this happens when 'Clean workspace' build process parameter is set to True) 
if ([IO.Directory]::Exists($Env:TF_BUILD_BINARIESDIRECTORY)) 
{ 
    $DeletePath = $Env:TF_BUILD_BINARIESDIRECTORY + "\*" 
    Write-Verbose "$Env:TF_BUILD_BINARIESDIRECTORY exists." 
    if(-not $Disable) 
    { 
     Write-Verbose "Ready to delete $DeletePath" 
     Remove-Item $DeletePath -recurse 
     Write-Verbose "Files deleted." 
    } 
} 
else 
{ 
    Write-Verbose "$Env:TF_BUILD_BINARIESDIRECTORY does not exist." 

    if(-not $Disable) 
    { 
     Write-Verbose "Ready to create it." 
     [IO.Directory]::CreateDirectory($Env:TF_BUILD_BINARIESDIRECTORY) | Out-Null 
     Write-Verbose "Directory created." 
    } 
} 

# Copy the binaries 
Write-Verbose "Ready to copy files." 
if(-not $Disable) 
{ 
    foreach ($file in $files) 
    { 
     Copy $file $Env:TF_BUILD_BINARIESDIRECTORY 
    } 
    Write-Verbose "Files copied." 
} 

更好的解決方案很可能是具有2個獨立的建立,其中所述第一生成發佈第二個項目作爲NuGet包的依賴關係。 The Microsoft ALM Rangers have delivered a guide,解釋如何設置。

+0

感謝您的意見。 – GermanBoy

+0

我發現「我的」解決方案:在構建配置「過程」2.5。我放了一些MSBuild參數,如:/ p:ReferenzPath =「...; ...」,以便所有解決方案都能找到所需的源。有一個名爲「$(TF_BUILD_BUILDDIRECTORY)」的系統變量幫助我找到基本路徑。之後,我在構建定義中放入MSBuild參數:/ p:GenerateProjectSpecificOutputFolder = true「。所有解決方案都將構建」每個項目「。現在我將編寫一個後構建腳本,將一些文件夾和配置文件複製到構建輸出,爲此,我將使用上面的代碼snipplet作爲方向 – GermanBoy

相關問題