It is currently Tue May 21, 2013 10:18 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to make manifest files for use by portable applications
PostPosted: Tue Apr 06, 2010 9:07 pm 
Offline

Joined: Tue Mar 09, 2010 7:36 pm
Posts: 197
I have recently started using the Mercurial distributed source control management application, I was previously using Subversion and had a Subversion directory with all the binaries so I could use it portably, this was not so easy with Mercurial due to its use of the new Windows Side By Side (SxS) assemblies.

http://en.wikipedia.org/wiki/Side-by-side_assembly

I eventually managed to create a portable version and have decided to write a tutorial so others can too. This example will use Mercurial as an example but I'm sure it can be applied to any SxS app.

Required apps:

Universal Extractor: http://www.portablefreeware.com/index.php?id=641

Only required if you want to follow along with how I determined the dependencies:

FileMon: http://www.portablefreeware.com/index.php?id=179
Mercurial: http://mercurial.selenic.com/downloads/ (not the TortoiseHG install)


Extract the installer using Universal Extractor.

Copy all the files out of "PFiles" to your desired Mercurial application directory.

Open the extracted "Windows\system32" directory and copy the dll files to your desired Mercurial application directory.

Open the extracted "Windows\winsxs\Manifests" directory and copy the manifest files to your desired Mercurial application directory.

The version numbers of the dll files should match the version number in the filename of their manifest files, in my case, for VC90.CRT, it was 9.0.30729.1.

Rename the copied manifest files so the filename is the same as the "name" attribute within the file, it should be in the filename anyway, you just need to truncate it. eg. Microsoft.VC90.CRT.manifest

Open the manifest file and start culling those attributes, the following is all you need in the file:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <noInheritable/>
  <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="x86"/>
    <file name="msvcr90.dll" hashalg="SHA1" hash="9785b1c493deb5b2134dc4aef3719cee207001bc"/>
    <file name="msvcp90.dll" hashalg="SHA1" hash="0f6bbf7fe4fb3fca2cb5b542eca1a1cad051f01c"/>
    <file name="msvcm90.dll" hashalg="SHA1" hash="7f3290ab2b7444c2b4a9b1fedfdb16466d7a21bb"/>
</assembly>
I presume the "type" needs to be changed to win64 if you have a 64 bit processor, I don't know, I haven't got one.

Note the "name", "version", "file name" and "hash" attributes. The name must be the same as the file name, the version must match the version of the dlls you copied earlier and the hash must be the correct SHA1 hash of the file listed in the file name attribute, you won't need to change any of these if you got the correct manifest file for the dlls.

It is very important that you remove any "publicKeyToken" attributes from ALL manifest files, that attribute causes the application to try and find the required dlls in the SxS directory, we don't want that to happen. Save and close the file.

During my trial and error experience working this out, I used FileMon to find out which files the application was trying to read, one of the first files it tries to find is "hg.exe.manifest". Applications typically have a manifest embedded in the executable, you can see this using a resource extractor, but they will also look for an additional manifest file in the same directory as the executable.

You can either use a resource extractor (http://www.portablefreeware.com/index.php?sc=113)to get the application manifest file or write your own, I wrote my own, it's very easy.

Copy one of the manifest files you copied to the application directory earlier and rename it to: hg.exe.manifest

Open this manifest file in a text editor and change it so it resembles the following:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="x86"/>
    </dependentAssembly>
  </dependency>
</assembly>
As before, the "type" may need to be changed if you use a 64 bit processor.

Ensure that the "name" matches the "name" in the other manifest file, if there are multiple assembly manifests then just add "dependency" elements as required, eg:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="x86"/>
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.MFC" version="9.0.30729.4148" processorArchitecture="x86"/>
    </dependentAssembly>
  </dependency>
</assembly>
Once you have these two manifests done, the application SHOULD run, but in this case it won't, if you are following along with FileMon then you will see that hg.exe starts python26.dll and then tries to find python26.dll.2.manifest. Looks like we need to create another manifest file.

This one is easy though, copy hg.exe.manifest and rename it to python26.dll.2.manifest, that's it.

hg.exe should run portably now, if you are watching with FileMon you will see that it looks in the application directory for the dlls and only in the system folders for generic libraries that are not application specific and should be on all systems, eg comctl32.dll.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group