2017-09-06 69 views
1

我想在使用TFS的CI中部署一堆WPF應用程序。到目前爲止,部署步驟是手動激活的,即我從我的開發者調用了Powershell腳本。框來運行每個項目並進行部署。如果有幫助,這裏是代碼片段。將ClickOnce部署簽名爲Team Foundation Server發佈進程的問題

$projs = Get-ChildItem -Path $pwd -Recurse -Include '*.csproj 
foreach ($proj in $projs) 
{ 

    $xml = [xml](Get-Content $proj) 
    $assemblyName="" 
    $publishUrl = "" 
    $productName ="" 

    $nodes = $xml.GetElementsByTagName('AssemblyName') 
    #Write "Trying to get AssemblyName" 
    foreach ($node in $nodes) { 
     $oldName = $node.'#text' 
     if($oldName.Contains("Beta")){continue} 
     $newName =$oldName+'_Beta' 
     #skip any PublishUrl that is still the default 'publish\' 
    # Write $newName 
     $node.'#text' = $newName 
     $assemblyName = $newName 
     } 
    #Write "Trying to get ProductName" 
    $nodesProduct = $xml.GetElementsByTagName('ProductName') 
    foreach ($node in $nodesProduct) { 
     if($node.'#text'.Contains(".NET")) 
      { 
      continue 
      } 
     $oldName = $node.'#text' 
     if($oldName.Contains("Beta")){continue} 
     $newName =$oldName+'_Beta' 
    # Write $newName 
     $node.'#text' = $newName 
     $productName = $newName 
     } 
    #Write "Trying to get PublishURL" 
    $nodesPublish = $xml.GetElementsByTagName('PublishUrl') 
    foreach ($node in $nodesPublish) { 
     $oldName = $node.'#text' 
     #skip any PublishUrl that is still the default 'publish\' 
     if ($node.'#text' -eq 'publish\') { break } 
     if($oldName.Contains("Beta")){continue} 
     $newName =$oldName+'Beta\' 
    # Write $newName 
     $node.'#text' = $newName 
     $publishUrl = $newName 
     } 
    #if all three params are not null save and deploy project 
    if($assemblyName -ne"" -And $publishUrl -ne "" -And $productName -ne "") 
    { 
     $xml.Save($proj) 
     Write "trying to deploy $productName to $publishUrl" 
     msbuild /m /t:publish /p:Configuration='Debug' /p:Platform=AnyCPU /p:ApplicationVersion=$appVersion /p:ApplicationRevision=$Revision /p:MinimumRequiredVersion=$newVersion /p:PublishUrl="$publishUrl" /verbosity:m $proj 
      $pubDir = Join-Path $proj.Directory -ChildPath "bin\Debug\app.publish" -Resolve -ErrorAction Stop 
      #copy the files to the publish URL 
      Write "$pubDir" 
      Copy-Item -Path "${pubDir}\*" -Destination "$publishUrl" -Include '*.*' -Recurse -Force 
      Copy-Item -Path "${pubDir}\Application Files" -Destination "$publishUrl" -Recurse -Force 
     tf vc undo /noprompt $proj 
     Write "Tf undone" 
    }` 

當我更改我的Assembly-info.cs以使開發和生產環境部署分開時,請忽略所有Beta版本。我已經生成了自己的證書並將其鏈接到我的.csproj文件。這項工作已經過測試,並且是我們目前的戰略。 我想將此腳本作爲Team Foundation Server中的後續操作集成,以便我們可以獲得CD。

在服務器上,我有:

  1. VSTS運行作爲我的管理員帳戶安裝在服務器

此相同的腳本生成以下錯誤上

  • 我PFX證書:

    \(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2884,5): warning MSB3327: Unable to find code signing certificate in the current user's Windows certificate store. To correct this, either disable signing of the ClickOnce manifest or install the certificate into the certificate store. 
    
    \(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4961,5): MSB4044: The "SignFile" task was not given a value for the required parameter "CertificateThumbprint". 
    

    我注意到TFS服務複製到代理程序上的.csproj文件沒有鏈接到進口證書(這也是源代碼管理)

    到目前爲止,我已經嘗試在服務器本身上安裝證書,並且也嘗試以NTService運行。有關此錯誤的更多信息,請參閱這些主題 12,3。然而,他們的解決方案似乎都沒有奏效。 我將不勝感激任何幫助。

  • +1

    您是否嘗試過只是TFS生成源(對所有項目),然後簽署這份建立與自己的證書,clickone清單使用'mage.exe' ?當然,這是獲得你想要的唯一替代方式。 –

    +0

    如果我這樣做,我可以保留當前的系統,它在tfs中構建源代碼,並使用PS腳本進行部署。我的目標是完全實現交付自動化,因此無需任何開發人員干預即可運行,無論是使用門控簽入還是基於時間的觸發器。除非我錯過了一些東西。 –

    +0

    您也可以使用'mage.exe'爲我上面的示例編寫PSScripts來簽署清單和證書。所以這個解決方案是完全自動化的交付。 –

    回答

    0

    這就是我最終做的工作。

    1. 加了我PFX爲鏈接的文件,以我所有的UI項目

    2. 的所有項目使用的證書從文件從這個menu

    3. 經過入源控制

    4. 製造一個新的構建定義誰是唯一的工作是運行我的PowerShell 片段

    5. 跑TFS我的帳戶下構建

    +0

    謝謝,我立即做到了,但是因爲24小時不讓我這麼做。 –