Mittwoch, 19. Juni 2013

Authoring a patch bundle

After the main program is deployed the maintenance will have to deploy fixpacks and service packs. I wondered how I should handle this with burn and decided to use a separate patch bundle.

Versioning used in this sample is MajorNumber.ServicePack.FixPack. Each patch bundle also has a separate UpgradeCode, because when removing bundle v1.0.0.1 while bundle v1.0.0.2 was installed  might leave the system with the v1.0.0.1 patch (issues about superseded patches.. see here).

Now I had several bundles, which all were authored to be a patch for the main bundle. That looks like this:
<Bundle Name="PatchingBundle 1.0.0.1" Version="1.0.0.1"
    Manufacturer="Jakob Devs Inc." UpgradeCode="[patch_bundle_code_v1.0.0.1]"
    ParentName="BaselineBootstrapper">
    <RelatedBundle Id="[parent_bundle_code]" Action="Patch" />
</Bundle>

There are several things of note here:
  • The UpgradeCode of this patch bundle is new, this leads to a separate entry in ARP's updates
  • ParentName: this puts the bundle in ARP's update section under the name BaselineBootstrapper. This should be the same for all patches.
  • RelatedBundle element: here I specify that this bundle patches the <parent_bundle>. This leads to this bundle being uninstalled when the <parent_bundle> is uninstalled. Cool :)
    To remove a Sp1Fp1 patch when the service pack is uninstalled, the parent_bundle_code will be the UpgradeCode of the ServicePack patch bundle.
Once a service pack is deployed, there'll be patches which target the service pack. These msp patches won't install on systems which don't have the service pack installed. I talked about that topic here.
To get  a state on the system where the user can remove installed patches, the burn engine offered me basically one solution:
Install every patch under a different UpgradeCode, so that all patch bundles show up in ARP.

The patch itself could theoretically be installed as superseding or not, I didn't find any difference so far. However, burn does not remove superseded patches, that's why I opted for non-superseding patches. They still all contain the diff to the baseline, though. Baselines will be the RTM or SP releases.
[Edit]: Apparently, an upgrade of version 1.0.0.x to 1.0.1 (yep, a service pack) always makes the patch superseding. That also means, when I'd uninstall bundle 1.0.0.1 while 1.0.1 is installed, the superseded patch stays on the system.

Just for the sake of completeness: what would the complete sequence of main installer, service pack, fix pack for SP look like?
<Bundle Name="Main RTM Bundle 1.0.0.0" Version="1.0.0.0"
    Manufacturer="Jakob Devs Inc." UpgradeCode="[main_bundle_code]" >
    <!-- no related bundle here ... -->
</Bundle>

The service pack is basically again a patch, so we'll relate it to the main RTM bundle above.
<Bundle Name="PatchingBundle 1.0.1.0 - SP1" Version="1.1.0"
    Manufacturer="Jakob Devs Inc." UpgradeCode="[patch_bundle_code_v1.0.1.0]"
    ParentName="BaselineBootstrapper">
    <RelatedBundle Id="[main_bundle_code]" Action="Patch" />
</Bundle>

Then I would author the fix pack for this service pack as this, but I relate it to the service pack patch. Of course this fix pack should have the diff from the SP1 baseline to the patch. It doesn't have to use the RTM as the baseline anymore. It'll get uninstalled when the SP is uninstalled:
<project name="integrator" basedir=".">
 <property name="baseDir" value="${project::get-base-directory()}" />
 <target name="build">
  <call target="cleanBuildfiles" />
  <call target="buildSoftware" />
  <call target="buildInstaller" />
  <call target="publishSoftware" />
 </target>
 <target name="buildSoftware">
  <nant 
   buildfile="${baseDir}\myFramework\default.build" 
   target="buildAll"
   inheritall="false"/>
 </target>
 <target name="buildInstaller">
  <nant 
   buildfile="${baseDir}\installer\default.build"
   target="buildInstaller"
   inheritall="false" />
 </target>
</project>
Here it also makes sense to use the <bal:Condition> element so that the Sp1Fp1 only installs if the service pack for the main RTM bundle is installed.

Dienstag, 18. Juni 2013

Conditioning a wix bundle when it should or should not run

I started to have this question when I prepared a patch bundle which should only install when the main product is already installed. Additional complexity is given when a service pack was applied and patches require the service pack to be installed. In an additional post I explain how to author patch bundles and how to remove fix pack bundles on top of SPs along with the service pack bundle.

Wix bundles have two points where you can configure whether they should execute or not.

The first which you'll find is the bundle/@Condition attribute:
<Bundle
    Name="TestBundle" Version="1.0.0.0"
    Manufacturer="TestDeploy Inc." UpgradeCode=""
    Condition="((VersionNT = v6.0) AND (ServicePackLevel &gt;= 2)) OR (VersionNT &gt;= v6.1)"
