title: Wix Custom Action Implementation for Writing Installfolder in text
body: <p>I have following Wix Code that is supposed to send the value of property to Custom Action Written in C#. Basically what I want is when the MSI is installed, I want to write the path of Folder where Wix installed the program in text file. I referred to <a href="http://blogs.msdn.com/b/jschaffe/archive/2012/10/23/creating-wix-custom-actions-in-c-and-passing-parameters.aspx" rel="nofollow">this</a> site and created code accordingly, but my Custom Action isn't working.</p>
  
  <p>Following is my Wix File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
      &lt;Product Id="*" Name="SetupInstallFolder" Language="1033" Version="1.0.0.0" Manufacturer="LP" UpgradeCode="9e10a7d8-4ffb-493c-8318-c44ba4bc0c4c"&gt;
          &lt;Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" /&gt;
  
          &lt;MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /&gt;
          &lt;MediaTemplate /&gt;
  
          &lt;Feature Id="ProductFeature" Title="SetupInstallFolder" Level="1"&gt;
              &lt;ComponentGroupRef Id="ProductComponents" /&gt;
          &lt;/Feature&gt;
      &lt;/Product&gt;
  
      &lt;Fragment&gt;
          &lt;Directory Id="TARGETDIR" Name="SourceDir"&gt;
              &lt;Directory Id="ProgramFilesFolder"&gt;
                  &lt;Directory Id="INSTALLFOLDER" Name="SetupInstallFolder" /&gt;
              &lt;/Directory&gt;
          &lt;/Directory&gt;
      &lt;/Fragment&gt;
  
      &lt;Fragment&gt;
          &lt;ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"&gt;
        &lt;Component Id="SomeRandomEXE"&gt;
          &lt;File Source ="G:\SarVaGYa\myworkspace\LatestLpa\lpa\lpa_c\here\src\lpa\Release\lpa.exe" /&gt;
        &lt;/Component&gt;      
          &lt;/ComponentGroup&gt;
      &lt;Binary Id="SetupCA2"  src="G:\visual studio stuffs\SetupCAInstallFolder\SetupCAInstallFolder\bin\Release\SetupCAInstallFolder.CA.dll"/&gt;
      &lt;CustomAction Id="INSTALLFOLDERFINDER" Execute="immediate" Property="INSTALLEDPATH" Value="[INSTALLFOLDER]" /&gt;
      &lt;InstallExecuteSequence&gt;
        &lt;Custom Action="INSTALLFOLDERFINDER" Sequence="2"&gt;&lt;/Custom&gt;
  
      &lt;/InstallExecuteSequence&gt;
      &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>I have also given my C# code that is supposed to get the value and write it in file:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Microsoft.Deployment.WindowsInstaller;
  
  namespace SetupCAInstallFolder
  {
      public class CustomActions
      {
          [CustomAction]
          public static ActionResult InstallFolderFinder(Session session)
          {
              session.Log("Here is the SetupCAInstallFolder");
              string path = session["INSTALLEDPATH"];
              session.Log("Installed Path is " + path);
              System.IO.File.WriteAllText("F:\\pathgenerated.txt", path);
              //System.IO.File.WriteAllText(path + "installed.txt", "sdkasdkasdlkasdk");
  
              return ActionResult.Success;
          }
      }
  }
  </code></pre>
  
  <p>The Wix file compiles and gives MSI that doesn't get the value of <strong>INSTALLEDPATH</strong> . If I add <strong>DllEntry="InstallFolderFinder"</strong> in CustomAction tag, it fails with error  <strong>The CustomAction/@DllEntry attribute cannot coexist with a previously specified attribute on this element.  The CustomAction element may only have one of the following target attributes specified at a time: DllEntry, Error, ExeCommand, JScriptCall, Script, Value, or VBScriptCall</strong></p>
  
  <p>How do I pass the value of INSTALLEDPATH to C# Custom Action?</p>