Automatic Versioning

Jan 31, 2015 at 4:25 AM
First I include a shared Link .cs file and tried to get version number with
    var ava = (System.Reflection.AssemblyVersionAttribute)Attribute.GetCustomAttribute(typeof(Script).Assembly, typeof(System.Reflection.AssemblyVersionAttribute));
    var v = ava != null ? ava.Version : "Current";
This didn't seem to work
then I tried that
    var ass = System.Reflection.Assembly.LoadFile(src_dir + @"\RPGStoryboards.exe");
    var ava = (System.Reflection.AssemblyVersionAttribute)Attribute.GetCustomAttribute(ass, typeof(System.Reflection.AssemblyVersionAttribute));
    var v = ava != null ? ava.Version : "Current";

program exited with code 255! :'(
any tip on how to get the version from the attribute of the files to install?


As a side node I tried to upgrade the wixsharp package in my installer.
"update-package wixsharp" didn't work smoothly because
  1. Setup already exist! (had to rename my setup class)
  2. allegedly can't add a reference to Microsoft.CSharp, I then made my installer a .NET4.5 assembly, but it didn't add it anyway, though it succeeded! :-o
Feb 1, 2015 at 2:42 AM
Edited Feb 1, 2015 at 7:31 AM
> ...any tip on how to get the version from the attribute of the files to install?
The more reliable way of extracting the file version is as follows:
static public Version GetFileVersion(string file)
{
    var info = FileVersionInfo.GetVersionInfo(file);
    //cannot use info.FileVersion as it can include description string
    return new Version(info.FileMajorPart,
                       info.FileMinorPart, 
                       info.FileBuildPart, 
                       info.FilePrivatePart);
}
It will work with both assemblies and native binaries.

>program exited with code 255!
Your build script will internally handle all errors associated with Wix# however any runtime error in the build script itself will fail the post-build action and will print a generic error '255' error message.

If there is a chance that you can have non Wix# specific runtime error then you need to change your main signature to return an int and use exception handling:
class Script
{
    static public int Main(string[] args)
    {
        try
        {
            //Wix# build steps
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            return 1;
        }
        return 0;
    }
}
>"update-package wixsharp" didn't work smoothly
I am not sure how NuGet gets around updates of the source code. Will see what I can do.
Feb 1, 2015 at 2:57 AM
Works a treat, thanks! :)
Feb 1, 2015 at 7:47 AM
The NuGet problem seems odd. When I tried it everything worked as expected:

Brand new consoleApp VS2013 project. Target v4.5.
PM> install-package -version 1.0.5.0 wixsharp
'WixSharp 1.0.5.0' already installed.
Adding 'WixSharp 1.0.5.0' to ConsoleApplication24.
Successfully added 'WixSharp 1.0.5.0' to ConsoleApplication24.

PM> update-package wixsharp
Updating 'WixSharp' from version '1.0.5.0' to '1.0.7.0' in project 'ConsoleApplication24'.
Removing 'WixSharp 1.0.5.0' from ConsoleApplication24.
Successfully removed 'WixSharp 1.0.5.0' from ConsoleApplication24.
Adding 'WixSharp 1.0.7.0' to ConsoleApplication24.
Successfully added 'WixSharp 1.0.7.0' to ConsoleApplication24.
Uninstalling 'WixSharp 1.0.5.0'.
Successfully uninstalled 'WixSharp 1.0.5.0'.
Feb 1, 2015 at 10:56 AM
mm.. indeed.. perhaps my unexplained mistake..
I just did the test again, where I modified the setup.cs and said no to overwrite when updating the package. It still updated successfully!
Sorry, never mind!
Thanks for testing! :)