Custom Tasks

AppFactory currently uses five tasks that are not part of the standard MSBuild package. Two of the custom tasks come from the exceptional MSBuld Extension Pack and three of them are part of the AppFactory project itself. The sections below explain how each task is used.


AssemblyInfo

The AssemblyInfo task comes from the MSBuld Extension Pack. It's used to update one important file in the template project: AssemblyInfo.cs. This file contains information like company name, version number, product GUID, etc. These values are important to the emulator and your test devices as they're evaluated when deploying and uninstalling applications. AppFactory uses this task to make sure AssemblyInfo.cs is updated to match the same values in the Application record.

For more information about this task see AssemblyInfo.


DbRowsToItems

DbRowsToItems is an AppFactory task defined in AppFactory.Tasks.dll. Its job is to load rows from the Applications table and convert them into MSBuild Items. MSBuild Items are normally used to represent files, but since they have metadata they can be used to represent almost anything. By converting Application records into Application "Items" we can make the data available throughout the build process and even make decisions in the build based on that data. Having the data available as an Item also allows us to pass it into other tasks (like the ItemToReplaceParams task below).

DbRowsToItems uses OleDbConnection and OleDbCommand to query the data. This provides flexibility on where Application data is stored. The sample AFProj File uses this task to load data from a Microsoft Access database, but the same data could just as easily be stored in SQL Server or even Microsoft Excel. All that's needed is the installed OleDb driver and the correct connection string.

For more information about using a custom data source see Application Data.


Detokenize

The Detokenize task comes from the MSBuld Extension Pack. It's used to execute "search and replace" across files in the template project. The items that get replaced are called tokens and the default token format is $(TokenName). The replacement values can come from anywhere, but the sample AFProj File exposes every column in the Applications table as $(Application.ColumnName). So, if a file in the template project had $(Application.Title) somewhere in it, that text might get replaced with The Denver Broncos (assuming "The Denver Broncos" was in the Title column in the Appplications table).

The sample AFProj File does a search and replace on WMAppManifest.xml and on all .Xaml files. WMAppManifest.xml controls things like the product GUID (important in the emulator) and application title. .Xaml files control the screens and resource dictionaries of applications so it makes sense to do detokenize those files too. You'll notice that by default .cs files are not detokenized, but these are just the defaults. The Detokenize task can be used to to detokenize values in any files.

For more information about this task see Detokenize.



ItemToReplaceParams

ItemToReplaceParams is an AppFactory task defined in AppFactory.Tasks.dll. The Detokenize task (mentioned above) is used to replace token values inside of template files, but the Detokenize task still needs to know which tokens to replace and which values to use.

By the time replacement values are needed in the build, DbRowsToItems (mentioned above) will have already been used to load columns from the Application table into MSBuild Items. The ItemToReplaceParams task is used to take the MSBuild Item that represents the current application and converts all of its metadata properties into replacement values with the "Application." prefix. This is how values like "Application.Title" flow from the database, through the build, and into tokens in the template files.

The sample AFProj File only uses ItemToReplaceParams to convert the Application Item into replacement values, but this task can be used with any MSBuild Item that has metadata.



OleDbExecute

OleDbExecute is an AppFactory task defined in AppFactory.Tasks.dll. It can be used to execute any arbitrary SQL statement against an OleDB data source. The sample AFProj File uses this task to update the LastBuilt column in the Applications table after each application is built.

This task is similar to the SqlExecute task that is part of the MSBuld Extension Pack.

Last edited Mar 5, 2012 at 4:31 PM by jaredbienz, version 9

Comments

No comments yet.