gpt4 book ai didi

powershell - 使用 mage.exe 在 Octopus 中配置 click once 应用程序,更改发布 url 和 app.config

转载 作者:行者123 更新时间:2023-12-03 23:49:05 26 4
gpt4 key购买 nike

我正在尝试通过以下过程发布一次点击:

  • Github 提交
  • Teamcity 构建和创建基本(未签名工件)
  • 推送到 Octopus 部署
  • Octopus 更改发布 URL 和应用程序设置
  • 八达通使用法师修改以上内容,重新创建app文件并修改和辞职
  • 八达通推送文件到部署站点

  • 在我需要更改应用程序设置之前,我的上述工作大致正常,但有以下警告:
  • 只有发布 url 被更改
  • 使用法师重新签署文件,但没有重新生成任何文件。

  • 它现在将发布文件并下载并尝试运行/安装应用程序并给出以下错误:
     Activation of http://myapp-setuptool-dev.mysite.co.uk/myappSetupTool.application resulted in exception. Following failure messages were detected:
    + Downloading http://myapp-setuptool-dev.mysite.co.uk/Application Files/myappSetupTool_0_1_1_110/myappSetupTool.exe.config did not succeed.
    + The remote server returned an error: (404) Not Found.

    为了让 Octopus 部署为我做配置转换,我必须在部署期间向 OD 添加一个脚本。在预部署部分,它复制“myappSetupTool.exe.config.deploy”文件并删除“.deploy”扩展名,以便 OD 将其视为配置并自动替换 appsetting。

    在部署后部分,我将文件复制回以具有“.deploy”扩展名。

    我发布说这会更改文件哈希值,这就是它不起作用的原因,所以我认为我必须重新生成 .application 和 .manifest 文件以进行补偿。

    问题 1:

    当文件具有 .deploy 扩展名或没有它们时,我是否需要重新生成这些文件?

    问题2:

    如果我需要删除“.deploy”扩展名,我是否需要将文件恢复原状?即将它们重命名为“*.deploy”?

    问题 3:

    实现这一目标的步骤是什么?我已将我的 powershell 脚本放在下面。
    $mage = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\mage.exe"
    $path = $OctopusParameters["Octopus.Action[deploy click once app].Output.deploymentPath"]

    Set-Location -Path $path

    write-host "mage: " $mage

    $appNameShort = "myappSetupTool"
    $appName = "$appNameShort.application"

    $folderName = $OctopusParameters["Octopus.Action[setup version number].Output.clickOnceVersion"]
    $version = $folderName.Replace("_", ".")
    $folderSegment = "Application Files\$appNameShort" + "_$folderName"

    $deploymentApplicaitonPath = "$path\$folderSegment\$appNameShort.application"
    $deploymentManifestRelativePath = "$folderSegment\$appNameShort.exe.manifest"
    $deploymentManifestPath = "$path\$deploymentManifestRelativePath"

    $appApplicationPath = "$path\$appName"
    $certFilePath = "$path\$certFileName"

    $setupPath = "$path\setup.exe"

    $url = "$publishUrl/$appName"

    write-host "deployment application path: " $deploymentApplicaitonPath
    write-host "deployment manifest path: " $deploymentManifestPath

    write-host "application file path: " $appApplicationPath
    write-host "cert file path: " $certFilePath
    write-host "setup.exe path: " $setupPath

    write-host "publish url: " $url

    write-host "renaming all .deploy files to remove deploy extension"
    #Need to resign the application manifest, but before we do we need to rename all the files back to their original names (remove .deploy)
    Get-ChildItem "$path\$folderSegment\*.deploy" -Recurse | Rename-Item -NewName { $_.Name -replace '\.deploy','' }

    write-host "deleting old app files manifest file to be regenerated"
    Remove-Item $deploymentManifestRelativePath

    Write-Host "Creating application manifest at "$deploymentManifestRelativePath
    write-host "running: $mage -New Application -t $deploymentManifestPath -n $appName -v $version -p msil -fd $path\$folderSegment -tr FullTrust -a sha256RSA"
    & "$mage" -New Application -t "$deploymentManifestPath" -n "$appName" -v $version -p msil -fd "$path\$folderSegment" -tr FullTrust -a sha256RSA

    write-host "Running: $mage -Sign $deploymentManifestPath -CertFile $certFilePath -Password $certPassword"
    & "$mage" -Sign "$deploymentManifestPath" -CertFile "$certFilePath" -Password $certPassword


    Write-Host "Creating application: $mage -New Deployment -t $appApplicationPath -n $appName -v $version -p msil -appm $deploymentManifestRelativePath -ip true -i true -um true -pu $appApplicationPath -appc $deploymentManifestRelativePath -a sha256RSA "
    & "$mage" -New Deployment -t "$appApplicationPath" -n "$appName" -v $version -p msil -appm "$deploymentManifestPath" -ip true -i true -um true -pu "$appApplicationPath" -appc "$deploymentManifestRelativePath" -a sha256RSA


    write-host "Running: $mage -Update $deploymentApplicaitonPath -ProviderUrl $url"
    & "$mage" -Update "$deploymentApplicaitonPath" -ProviderUrl $url



    write-host "Running: $mage -Update $appApplicationPath -ProviderUrl $url"
    & "$mage" -Update "$appApplicationPath" -ProviderUrl $url

    write-host "Running: $mage -Update $appApplicationPath -AppManifest $deploymentManifestRelativePath"
    & "$mage" -Update "$appApplicationPath" -AppManifest "$deploymentManifestRelativePath"

    write-host "Running: $mage -Sign $appApplicationPath -CertFile $certFilePath -Password $certPassword"
    & "$mage" -Sign "$appApplicationPath" -CertFile "$certFilePath" -Password $certPassword

    write-host "Running: $setupPath -url=$publishUrl/"
    & "$setupPath" "-url=$publishUrl/"

    write-host "update files to have deploy extension again"
    #Rename files back to the .deploy extension, skipping the files that shouldn't be renamed
    Get-ChildItem -Path "Application Files\*" -Recurse | Where-Object {!$_.PSIsContainer -and $_.Name -notlike "*.manifest" -and $_.Name -notlike "*.application" -and $_.Name -notlike "*.gif" -and $_.Name -notlike "*.png"} | Rename-Item -NewName {$_.Name + ".deploy"}

    最佳答案

    所以我想通了......不知道原始脚本有什么问题,但决定回归基础并将其分解为多个部分,脚本如下:

    $mage = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\mage.exe"
    $path = $OctopusParameters["Octopus.Action[deploy click once app].Output.deploymentPath"]

    Set-Location -Path $path

    write-host "mage: " $mage

    $appNameShort = "myappSetupTool"
    $appName = "$appNameShort.application"

    $folderName = $OctopusParameters["Octopus.Action[setup version number].Output.clickOnceVersion"]
    $version = $folderName.Replace("_", ".")
    $folderSegment = "Application Files\$appNameShort" + "_$folderName"

    $deploymentApplicaitonPath = "$path\$folderSegment\$appNameShort.application"
    $deploymentManifestRelativePath = "$folderSegment\$appNameShort.exe.manifest"
    $deploymentManifestPath = "$path\$deploymentManifestRelativePath"

    $appApplicationPath = "$path\$appName"
    $certFilePath = "$path\$certFileName"

    $setupPath = "$path\setup.exe"

    $url = "$publishUrl/$appName"

    write-host "deployment application path: " $deploymentApplicaitonPath
    write-host "deployment manifest path: " $deploymentManifestPath

    write-host "application file path: " $appApplicationPath
    write-host "cert file path: " $certFilePath
    write-host "setup.exe path: " $setupPath

    write-host "publish url: " $url






    ##
    ## order of process
    ##
    ## 1) remove all .deploy extensions
    ## 2) set properties on the applicaiton manifest file
    ## 3) update applicaiton manifest file directly
    ##
    ## 4) set properties on .application file
    ## 5) update .application file directly
    ##
    ## 6) sign application manifest
    ## 7) sign .application file
    ## 8) update setup.exe
    ##
    ## 9) put .deploy back on files
    ##

    ##### 1

    write-host "renaming all .deploy files to remove deploy extension"
    #Need to resign the application manifest, but before we do we need to rename all the files back to their original names (remove .deploy)
    Get-ChildItem "$path\$folderSegment\*.deploy" -Recurse | Rename-Item -NewName { $_.Name -replace '\.deploy','' }


    ##### 2




    ##### 3

    & "$mage" -Update "$deploymentManifestPath" -CertFile "$certFilePath" -Password $certPassword


    ##### 4

    write-host "Running: $mage -Update $appApplicationPath -ProviderUrl $url"
    & "$mage" -Update "$appApplicationPath" -ProviderUrl $url

    write-host "Running: $mage -Update $deploymentApplicaitonPath -ProviderUrl $url"
    & "$mage" -Update "$deploymentApplicaitonPath" -ProviderUrl $url


    ##### 5

    write-host "Running: $mage -Update $appApplicationPath -AppManifest $deploymentManifestRelativePath"
    & "$mage" -Update "$appApplicationPath" -AppManifest "$deploymentManifestRelativePath"


    ##### 6

    write-host "Running: $mage -Sign $deploymentManifestPath -CertFile $certFilePath -Password $certPassword"
    & "$mage" -Sign "$deploymentManifestPath" -CertFile "$certFilePath" -Password $certPassword



    ##### 7

    write-host "Running: $mage -Sign $appApplicationPath -CertFile $certFilePath -Password $certPassword"
    & "$mage" -Sign "$appApplicationPath" -CertFile "$certFilePath" -Password $certPassword



    ##### 8

    write-host "Running: $setupPath -url=$publishUrl/"
    & "$setupPath" "-url=$publishUrl/"



    ##### 9

    write-host "update files to have deploy extension again"
    #Rename files back to the .deploy extension, skipping the files that shouldn't be renamed
    Get-ChildItem -Path "$folderSegment\*" -Recurse | Where-Object {!$_.PSIsContainer -and $_.Name -notlike "*.manifest" -and $_.Name -notlike "*.application"} | Rename-Item -NewName {$_.Name + ".deploy"}

    关于powershell - 使用 mage.exe 在 Octopus 中配置 click once 应用程序,更改发布 url 和 app.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41142074/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com