Update Azure CSPKG with a transformed web.config post-publish
Asked Answered
S

3

6

My build:

  1. Build with msbuild (/t: build)
  2. Publish with msbuild (/t: publish)
  3. Package with nuget
  4. Deploy with octopus

produces an artifact (nuget package) that contains the following files:

  • Azure.ccproj.cspkg
  • ServiceConfiguration.Production.csfg
  • Web.config (which will be transformed during deployment via Octopus)

The cspkg is a valid, deployable package. The problem is that it contains a web.config that is pre-transform because the transform occurs at deployment time. See the Octopus documentation for transforms and variable substitution for reference.

How do I overwrite the web.config inside the cspkg with the transformed web.config that resides in the deployment package?

I have powershell and the full .net framework at my disposal.

Alternatively, if it makes more sense to unpack the cspkg, overwrite the file and then re-package, I consider that acceptable. I am not sure how to do that either.

I know that Save-AzureServiceProjectPackage exists but I cannot get it to run and the documentation is lacking.

Silden answered 9/10, 2014 at 16:16 Comment(0)
S
0

I have figured out how to do what I need based upon the information contained in Brad Webber's post in the Octopus Support forum.

I have posted a public git repo containing a simple sample solution and documentation here.

Silden answered 9/10, 2014 at 21:10 Comment(0)
H
1

I have an Octopus project with 2 steps: first for Dev hosted in IIS, second for Prod hosted in Azure. TeamCity procuded 2 nuget packages: one by OctoPack for Dev, another by NuGet Pack for Prod with cspkg.

I have this target in my Azure.ccproj:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="Transform" BeforeTargets="BeforeBuild" Condition="'$(TEAMCITY_VERSION)' != ''">
  <PropertyGroup>
      <SourceTransformFile>..\Api\Web.config</SourceTransformFile>
      <TransformFile>..\Api\Web.Prod.config</TransformFile>
      <DestinationTransformFile>..\Api\Web.config</DestinationTransformFile>
  </PropertyGroup>
  <TransformXml
      Source="$(SourceTransformFile)"
      Transform="$(TransformFile)"
      Destination="$(DestinationTransformFile)" />
</Target>

The condition allows to run in only on the build server and not locally.

Heteroecious answered 9/10, 2014 at 17:52 Comment(3)
Thanks for your answer but it does not meet my needs. I know how to perform transforms using the TransformXml task. That is a build-time transform. I am dependent upon Octopus' deploy-time transforms so this solution does not solve my problem.Silden
@David: per my knowledge Octopus doesn't perform transformation inside cspkg in v.2, it's going to change in v.3 though. So I think the only way is to transform manually, then pack and send to OD.Heteroecious
Agreed with your first sentence. I have figured out how to do it. Posted the reference to the solution in my answer.Silden
K
1

I have solved this by sending the solution as it is to Octopus Deploy which allows me to run .config transformations in Octopus. After running the transformations I create the .cspkg package with custom powershell script.

I have written a thorough post of the Octopus deploying part. You can find it here: http://henrihietala.github.io/

Kwon answered 21/10, 2014 at 10:48 Comment(0)
S
0

I have figured out how to do what I need based upon the information contained in Brad Webber's post in the Octopus Support forum.

I have posted a public git repo containing a simple sample solution and documentation here.

Silden answered 9/10, 2014 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.