Putting your App-V Scripts directly into the .AppV 5.1 file

Using Scripts to aid the deployment of App-V packages makes the virtual applications more flexible and deployable in production.  Prior to the App-V 5.1 release, this was done by manually editing the external Deployment and/or User Configuration.xml files.  Not only was the editing originally a clunky process (leading to the development of a free editor tool ACE to edit those files), but we found that dealing with these external files was cumbersome.  If you used the App-V Management Server or Stand-alone models to deploy your packages, you could easily forget to use the external files. And if you used Config Manager instead to deploy the files were automatically applied, but, it was possible to forget that only editing the Deployment config meant that the UserConfig file might override the change.

Last year we noticed that the virtual Office 2013/365 package created by the Office Deployment Toolkit included scripts inside the AppXManifest file packed up in the .AppV file and so we requested a feature to expose this capability to all apps via the Sequencer.  This feature was included in version 5.1 of App-V.

The process still involves editing a finicky XML file, so independently ACE was expanded to support this file, and I created a new tool AppVManifestEditor (AVME) to do so.  Using ACE allows you to have one tool that works with either file, but the free AVME tool provides more editing features to the internal file than ACE, and AVME probably works better in the workflow of sequencing since you don’t have to save the package off and then reopen to import the changes.

In our training class last week, one of the students raised a question about how best configure their Java package that turned into an exercise to use the AppVManifestEditor tool.  While the initial attempt failed (explained in the note at the end of this post), we proved the process of editing scripts directly into the App-V package out, plus we learned just how picky the XML can be.  So here is the story…

Java includes a deployment.properties file that is written to the user’s local profile in a subfolder structure under the user’s AppData/Local folder.  The customer wanted to include a customized version of this file in the package.

The AppData/Local  folder is excluded by default when sequencing App-V.  Removing the exclusion would be the quick answer, but Java puts a lot of other stuff under AppData/Local that we didn’t included in the package.  So instead we decided to copy the desired file into our package and then use a Publish-Package script to copy it to the native system where the package would pick it up.

When scripting in App-V, you need to remember that the user publishing scripts run in the user’s security context, but not with the user’s environment block, but a system one.  This means you can’t use the username, homedrive, or other variables that you are used to using to reference user profile locations.  So our script needed to use the free TMurgent ScriptLauncher tool.  This exe is copied into the package along with the required file.  The script we want to run uses the ScriptLauncher.exe tool to call “cmd.exe /c” with a copy command to copy the file.  We need ScriptLauncher so that we can use a variable it defines, %EffectiveUserName%, as part of the destination path for the copy command.  Here is how all this works:

1) You start by sequencing the package as normal, getting to the multi-tabbed Sequence Editor.

2) After making all other changes, on the Package Files tab of the editor, you right-click on the Scripts folder and add the files we want to use in scripting [Note: we don’t have to place the files inside the package, nor must we place them in this folder, but doing it this way keeps the files inside the package and separated out so it is clear what their purpose is]:

We can use the App-V Variable [{AppVPackageRoot]} as a placeholder for the location at the client where the Root folder of the package will be (nominally C:\ProgramData\AppV\GuidOfPackageId\GuidOfPackageVersionId\Root). The Scripts folder created by the Sequencer for us is referenced relatively from there by going up one level ( “..\” ) and then to the scripts folder.

3) Next you click on the Advanced tab of the Sequence Editor.

Click on the new Manifest file Export button (new in App-V 5.1), and save the AppXManifest.xml file to a convenient place, like the desktop.

4) Minimize the sequencer and launch AppVManifestEditor (It is OK to install this in your sequencer image as it adds no new dependencies that might break your packages). Open the AppXManifest.xml file using the “…” button in the AppVManifestEditor. Click on the Scripts tab and add your scripts.

Most of the time, companies publish to the user and not the machine (-Global) account, so we want to edit the publish script in the User Scripts sub-tab. (If machine publishing is going to be used, we would have to use Start of Virtual Environment scripting since we don’t know who the user is at publishing time).

You check the checkbox on left to enable the type of script you want, then enter the Path and Arguments field and additional options to the right.

After editing, using AppVManifestEditor, save the file back to the desktop using the SaveAs button.

5) Using the Sequencer, import the changed XML file back in using the Import button on the Advanced tab. Now save the package off and test away!

_________________________

SIDE NOTE: The App-V variable name is case sensitive. During the class, we entered the name using a lower case “v” character [{AppvPackageRoot}] instead of [{AppVPackageRoot}], as shown in the image below:
This caused the script to fail as the client appears to assume that the string should be interpreted as a VFS folder, as is shown below:
It was hard to spot that error in the class. Even with several people staring at it we didn’t notice the problem during the class and I had to look into it offline. Fixing the case of this variable in the script solved the problem:

Links to free download tools mentioned in this post:

Name Vendor Link
AppV_Manage TMurgent http://www.tmurgent.com/appv/index.php/en/resources/AppV_Manage/221-appv-manage-introduction
AppVManifestEditor (AVME) TMurgent http://www.tmurgent.com/appv/index.php/en/resources/tools/348-avme
ScriptLauncher TMurgent http://www.tmurgent.com/appv/index.php/en/resources/tools/169-scriptlauncher-for-app-v-5
Applciation Configuration Editor (ACE) Virtual Engine http://virtualengine.co.uk/vet/ace/

Author: Tim Mangan

Microsoft MVP for App-V Citrix CTP