>
<!-- bundle stuff -->
</Bundle>
Here the condition checks that at least NT in version 6.0 (Windows Server 2008) is installed with at least ServicePack 2, or that the windows versions bigger than 6.1 (Windows 7). Microsoft provides a list of the windows versions.

This can only be used with prebuilt wix burn variables. A list of those can be found herehttp://wix.sourceforge.net/manual-wix3/bundle_built_in_variables.htm.

The second method requires the WixBalExtension's Condition element:
<bal:Condition
   Message="The Bootstrapper has to be installed in version $(var.BaselineVersion)">  
      WixBundleInstalled OR      
      ((SampleMsiInstalledState = 5) AND (SampleMsiInstalledVersion &gt;= v$(var.BaselineVersion)))
</bal:Condition>
<util:ProductSearch Guid="[msi_prerequisite_package_product_code]"
    Result="version" Variable="SampleMsiInstalledVersion" />
<util:ProductSearch Guid="[msi_prerequisite_package_product_code]"
    Result="state" Variable="SampleMsiInstalledState" />
Here we use a ProductSearch from the WixUtilExtension to find the state and versions of related msi packages. The version is then compared to the minimum version of a bundle that's required for the bundle (BasellineVersion).
I haven't found a way to search for installed bundles, but it is apparently possible to do a registry search for the bundle UpgradeCode. However, that's wix implementation details and should be used with care.

What i found important is: Use some kind of fallback condition, like the WixBundleInstalled (this variable is 1 if installed, 0 else). Without that, the SampleMsiInstalledState could be false because someone forced the bundle to uninstall, then the conditions would evaluate to false and the bundle won't run anymore. No user likes bundle corpses on the system.

Donnerstag, 11. April 2013

Setting up RaspberryPi with ArchLinux to automatically connect to WLAN

Got a RaspberryPi.
After simply dd'ing the ArchLinux onto an SD card, booting was possible, and composite output was working. Neat.
Plug in a wlan usb stick. Try to configure it like it was described here, but things just didn't work out fine. Problem was, the wlan0 device wasn't yet existing, when the boot process reached the starting of the wlan connection. Fail followed.

What kind of saved me, after I understood what to do, was this thread.
However, what I did was slightly different:
I called
systemctl --full
and search for the line providing something like this:
sys-devices-pci0000:00-0000:00:1c.1-0000:02:00.0-bcma0:0-net-wlan0.device
Then i put that into the file to After and BindTo
[edit]
Had to change my approach. Before, I changed the file /etc/systemd/system/network.service, but that kind of didn't work nicely. Probably, because network.service is not netcfg. The change in netcfg file below just adds two lines which tells Arch to wait with this netcfg service until the wlan is up and running:
After=sys-subsystem-net-devices-wlan0.device
BindsTo=sys-subsystem-net-devices-wlan0.device
so that we get the resulting file:
cat /etc/systemd/system/multi-user.target.wants/netcfg\@Stadtkater.service 
[Unit]
Description=Netcfg networking service for profile %i
Before=network.target
Wants=network.target
After=sys-subsystem-net-devices-wlan0.device
BindsTo=sys-subsystem-net-devices-wlan0.device

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/netcfg check-iface %i
ExecStop=-/usr/bin/netcfg down %i
KillMode=none

[Install]
WantedBy=multi-user.target
Not sure what I did there exactly and what's the difference between After and BindTo, but it worked and the raspberry pi connects now to the wlan after a fresh start. So now i can ssh and don't have to use a crappy TV signal anymore :)

Mittwoch, 20. März 2013

BURN #04: passing preprocessor variables into the build

A nice solution is explained here on stackoverflow:

it basically says that you should:

1st in the wixproj file add the following:
<Target Name="BeforeBuild">
    <CreateProperty Condition="$(BuildNumber) != ''"
Value="BuildNumber=$(BuildNumber);$(DefineConstants)">
      <Output TaskParameter="Value" PropertyName="DefineConstants" />
    </CreateProperty>
    <CreateProperty Condition="$(RevisionNumber) != ''"
Value="RevisionNumber =$(RevisionNumber);$(DefineConstants)">
      <Output TaskParameter="Value" PropertyName="DefineConstants" />
    </CreateProperty>
  </Target>
2nd in your msbuild task do this:
<MSBuild Projects="YourWixProject.wixproj" 
   Properties="BuildNumber=$(VerBuildNumber);RevisionNumber=$(RevisionNumber)" 
/>

Donnerstag, 14. März 2013

Writing custom NANT and msbuild tasks

Just a friendly reminder to reuse work of others.

See here for msbuild:
Nant help can be found here:
Or, since i only wanted to learn how to write a task which deletes directories which are older than XX:
Look at slashdot to delete all directories which are more than 7 days old

Sonntag, 24. Februar 2013

