Can MS Deploy do a package and transform, but not deploy?

Using msbuild in .NET 4.0, I can build web project with the "Package" target, and it does a nice job of putting the package in a zip file. But, when I look at the web.config in there, it's not transformed, it has "$(ReplacableToken_Web_SiteConnection-Web.config Connection String_0)"

I can run the "TransformWebConfig" target and it will do the proper transform, but just in its own silo.

I can also run the "Build" target and pass the "DeployOnBuild=True;DeployTarget=MSDeployPublish" properties and it will deploy the package on my server with the proper web.config transform done.

But, if I want to manually deploy the package to the server, how do I do a "Package" with a "TransformWebConfig" so that the zip file has the final web.config in there?


If you want to skip this from happening then you need to set a property in your build. You can do this in two ways

  • Edit your project file
  • Create a .wpp.targets file
  • I would recommend #2. For this case create a new file in the same directory as your project file with the name {ProjectName}.wpp.targets where {ProjectName} is the name of your project. Then inside of this file you should place the following contents.

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
             ToolsVersion="4.0">
      <PropertyGroup>
        <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>
      </PropertyGroup>
    </Project>
    

    In this case you are setting the property AutoParameterizationWebConfigConnectionStrings which tells the Web Publishing Pipeline to not insert those {} placeholders in the web.config for the connection strings.


    The way we do this is by modifiying the project build to do the transform prior to packaging it up.

    The Target is call TransformXml and is a part of Microsoft.Web.Publishing.Tasks.dll

    In your own targets its

    <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)MicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.Tasks.dll"  /> 
    

    But it will be included in a default VS C# build.

    So

    <TransformXml Source="web.config" Transform="web.release.config" Destination="$(DeployPath)web.config" />
    

    Does the trick for us.

    Set up those paths with the right ItemGroup ("content" most likely) and make sure that target gets fired prior to the call to Package in your .csproj, and the build output will contain a "Web.config" like normal, with the right transformed values.

    Alternatively (we've used this for packages that need to be everything to everyone), you can use that trick to do ALL the transforms and include each of them in the final package.

    Then you call Msdeploy manually and use its skip and replace directives (forgot the technical term) to only output the right one at deploy-time

    Assuming you have a web.usethisone.config in your package, that looks like

    -skip:objectname=filepath,absolutepath=web..*.config 
    
    -replace:objectName=filepath,match=.*web.usethisone.config,replace=web.config
    
    链接地址: http://www.djcxy.com/p/81634.html

    上一篇: teamcity不执行msbuild命令

    下一篇: MS Deploy能做一个软件包并进行转换,但不能部署吗?