如何使用 Powershell 将 .PublishSettings 文件转换为 .pubxml 和 .pubxml.user 文件

问题描述 投票:0回答:1

我的团队维护着大量的网站。每个都是 Visual Studio 解决方案中的一个项目,具有发布配置文件 (Properties\PublishProfiles\xxx.pubxml)。目标是 1) 在 Azure Web 应用程序中托管每个网站,2) 修改发布配置文件,以便它们发布到相应的 Web 应用程序。

我已编写 Powershell 脚本来生成所有 Web 应用程序,并下载每个 Web 应用程序的 .PublishSettings 文件(使用 Get-AzureRmWebAppPublishingProfile)。

我的问题是,如何使用 Powershell 将 .PublishSettings 文件转换为 .pubxml 和 .pubxml.user 文件?我可以为每个站点手动执行此操作(发布 | 导入配置文件),但由于涉及大量站点,我需要在 Powershell 脚本中执行此操作。

azure powershell publish publish-profiles
1个回答
0
投票

我在我的环境中尝试了以下示例代码,以使用 PowerShell 将

.PublishSettings
文件转换为
.pubxml
.pubxml.user
文件。

$resourcegroup = "xxxx"
$webapp = "newapj"
$file = Get-AzureRMWebAppPublishingProfile -ResourceGroupName $resourcegroup -Name $webapp -OutputFile "/home/madugula/webapp.publishsettings"
function Convert-PubSettingsToPubxml {
    param(
        [string]$publishSettingsPath
    )
    $publishSettingsPath = "/home/madugula/webapp.publishsettings"
    $Content = Get-Content -Path $publishSettingsPath 
    $profile = [xml]$Content
    $publishProf = $profile.PublishData.PublishProfile | Where-Object { $_.PublishMethod -eq "MSDeploy" }


    $pubxmlContent = @"
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish>$($publishProf.DestinationPublishUrl)</SiteUrlToLaunchAfterPublish>
    ....#Add it
  </PropertyGroup>
</Project>
"@
    $xmlUserContent = @"
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    #Add other properties as per your requirement
.....
  </PropertyGroup>
</Project>
"@
    $PathpubXml = [System.IO.Path]::ChangeExtension($publishSettingsPath, "pubxml")
    $userpathpubxml = [System.IO.Path]::ChangeExtension($publishSettingsPath, "pubxml.user")

    $pubxmlContent | Out-File -FilePath $PathpubXml
    $xmlUserContent | Out-File -FilePath $userpathpubxml

    Write-Host "Conversion Done. saved at: $PathpubXml, $userpathpubxml"
}

$publishSettingsPath = "/home/madugula/WebApp.PublishSettings"
Convert-PubSettingsToPubxml -publishSettingsPath $publishSettingsPath

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.