BURN #03: Applying patches in the bootstrapper

Slipstreaming msp packages (like tweaking the RTM installer to install patches automatically)

Technically, slipstreaming is installing the patch-msp with the msi in a single transaction:
msiexec /i D:\product.msi PATCH=D:\patch.msp

Andreas Kerl's .NET-dev article explained how to slipstream patches into an installer:
<PackageGroup Id="Product">
  <MsiPackage Id="Product" Name="packages\product.msi">
    <SlipstreamMsp Id="Patch"/>
  </MsiPackage>
  <MspPackage Name="packages\patch.msp"/>
</PackageGroup>

Well, that does not seem to be necessary, much simpler and also working due to the MspPackage/@Slipstream attribute being set to 'yes' always, this works too:
<PackageGroup Id="Product">
  <MsiPackage Id="Product" Name="packages\product.msi"/>
  <MspPackage Id="Patch" Name="packages\patch.msp"/>
</PackageGroup>

See Stewart Heath's article.

Freitag, 22. Februar 2013

Starting to LOG and TRACE my programs


BURN #02: How to sign the msi packages and the Bootstrapper

Some examples on conditions, how to change the installer GUI, and signing the packages.

http://neilsleightholm.blogspot.de/2012/05/wix-burn-tipstricks.html

About signing:
I created several .wixproj files for msbuild compilation. But to get signing to work, i had to do the following (this is probably just one way to do it):

Wix projects by default call a wix.targets task, which has many msbuild tasks for building the msi/merge modules, whatever with the installed wix version. It also holds an abstract task which you can redefine/redirect to sign you stuff.

To sign msi and cab packages:
<Target Name="SignCabs">
  <Exec Command="$(signToolCall) &quot;%(SignCabs.FullPath)&quot;" />
 </Target>
 
 <Target Name="SignMsi">
  <Exec Command="$(signToolCall) &quot;%(SignMsi.FullPath)&quot;" />
 </Target>

To sign BURN bootstrapper:
<Target Name="SignBundleEngine">
  <Exec Command="$(signToolCall) &quot;@(SignBundleEngine)&quot;" />
 </Target>
 
 <Target Name="SignBundle" >
  <Exec Command="$(signToolCall) &quot;@(SignBundle)&quot;" />
 </Target>

And most important: each .wixproj file must have a property called (it does not matter in which property group you push that):
<PropertyGroup>
  <!-- this makes wix sign everything it can -->
  <SignOutput>true</SignOutput>
 </PropertyGroup>

To streamline everything, just put this one line into your .wixproj file:
    <Import Project="$(WixTargetsPath)" />
 <!-- the WixTargetsPath line already exists. add your default targets file to your .wixproj targets -->
    <Import Project="..\Default.targets" />

And to round everything up, here's my complete Default.targets file with methods to find the ProgramFiles (x86) directory and the windows installer SDK directory:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <PropertyGroup>
  <!--MSBuild 4.0 property-->
  <ProgramFiles32>
  $(MSBuildProgramFiles32)
  </ProgramFiles32> 
  <!--Use OS env var as a fallback:- 32 bit MSBuild 2.0/3.5 on x64 will use this-->
  <ProgramFiles32 Condition=" '' == '$(ProgramFiles32)'">
  $(ProgramFiles%28x86%29)
  </ProgramFiles32>

  <!-- Handle MSBuild 2.0/3.5 running in 64 bit mode - neither of the above env vars are available. http://stackoverflow.com/questions/336633
       NB this trick (Adding a literal " (x86)" to the 64 bit Program Files path) may or may not work on all versions/locales of Windows -->
  <ProgramFiles32 Condition ="'$(ProgramFiles32)'=='' AND 'AMD64' == '$(PROCESSOR_ARCHITECTURE)'">
  $(ProgramFiles) (x86)
  </ProgramFiles32>

  <!--Catch-all - handles .NET 2.0/3.5 non-AMD64 and .NET 2.0 on x86 -->
  <ProgramFiles32 Condition=" '' == '$(ProgramFiles32)' ">
  $(ProgramFiles)
  </ProgramFiles32>

  <!-- some important directories -->
  <ProductsDir Condition=" '$(ProductsDir)' == '' ">
  $(MSBuildThisFileDirectory)..\Products\
  </ProductsDir>
  <msiDir>
  "$(ProgramFiles32)\Microsoft SDKs\Windows\v7.0A\bin\"
  </msiDir>
  
  <!-- signtool configuration -->
  <signTool>
  $(msiDir)signtool.exe
  </signTool>
  <timeStampServer>
  http://timestamp.verisign.com/scripts/timestamp.dll
  </timeStampServer>
  <signKey>
  "$(ProductsDir)your_key_file.pfx"
  </signKey>
  <uniformResourceLocator>
  www.your_web_adress.com
  </uniformResourceLocator>
  <signToolCall>
  $(signtool) sign  /f $(signKey) /p smokey11 /du $(uniformResourceLocator) /t $(timeStampServer)
  </signToolCall>
 </PropertyGroup>

 <PropertyGroup>
  <!-- this makes wix sign everything it can -->
  <SignOutput>true</SignOutput>
 </PropertyGroup>
 
 <Target Name="SignCabs">
  <Exec Command="$(signToolCall) &quot;%(SignCabs.FullPath)&quot;" />
 </Target>
 
 <Target Name="SignMsi">
  <Exec Command="$(signToolCall) &quot;%(SignMsi.FullPath)&quot;" />
 </Target>
 
 <Target Name="SignBundleEngine">
  <Exec Command="$(signToolCall) &quot;@(SignBundleEngine)&quot;" />
 </Target>
 
 <Target Name="SignBundle" >
  <Exec Command="$(signToolCall) &quot;@(SignBundle)&quot;" />
 </Target>
