4
votes

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.

3

3 Answers

1
votes

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.

1
votes

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/

0
votes

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.