0

I've created a custom task to get me a three-part version number of my assembly that was built in MSBuild.

I've created a custom <Target Name="GetVersion"> for this, and it works nicely - the three-part version number(1.5.2) is stored into a ThreePartBuildNumber property in MSBuild.

But how do I tell MSBuild inside Visual Studio 2010 to call this target once it's compiled my assembly, and before creating my WiX Setup project (where I'd like to set the WiX install script's Product/@Version to this three-part version number automatically)?

How can I "plug" this new target into the usual VS 2010 build process?

Update:

OK, I've managed to get this into the *.wixproj file which is also a MSBuild file, really. In the <Target Name="BeforeBuild">, I can successfully determine the three-part version number, and it's stored inside a MSBuild property called ThreePartVersionNumber.

But how on earth can I now access this properly filled MSBuild property in my WiX setup? I tried setting <Product Version="$(var.ThreePartVersionNumber) ...>, but that doesn't work - it doesn't seem to find the variable.... neither works with the sys. or env. prefixes, either....

So how do I make this MSBuild property that has the information I need "visible" to the WiX installer script/XML ?!?!?!? I can't seem to see the forest for all those angle brackets .....

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

Use the /verbosity:d switch to get a full view of all the targets that were performed and their rough reason for being called (dependent-on). Identify the exact thing you want to be before or after or dependent upon. Besides using the depends attributes on your Target, there are also various properties that are used to collect dependencies for various purposes. You can identify these by using /preprocess and then looking up the Targets that catch your eye from the previous step.

I've found that specific answers often don't work, as the build situation is different for my language or the exact inclusion order matters or other minor things; so this is how I've found the real triggers in my case.

JDługosz
  • 5,592
  • 3
  • 24
  • 45
0

What I've done in the end:

inside my WiX setup project, in the myproject.wixproj MSBuild file, I've added a new custom task like this:

<UsingTask TaskName="GetThreePartVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
        <AssemblyPath ParameterType="System.String" Required="true" />
        <ThreePartVersion ParameterType="System.String" Output="true" />
    </ParameterGroup>
    <Task>
        <Using Namespace="System.Diagnostics" />
        <Code Type="Fragment" Language="cs">
           <![CDATA[
             Log.LogMessage("Getting version details of assembly at: " + this.AssemblyPath, MessageImportance.High);
             Version v = Version.Parse(FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion);
             this.ThreePartVersion = v.ToString(3);
           ]]>
        </Code>
    </Task>
</UsingTask>

and then in the BeforeBuild target, I added these lines to call this task and define a WiX constant with the results:

<Target Name="BeforeBuild">
    <GetThreePartVersion AssemblyPath="$(SolutionDir)Plugin\$(OutputPath)Swisscom.Vidia.Plugin.dll">
        <Output TaskParameter="ThreePartVersion" PropertyName="ThreePartVersionNumber" />
    </GetThreePartVersion>
    <PropertyGroup>
        <DefineConstants>ThreePartBuildVersion=$(ThreePartVersionNumber)</DefineConstants>
    </PropertyGroup>
    <Message Text="Three-part version: $(ThreePartVersionNumber)" />
</Target>

and now in my WiX project.wxs file, I can reference that constant that's been defined, and use it for the <Product Version="..." ... /> attribute:

<Product Id="*" Name="MyProject" Language="1033" 
         Version="$(var.ThreePartBuildVersion)" ......>

It took a bit of twiddling and a lot of trial & mostly error until I finally got it right - but this is the way it works for me now. Hope this might help some other soul some day....

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459