title: Automatically retrieve EXE file version to embed in NSIS installer metadata
body: <p>I am attempting to remove one more step in my application's release process by automatically retrieving versioning info from my executable (in this case, a .NET application).</p>
  
  <p>Up to this point, I have been able to get by with a limited knowledge of NSIS, but I am quickly learning that this is not enough.</p>
  
  <p><strong>Step 1: Declare version info in executable</strong></p>
  
  <p>In AssemblyInfo.cs, I declare <code>[assembly: AssemblyVersion("1.0.0.1")]</code>. This successfully makes the version info appear in the compiled executable (under "File version" and "Product version").</p>
  
  <p><strong>Step 2: Retrieve version info from executable</strong></p>
  
  <p>According to this <a href="http://nsis.sourceforge.net/GetFileVersion" rel="noreferrer">article on "GetFileVersion"</a>, importing "FileFunc.nsh" allows you to retrieve version info from an executable.</p>
  
  <p>Code used:</p>
  
  <pre><code>Section
      Var /GLOBAL version
      ${GetFileVersion} "C:\test.exe" $version
      ...
  SectionEnd
  </code></pre>
  
  <p><strong>Step 3: Verify contents of function call</strong></p>
  
  <p>Based on <a href="http://nsis.sourceforge.net/Docs/Chapter5.html#5.1.7" rel="noreferrer">section 5.1.7 of the documentation</a>, I should be able to print to the command line during compile time using the "!echo" command. The difference between printing the contents of a variable (or a constant, etc) still confuses me, so I have tried all four of these options:</p>
  
  <pre><code>!echo $version
  !echo "$version"
  !echo "${version}"
  !echo ${version}
  </code></pre>
  
  <p>This results in:</p>
  
  <pre><code>$version (InstallScript.nsi:15)
  $version (InstallScript.nsi:16)
  ${version} (InstallScript.nsi:17)
  ${version} (InstallScript.nsi:18)
  </code></pre>
  
  <p><strong>Step 4: Declare the installer metadata</strong></p>
  
  <p>Based on <a href="http://nsis.sourceforge.net/Docs/Chapter4.html#4.8.3" rel="noreferrer">section 4.8.3</a>, I should be able to add installer metadata via <code>VIProductVersion</code> and <code>VIAddVersionKey</code>.</p>
  
  <pre><code>VIProductVersion $version 
  VIAddVersionKey "FileVersion" "$version"
  </code></pre>
  
  <p>In the built installer, this adds the string "$version" into the specified fields.</p>
  
  <hr>
  
  <p>Is there a <code>ToString()</code> equivalent in NSIS? How can I access a variable's contents? Does the print of the variable name mean that it has no contents? How can I verify that <code>GetFileVersion</code> is called correctly, executes correctly, and returns a value?</p>