使用发布配置文件部署现有包 [英] Deploying an existing package using publish profiles

查看:31
本文介绍了使用发布配置文件部署现有包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的发布配置文件支持(在 VS2012 和 VS2010 中通过更新提供)创建持续交付部署管道",其中在第一个阶段"制作包/zip,并将相同的包部署到各种环境使用不同的配置.

I'm trying to use the new publish profile support (available in VS2012 and in VS2010 via an update) to create a continuous delivery "deployment pipeline", whereby a package/zip is made in the first "stage" and the same package is deployed to various environments using different configurations.

使用 pubxml 文件中定义的设置、从命令行部署现有包时涉及哪些任务/属性,并且不会导致构建?换句话说,我想发布"到一个,然后再将同一个包发布"到另一个配置文件而不重建它.

What tasks/properties are involved in deploying an existing package using settings defined in a pubxml file, from the command line, and without causing a build? Put another way, I'd like to "publish" to a package, then later "publish" that same package to another profile without rebuilding it.

(我知道我可以直接使用 MSDeploy,但如果可能,我希望每个项目的管道更少)

(I know I can use MSDeploy directly, but I'd prefer to have less plumbing on each project if possible)

推荐答案

更新 2014-01-28

使我的自定义脚本与 VS/Azure SDK 的不断变化的版本保持同步最终是一项繁重的工作,所以我实际上已经恢复到使用生成的 deploy.cmd 脚本,一个小区别:

Keeping my custom script up to date with the changing versions of VS / Azure SDK ended up being too much hard work, so I've actually reverted to using the generated deploy.cmd script, with one minor difference:

我已经开始将所有参数值从 ProfileName.pubxml 文件中删除,而是将它们放在 ProfileName.paramters.xml 中(在 中生成的示例>.SetParameters.xml 与包,文档在这里).这些将由 Visual Studio/MSBuild 按照约定自动拾取,我可以在运行时通过在调用 deploy.cmd 时传入 -setParamFile:path oProfileName.parameters.xml 来使用它们

I've started leaving all my parameter values out of the ProfileName.pubxml file and instead putting them in a ProfileName.paramters.xml (example generated in .SetParameters.xml with package, docs here). These will automatically be picked up by Visual Studio / MSBuild by convention and I can use them at runtime by passing in -setParamFile:path oProfileName.parameters.xml when calling deploy.cmd

更新 - 现在正在 GitHub 上维护(并记录)此脚本的更新版本 - https://github.com/richardszalay/msdeploy-package-publish

经过大量挖掘,我发现 Microsoft.Web.Publishing.targets (v10.5) 中的几个问题阻止了它的工作.为了解决这些问题,我创建了以下 MSBuild 脚本,可以将其放置在与 Web 应用程序的 csproj 相同的目录中.我添加了与修复和实施细节相关的评论.

After much digging, I found that several issues in Microsoft.Web.Publishing.targets (v10.5) that prevents this from working. To workaround these issues, I've created the following MSBuild script that can be placed in the same directory as the Web Application's csproj. I've added comments related to fixes and implementation details.

该脚本使用 Microsoft.Web.Publishing.targets,因此大多数标准属性应该仍然有效.以下是您可以使用它的一些方法:

The script uses Microsoft.Web.Publishing.targets, so most of the standard properties should still work. Here are some ways you can use it:

# Convention based
msbuild PackageDeploy.build /p:PublishProfile=Stage;WebPublishPipelineProjectName=Name_of_your_web_application

# Absolute paths to profile + package
msbuild PackageDeploy.build /p:PublishProfile=PathToProfile.pubxml;PackageFileName=PathToPackage.zip;WebPublishPipelineProjectName==Name_of_your_web_application

如果您使用的是 VS2012,请确保声明 VisualStudioVersion=v11.0 以导入正确的发布文件.

If you're using VS2012, make sure you declare VisualStudioVersion=v11.0 to import the correct publishing file.

使用此脚本,您无需在部署管道的后续阶段重新检查您的 Web 应用程序.在构建/打包阶段之后,您只需要保留以下工件:

Using this script, you shouldn't need to recheck out your web application in subsequent stages in your deployment pipeline. You'll just need to keep the following artifacts after the build/package stage:

  • PackageDeploy.build(下)
  • 您的发布配置文件
  • Web 应用程序包 zip

这是 PackageDeploy.build 的源代码:

Here's the source for PackageDeploy.build:

<!--
This build script supports deployment of a website package to a publish profile without rebuilding the project or package

If placed in the same directory as a web project that uses publish profiles, the following arguments will need to be defined:

Convention based required arguments:
  PublishProfile: the name of the publish profile (or a path to a pubxml file if using non-convention based)
  Configuration: Debug/Release

Convention based optional arguments:
  VisualStudioVersion: Property specific to this build script that determines which WPP version to use (v10.5 [default] for VS2010+Azure updates, v11.0 for VS2012)
  WebPublishPipelineProjectName:
  WebPublishPipelineProjectDirectory: The root to the web project directory if this build script isn't there and PublishProfile isn't a path (to auto-detect publish profile directory)

Non-convention based optional arguments:
  PackageFileName: The full path to the website package zip
  UseDeclareParametersXMLInMsDeploy: true to save the parameters to a file and then use that file; false to inline the parameters
  UseMsDeployExe: true to use msdeploy.exe; false to use the VS MSBuild task

-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="DeployFromPackage">

  <PropertyGroup>
    <!-- IMPL: Set this to v11.0 to use VS2012 -->
    <VisualStudioVersion>v10.5</VisualStudioVersion>
  </PropertyGroup>

  <PropertyGroup>
    <!-- IMPL: Declared in Microsoft.Web.Publishing.targets, but we need to declare PublishProfileRootFolder before it's imported -->
    <WebPublishPipelineProjectDirectory Condition="'$(WebPublishPipelineProjectDirectory)'==''">$(MSBuildProjectDirectory)</WebPublishPipelineProjectDirectory>

    <!-- IMPL: Usually detected by ".csproj" vs ".vbproj", but PackageDeploy.build is neither -->
    <PublishProfileRootFolder Condition="'$(PublishProfileRootFolder)' == '' and Exists('My ProjectPublishProfiles')">$(WebPublishPipelineProjectDirectory)My ProjectPublishProfiles</PublishProfileRootFolder>
    <PublishProfileRootFolder Condition="'$(PublishProfileRootFolder)' == '' and Exists('PropertiesPublishProfiles')">$(WebPublishPipelineProjectDirectory)PropertiesPublishProfiles</PublishProfileRootFolder>
  </PropertyGroup>

  <!-- IMPL: Select the correct version of Microsoft.Web.Publishing.targets (usually done by the csproj via WebApplication.targets) -->
  <Import Project="$(MSBuildExtensionsPath32)MicrosoftVisualStudio$(VisualStudioVersion)WebMicrosoft.Web.Publishing.targets" />

  <!-- FIX: MSDeployPublish depends on building the package (can be skipped by clearing MSDeployPublishDependsOn) -->
  <!-- IMPL: ImportPublishingParameterValues transforms all the MSDeployParameterValue+ParameterValue to MsDeployDeclareParameters+Value -->
  <Target Name="DeployFromPackage" Condition="'$(PublishProfile)' != ''" DependsOnTargets="ImportPublishingParameterValues">

    <PropertyGroup>
      <_PublishMsDeployServiceUrl>$(MsDeployServiceUrl)</_PublishMsDeployServiceUrl>
      <_PublishMsDeployServiceUrl Condition="('$(MSDeployPublishMethod)'=='INPROC')"></_PublishMsDeployServiceUrl>
    </PropertyGroup>

    <ItemGroup>
      <!-- IMPL: Always uses "package" source -->
      <MsDeploySourceProviderSetting Remove="@(MsDeploySourceProviderSetting)" />
      <MsDeploySourceProviderSetting Include="package">
        <Path>@(_MSDeployPackageFile->'%(FullPath)')</Path>
        <EncryptPassword>$(DeployEncryptKey)</EncryptPassword>
        <WebServerAppHostConfigDirectory>$(_MSDeploySourceWebServerAppHostConfigDirectory)</WebServerAppHostConfigDirectory>
        <WebServerManifest>$(_MSDeploySourceWebServerManifest)</WebServerManifest>
        <WebServerDirectory>$(_MSDeploySourceWebServerDirectory)</WebServerDirectory>
      </MsDeploySourceProviderSetting>

      <MsDeployDestinationProviderSetting Remove="@(MsDeployDestinationProviderSetting)" />
      <MsDeployDestinationProviderSetting Include="auto">
        <Path></Path>
        <ComputerName>$(_PublishMsDeployServiceUrl)</ComputerName>
        <UserName>$(UserName)</UserName>
        <Password>$(Password)</Password>
        <EncryptPassword>$(DeployEncryptKey)</EncryptPassword>
        <IncludeAcls>False</IncludeAcls>
        <AuthType>$(AuthType)</AuthType>
        <WebServerAppHostConfigDirectory>$(_MSDeployDestinationWebServerAppHostConfigDirectory)</WebServerAppHostConfigDirectory>
        <WebServerManifest>$(_MSDeployDestinationWebServerManifest)</WebServerManifest>
        <WebServerDirectory>$(_MSDeployDestinationWebServerDirectory)</WebServerDirectory>
      </MsDeployDestinationProviderSetting>
    </ItemGroup>

    <!--Debug/Diagnostic message is not localized-->
    <Message Text="MSDeployPublish MsDeploySourceProviderSetting is @(MsDeploySourceProviderSetting)" Condition="$(EnablePackageProcessLoggingAndAssert)" />
    <Message Text="MSDeployPublish MsDeployDestinationProviderSetting is @(MsDeployDestinationProviderSetting)" Condition="$(EnablePackageProcessLoggingAndAssert)"/>

    <ExportParametersFile
      Condition="!$(UseDeclareParametersXMLInMsDeploy) And $(EnablePackageProcessLoggingAndAssert)"
      Parameters="@(MsDeployDeclareParameters)"
      DeclareSetParameterFile="$(PackageLogDir)MSDeployPublish.parameters.xml"
      GenerateFileEvenIfEmpty="True"
      />

    <!--First delete the ParameterFile-->
    <Delete Files="$(PublishParametersFile)"  Condition="Exists($(PublishParametersFile))" ContinueOnError="true"/>

    <!-- FIX: Use SetParameterFile (rather than DeclareSetParameterFile), which isn't used anywehere in Microsoft.Web.Publishing.targets -->
    <ExportParametersFile
      Parameters="@(MsDeployDeclareParameters)"
      SetParameterFile="$(PublishParametersFile)"
      GenerateFileEvenIfEmpty="True"
      Condition="$(UseDeclareParametersXMLInMsDeploy)"
      />

    <PropertyGroup>
      <_VsPublishParametersFile></_VsPublishParametersFile>
      <_VsPublishParametersFile Condition="$(UseDeclareParametersXMLInMsDeploy) and '$(_VsPublishParametersFile)'==''">$(PublishParametersFile)</_VsPublishParametersFile>
    </PropertyGroup>

    <ItemGroup Condition="!$(UseDeclareParametersXMLInMsDeploy)">
      <_VsPublish_MsDeployDeclareParameters Remove="@(_VsPublish_MsDeployDeclareParameters)" />
      <_VsPublish_MsDeployDeclareParameters Include="@(MsDeployDeclareParameters)" />

      <!-- IMPL: Utilising the real version of this has way too much baggage (simplifying it could have repercussions, though) -->
      <_VsPublish_MsDeployDeclareParameters Include="$(DeployParameterIISAppName)" Condition="'$(DeployIisAppPath)' != ''">
        <Value>$(DeployIisAppPath)</Value>
      </_VsPublish_MsDeployDeclareParameters>
    </ItemGroup>

    <!-- FIX: Microsoft.Web.Publishing.targets uses "SetParameterItems", which doens't appear to work. This uses SimpleSetParameterItems instead  -->
    <VSMSDeploy
      Condition="!$(UseMsdeployExe)"
      MSDeployVersionsToTry="$(_MSDeployVersionsToTry)"
      Source="@(MsDeploySourceProviderSetting)"
      Destination="@(MsDeployDestinationProviderSetting)"
      DisableLink="$(PublishDisableLinks)"
      EnableLink="$(PublishEnableLinks)"
      AllowUntrustedCertificate="$(AllowUntrustedCertificate)"
      BuildingInsideVisualStudio="$(BuildingInsideVisualStudio)"
      SkipExtraFilesOnServer="$(SkipExtraFilesOnServer)"
      SkipRuleItems="@(MsDeploySkipRules)"
      OptimisticParameterDefaultValue="$(EnableOptimisticParameterDefaultValue)"
      SimpleSetParameterItems="@(_VsPublish_MsDeployDeclareParameters)"
      ImportSetParametersItems="$(_VsPublishParametersFile)"
      RetryAttempts="$(RetryAttemptsForDeployment)"
      InvokedByPublish="true"
    >
      <Output TaskParameter="Result" PropertyName="_PublishResult" />
    </VSMSDeploy>

    <!-- FIX: Microsoft.Web.Publishing.targets uses "SetParameterItems", which doens't appear to work. This uses SimpleSetParameterItems instead  -->
    <MSdeploy
          Condition="$(UseMsdeployExe)"
          Verb="sync"
          Source="@(MsDeploySourceProviderSetting)"
          Destination="@(MsDeployDestinationProviderSetting)"
          DisableLink="$(PublishDisableLinks)"
          EnableLink="$(PublishEnableLinks)"
          EnableRule="$(MsDeployDoNotDeleteRule)"
          AllowUntrusted="$(AllowUntrustedCertificate)"
          SkipRuleItems="@(MsDeploySkipRules)"
          OptimisticParameterDefaultValue="$(EnableOptimisticParameterDefaultValue)"
          SimpleSetParameterItems="@(_VsPublish_MsDeployDeclareParameters)"
          ImportSetParametersItems="$(_VsPublishParametersFile)"
          RetryAttempts="$(RetryAttemptsForDeployment)"
          ExePath="$(MSDeployPath)" />
  </Target>

</Project>

这篇关于使用发布配置文件部署现有包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