</Project>

Dienstag, 19. Februar 2013

BURN #01: Get the BootstrapperApplicationData.xml

This one is not tricky at all. You basically want to get this data if your installer is running, to get the dependencies of the .msi packages right.
Now, there's no example from wix.sourcefourge.com, nor from anywhere else I searched.

This code in your BootstrapperApplication UX (user experience) gets you the file.
    string fileName = "BootstrapperApplicationData.xml"; 
    string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName); 
    using (FileStream stream = new FileStream(path, FileMode.Open)) 
    { 
        ... 
    }

If you want to have this file without running your installer: don't go starting it and searching for the file. That'd suck. No, just go to cmd, and run:
%WiX%\bin\dark.exe <your_file> -x <extract_to_this_dir>

So, how to get custom data in there?
It's a bit fuzzy at the moment, but Rob Mensching said:
You just add rows to a table that has BootstrapperApplicationData="yes". The Binder will translate all those rows into BootstrapperApplicationData.xml.
-----------------------
First, the CustomTable definition (just Column elements) can be put in a separate Fragment. Then, when you populate a CustomTable (add Row elements) that CustomTable will reference the definition.That means you need to put the CustomTable/Row in a fragment that is referenced. 
Often, the CustomTable/Row data is so verbose, there is a tendency to put it in a separate Fragment. That is a completely reasonable but now it's floating in an island that needs a "hackish" reference. Empty PayloadGroup for Bundles is very good, BTW.
So what's the ideal?  The ideal is to create an Extension. The Extension would then extend the compiler to provide a "pretty face" on your CustomTable and be far more powerful than the raw Row elements. 
We cheated for a long time with the wixstdba by using WixVariables before finally creating the "pretty face". Looking back, we should have done it earlier. <smile/> 

Donnerstag, 14. Februar 2013

What to do if dependency injection complains: especially Unity!!

Well, Unity simply sucks up to a certain version. It fails to get the assembly and complains with: Assembly can't be found. -- yeah, but which assembly, asshole???
Slashdot said something about that here.
That statement below catches such events and lets you know something. If it helps?
AppDomain.CurrentDomain.AssemblyResolve +=
          new ResolveEventHandler(CurrentDomain_AssemblyResolve);

How to add syntax highlighting to blog posts

This should be the first post.. but here we go as second :)
How to add syntax highlighting to a blog per javascript (from alexgorbatchev)

Currently I use prettyprint (Prettify) from a google dev:
http://code.google.com/p/google-code-prettify/
To use it, simply put this in your &lt;head&gt; tag:
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&skin=sunburst&lang=css" defer="defer"></script>
Stackoverlflow on code formatting
Escape the html characters

Shamelessly copied from: oneqonea.blogspot.com
<!-- Syntax Highlighter Additions START -->
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeEmacs.css" rel="stylesheet" type="text/css" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript" />

<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushColdFusion.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushErlang.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js" type="text/javascript" />
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript" />
 
<script language="javascript" type="text/javascript">
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.all();
</script>
<!-- Syntax Highlighter Additions END -->

Mittwoch, 13. Februar 2013

How to redirect assembly versions in .NET


.NET Assembly versions can be redirected in application, publisher policy, or machine configuration files.
The assemblies need to be signed == have a strong name. If they are not signed, the version is not taken into account by calling assemblies.
Slashdot had it's take on that here.

This example shows how to redirect in the app.config file
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <publisherPolicy apply="no" />
      <dependentAssembly>
        <!-- i stumbled over this one: i started using culture="en-us", that failed. -->
        <assemblyIdentity name="MyDependant.Assembly.ToRedirect"
          publicKeyToken="cf95ca7471e897ff"
          culture="Neutral" />
        <!--  -->
        <bindingRedirect oldVersion="1.0.0.0-1.0.0.163" newVersion="1.0.0.163" />
        <publisherPolicy apply="no" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>