2
votes

Current client we are setting up CI/CD using VSO => Azure devops and I need some help with the configuration of the releases in the environments. Here's the situation and issue.

I've got the builds all set up and working properly.

I've got 2 Environments set up in the release configuration. Artifact is set up for the drops. Dev environment is set up as well as QA.

In VS2015 I've got the web.config transforms and configurations set up for Debug, Dev, QA, and Release. Dev/QA/Release each have a transformation that is to be applied for their respective enviornment.

Build triggers upon checkin and the release deployment triggers correctly upon successful build.

Dev environment and QA environment both trigger correctly in the release and are released accordingly.

In the task configuration for each I've got the XML Transformation selected as well as the correct deployment slot. The issue is that the only web.config transformation that is being applied is the release transformation not the correct transformation for the respective environment.

I have 4 transformation configs in the environment set up.

web.config

web.Debug.config web.Dev.config web.QA.config web.Release.config

in VSO I have 2 environments set up in the Release Package

Dev & QA

In each of the environment I have the XML Transformation check which the tooltip states that it will apply the web.Release.config and each respective environment config.

The later is not happening.

logs:

the logs state:

Unable to apply transformation for the given package. Verify the following.

 1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the tag for each config in the csproj file and rebuild.

 2. Ensure that the config file and transformation files are present in the same folder inside the package.

Both of those states have been confirmed. I've got the transform configs set to copy if newer.

enter image description here

enter image description here


     <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
  <Import Project="..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props')" />
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{88941EE6-99FC-4DE5-8FE3-9F532FD855F2}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>TripManager</RootNamespace>
    <AssemblyName>TripManager</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>true</UseIISExpress>
    <IISExpressSSLPort>44385</IISExpressSSLPort>
    <IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication>
    <IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>
    <IISExpressUseClassicPipelineMode />
    <UseGlobalApplicationHostFile />
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
    <TargetFrameworkProfile />
    <Use64BitIISExpress />
    <TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>
    <ApplicationInsightsResourceId>/subscriptions/ee4492d7-5913-4e7b-85c0-3915e8c6c5c2/resourcegroups/rg-TripTracker-dev-SC/providers/microsoft.insights/components/TripManager</ApplicationInsightsResourceId>
    <WebProject_DirectoryAccessLevelKey>1</WebProject_DirectoryAccessLevelKey>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'QA|AnyCPU'">
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>

</Project>

2
Did you enable verbose logging and look at the logs? Are the environment-specific transform files present in the package being deployed? - Daniel Mann
@DanielMann updated post to answer question. - David Yancey
@DavidYancey Can you show the detail release logs by adding a release variavle system.debug as true? - Marina Liu
And can you also show the .csproj file? - Marina Liu
@MarinaLiu-MSFT I've added the .csproj file removing the itemgroup. As for the logs all that is shown is:  Unable to apply transformation for the given package. Verify the following. 1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the <DependentUpon> tag for each config in the csproj file and rebuild. 2. Ensure that the config file and transformation files are present in the same folder inside the package. - David Yancey

2 Answers

6
votes

The problem is that config transform files are not included in the build result.

Ensure that the config file and transformation files are present in the same folder inside the package.

Marina Liu's answer could work, but there is a much simpler way to achieve this:

  1. The transform file should not be Dependent upon web.config. Just create a new file in the same directory as the web.config file.
  2. Set the Build Action of the transform file to Content.

Or just change the entry in the .csproj file from this:

<None Include="Web.QA.config">
    <DependentUpon>Web.config</DependentUpon>
</None>

To this:

<Content Include="Web.QA.config" />

This makes sure the files are included in the package after build.

2
votes

No matter whether the transformation is applied for the MSBuild generated package or not, add the config files to the zipped package (as option 2 in release log suggests: Ensure that the config file and transformation files are present in the same folder inside the package) should work.

So you can add the config files in your build definition before the artifacts published. Detail steps as below:

After Visual Studio Build task (and before Publish Build Artifacts) and the following tasks to extract the zip file and add config files in the extract folder, then zip the files again:

1. Extract files task

Archive file patterns: $(Build.ArtifactStagingDirectory)\*.zip

Destination folder: specify the folder for the extract files, such as $(Build.ArtifactStagingDirectory)\test

enter image description here

2. Copy Files task

Source Folder: $(Build.SourcesDirectory)

Contents: **\*.config

Target Folder: Folder for the extract files, such as $(Build.ArtifactStagingDirectory)\test

enter image description here

3. Delete Files task

Source Folder: $(Build.ArtifactStagingDirectory)

Contents: *.zip (delete the zip file which generated by Visual Studio Build task)

enter image description here

4. Archive Files task

Root folder (or file) to archive: Folder for the extract files, such as $(Build.ArtifactStagingDirectory)\test

Archive type: zip

Archive file to create: such as $(Build.ArtifactStagingDirectory)\package.zip

enter image description here

5. Delete Files task

Source Folder: $(Build.ArtifactStagingDirectory)

Contents: delete the extract folder,such as test

enter image description here

Then the package will be deployed to Azure App Service successful in release.