2017-09-06 27 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小时不让我这么做。 –