Genexus Deployment Engine is a powerful tool that allows you to deploy your Genexus generated applications to either on-premises servers or to a vast range of Cloud Providers.
Its sole purpose is to traverse what's called the "references tree" to figure out what are all the needed objects for your application to run properly on a production environment.
But sometimes you need something that's not in the Knowledge Base, or for some reason, you need to remove something from the Knowledge Base, say for security reasons, or if for instance some objects have references to objects that you know, and are positive, that these are not used at runtime. And maybe you want to run a custom script before moving to production, before creating the war or zip file.
The generation of the war or zip file consists of two tasks. The first one (CreateDeployProject) will generate an MSBuild script file with the extension .gxdproj, which contains every GeneXus object form your Knowledge Base that is involved in the deployment of the selected Deployment unit or objects. The second task (CretePackage), takes the previously generated gxdproj file, and based on its contents, tries to find every file generated for every declared object. More on these tasks here: Application Deployment MSBuild tasks.
When the CreateDeployProject task executes, it will look for a file called <Deployment Unit Name> _user.gxdproj. If it does not exist, it will be created but never overwritten.
At first, the file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!--AdditionalDirectory>some directory to copy</AdditionalDirectory-->
<!-- You can add a directory where every AdditionalFile will be copied (relative to the root) -->
<!--AdditionalFile Include="some File to copy"/-->
This file will be copied to $(DeployFullPath)\$(AdditionalFileDestination)
This file will be copied to $(DeployFullPath)\TargetDir
<AdditionalFile Include="C:\myfiles\my other file.txt">
<!-- Uncomment this section in case you want to delete files right before creating the package
<Message Text="RemovingUserExcludedFiles" Importance="high" />
<Target Name="BeforePackaging" DependsOnTargets="RemoveExtraFiles">
Notice there's an AdditionalDirectory tag. You can add as many tags as you wish with all the directories you want to add. Keep in mind this will copy every file and directories in the destination, following the original structure.
There's also a tag called AdditionalFile which allows you to add as many files as you wish.
But where will these files be copied? You have two options for this. You can set a default destination folder with the tag AdditionalFileDestination. If you set a path there, every file will be copied into that destination. Alternatively, you set an additional property to your files called RelativeTargetDir. This is a property that only applies to the file it belongs to, and assures that the mentioned file will be copied into that directory.
There's a whole target for that called RemoveExtraFiles.
In the ItemGroup in that target, you need to add every file you want to delete. Keep in mind that you can use wild cards (*) for either file names and/or directories.
The last task of the target deletes every file included in the UneededFiles item group.
The last target of the user.gxdproj file is called BeforePackaging and will be run exactly when you think, right before creating the package. So, at this point everything is in place, the extra files you added, and the ones you wanted to delete are gone. In this target, you can run your own scripts by calling the Exec task or adding the imports needed to call your own tasks.
Keep in mind that in this process there a few variables you can use:
$(DeployFullPath): the absolute path where the deploy engine is copying files.
$(WebPath): this is the web directory from the source environment.
This feature is available since GeneXus 16 upgrade 10.