AndreyS
AndreyS

Reputation: 385

How can I get File Version of basic msi installation package (setup.exe) in MSBuild

I have setup.exe. This is a Basic MSI Installation package. I use InstallShield to create it. How can I get its FileVersion in MSBuild script? I cannot use GetAssemblyIdentity task

    <GetAssemblyIdentity AssemblyFiles="setup.exe">
        <Output
            TaskParameter="Assemblies"
            ItemName="MyAssemblyIdentities"/>
    </GetAssemblyIdentity>

because my setup.exe is not an assembly and doesn't contain an assembly manifest, so an error appears if invoke this task:

Could not load file or assembly 'setup.exe' or one of its dependencies. The module was expected to contain an assembly manifest.

Upvotes: 2

Views: 828

Answers (1)

stijn
stijn

Reputation: 35921

The FileVersionInfo class provides this functionality, and inline code allows using it from MSBuild directly:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >

  <UsingTask TaskName="GetVersion" TaskFactory="CodeTaskFactory"
             AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
    <ParameterGroup>
      <TheFile Required="true" ParameterType="System.String"/>
      <TheVersion ParameterType="System.String" Output="true" />
    </ParameterGroup>
    <Task>
      <Code Type="Fragment" Language="cs">
        <![CDATA[
          TheVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo( TheFile ).FileVersion;
         ]]>
      </Code>
    </Task>
  </UsingTask>

  <Target Name="DoGetVersion">
    <GetVersion TheFile="$(MyAssemblyIdentities)">
      <Output PropertyName="FetchedVersion" TaskParameter="TheVersion" />  
    </GetVersion>
    <Message Text="Version = $(FetchedVersion)" />
  </Target>

</Project>

Upvotes: 3

Related Questions