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

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

问题描述

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

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年1月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中生成,带有包

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\to\ProfileName.parameters.xml when calling deploy.cmd

更新-此脚本的较新版本现已在GitHub上维护(并记录在文档中)-

UPDATE - A newer version of this script is now being maintained (and documented) on 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=Path\To\Profile.pubxml;PackageFileName=Path\To\Package.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(如下)
  • 您的发布个人资料
  • 网络应用程序包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 Project\PublishProfiles')">$(WebPublishPipelineProjectDirectory)\My Project\PublishProfiles</PublishProfileRootFolder>
    <PublishProfileRootFolder Condition="'$(PublishProfileRootFolder)' == '' and Exists('Properties\PublishProfiles')">$(WebPublishPipelineProjectDirectory)\Properties\PublishProfiles</PublishProfileRootFolder>
  </PropertyGroup>

  <!-- IMPL: Select the correct version of Microsoft.Web.Publishing.targets (usually done by the csproj via WebApplication.targets) -->
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\$(VisualStudioVersion)\Web\Microsoft.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天全站免登陆