Troubleshooting the Packaging Process
by Jason Lee
This topic describes how you can collect detailed information about the packaging process by using the EnablePackageProcessLoggingAndAssert property in the Microsoft Build Engine (MSBuild).
When you set the EnablePackageProcessLoggingAndAssert property to true, MSBuild will:
- Add additional information about the packaging process to the build logs.
- Log errors under certain conditions, for example, if duplicate files are found in the packaging list.
- Create a Log directory in the ProjectName_Package folder and use it to record information about the files you’re packaging.
If the packaging process is failing, or your web deployment packages don’t contain the files that you expect, you can use this information to troubleshoot the process and pinpoint where things are going wrong.
[!NOTE] The EnablePackageProcessLoggingAndAssert property only works if you build your project using the Debug configuration. The property is ignored in other configurations.
This topic forms part of a series of tutorials based around the enterprise deployment requirements of a fictional company named Fabrikam, Inc. This tutorial series uses a sample solution—the Contact Manager solution—to represent a web application with a realistic level of complexity, including an ASP.NET MVC 3 application, a Windows Communication Foundation (WCF) service, and a database project.
The deployment method at the heart of these tutorials is based on the split project file approach described in Understanding the Project File, in which the build process is controlled by two project files—one containing build instructions that apply to every destination environment, and one containing environment-specific build and deployment settings. At build time, the environment-specific project file is merged into the environment-agnostic project file to form a complete set of build instructions.
Understanding the EnablePackageProcessLoggingAndAssert Property
Building and Packaging Web Application Projects described how the Web Publishing Pipeline (WPP) provides a set of MSBuild targets that extend the functionality of MSBuild and enable it to integrate with the Internet Information Services (IIS) Web Deployment Tool (Web Deploy). When you package a web application project, you’re invoking WPP targets.
Lots of these WPP targets include conditional logic that logs additional information when the EnablePackageProcessLoggingAndAssert property is set to true. For example, if you review the Package target, you can see that it creates an additional log directory and writes a list of files to a text file if EnablePackageProcessLoggingAndAssert is equal to true.
[!code-xmlMain]
1: <Target Name="Package"
2: Condition="$(_CreatePackage)"
3: DependsOnTargets="$(PackageDependsOn)">
4:
5: <!--Log the information Set $(EnablePackageProcessLoggingAndAssert) to True
6: if you want to see this information-->
7: <MakeDir Condition="$(EnablePackageProcessLoggingAndAssert) And
8: !Exists('$(PackageLogDir)')"
9: Directories="$(PackageLogDir)" />
10: <WriteLinesToFile Condition="$(EnablePackageProcessLoggingAndAssert)"
11: Encoding="utf-8"
12: File="$(PackageLogDir)\Prepackage.txt"
13: Lines="@(FilesForPackagingFromProject->'
14: From:%(Identity)
15: DestinationRelativePath:%(DestinationRelativePath)
16: Exclude:%(Exclude)
17: FromTarget:%(FromTarget)
18: Category:%(Category)
19: ProjectFileType:%(ProjectFileType)')"
20: Overwrite="True" />
[!NOTE] The WPP targets are defined in the Microsoft.Web.Publishing.targets file in the %PROGRAMFILES(x86)%
Enabling the Additional Logging
You can supply a value for the EnablePackageProcessLoggingAndAssert property in various ways, depending on how you build your project.
If you build your project from the command line, you can supply a value for the EnablePackageProcessLoggingAndAssert property as a command-line argument:
[!code-consoleMain]
1: MSBuild.exe /t:Build
2: /p:Configuration=DEBUG
3: /p:DeployOnBuild=true
4: /p:DeployTarget=Package
5: /p:EnablePackageProcessLoggingAndAssert=true
6: [Your project].csproj
If you’re using a custom project file to build your projects, you can include the EnablePackageProcessLoggingAndAssert value in the Properties attribute of the MSBuild task:
[!code-xmlMain]
1: <Target Name="BuildProjects" Condition=" '$(BuildingInTeamBuild)'!='true' ">
2: <MSBuild Projects="@(ProjectsToBuild)"
3: Properties="OutDir=$(OutputRoot);
4: Configuration=$(Configuration);
5: DeployOnBuild=true;
6: DeployTarget=Package;
7: EnablePackageProcessLoggingAndAssert=true"
8: Targets="Build" />
9: </Target>
If you’re using a Team Foundation Server (TFS) build definition to build your projects, you can supply a value for the EnablePackageProcessLoggingAndAssert property in the MSBuild Arguments row:
[!NOTE] For more information on creating and configuring build definitions, see Creating a Build Definition That Supports Deployment.
Alternatively, if you want to include the package in every build, you can modify the project file for your web application project to set the EnablePackageProcessLoggingAndAssert property to true. You should add the property to the first PropertyGroup element within your .csproj or .vbproj file.
[!code-xmlMain]
1: <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="...">
2: <PropertyGroup>
3: <EnablePackageProcessLoggingAndAssert
4: Condition=" '$(EnablePackageProcessLoggingAndAssert)' == '' ">
5: true
6: </EnablePackageProcessLoggingAndAssert>
7: <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8: <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Reviewing the Log Files
When you build and package a web application project with EnablePackageProcessLoggingAndAssert set to true, MSBuild creates an additional folder named Log in the ProjectName_Package folder. The Log folder contains various files:
The list of files that you see will vary according to the things in your project and your build process. However, these files are typically used to record the list of files that the WPP is collecting for packaging, at various stages of the process:
- The PreExcludePipelineCollectFilesPhaseFileList.txt file lists the files that MSBuild collects for packaging before any files that are specified for exclusion are removed.
The AfterExcludeFilesFilesList.txt file contains the modified file list after any files that are specified for exclusion are removed.
[!NOTE] For more information on excluding files and folders from the packaging process, see Excluding Files and Folders from Deployment.
- The AfterTransformWebConfig.txt file lists the files collected for packaging after any Web.config transforms have been performed. In this list, any configuration-specific Web.config transform files, like Web.Debug.config and Web.Release.config, are excluded from the list of files for packaging. A single transformed Web.config is included in their place.
- The PostAutoParameterizationWebConfigConnectionStrings.txt file contains the list of files after the connection strings in the Web.config file have been parameterized. This is the process that lets you replace your connection strings with the right settings for your target environment when you deploy the package.
The Prepackage.txt file contains the finalized pre-build list of files to be included in the package.
[!NOTE] The names of the additional log files typically correspond to WPP targets. You can review these targets by examining the Microsoft.Web.Publishing.targets file in the %PROGRAMFILES(x86)%
If the contents of your web package aren’t what you expected, reviewing these files can be a useful way to identify at what point in the process things went wrong.
Conclusion
This topic described how you can use the EnablePackageProcessLoggingAndAssert property in MSBuild to troubleshoot the packaging process. It explained the different ways in which you can supply the property value to the build process, and it described the additional information that is recorded when you set the property to true.
Further Reading
For more information on using custom MSBuild project files to control the deployment process, see Understanding the Project File and Understanding the Build Process. For more information on the WPP and how it manages the packaging process, see Building and Packaging Web Application Projects. For guidance on how to exclude specific files and folders from web deployment packages, see Excluding Files and Folders from Deployment.
|