title: Guaranteed way to find the filepath of the ildasm.exe and ilasm.exe files regardless of .NET version/environment?
body: <p>Is there a way to programmatically get the FileInfo/Path of the ildasm.exe/ilasm.exe executables? I'm attempting to decompile and recompile a dll/exe file appropriately after making some alterations to it (I'm guessing PostSharp does something similar to alter the IL after the compilation).</p>
  
  <p>I found a blog post that pointed to:</p>
  
  <pre><code>var pfDir = Environment.GetFolderPath(Environment.SpecialFolders.ProgramFiles));
  var sdkDir = Path.Combine(pfDir, @"Microsoft SDKs\Windows\v6.0A\bin");
  
  ...
  </code></pre>
  
  <p>However, when I ran this code the directory did not exist (mainly because my SDK version is 7.1), so on my local machine the correct path is <code>@"Microsoft SDKs\Windows\v7.1\bin"</code>. How do I ensure I can actually find the ildasm.exe?</p>
  
  <p>Similarly, I found another blog post on how to get access to ilasm.exe as:</p>
  
  <pre><code>string windows = Environment.GetFolderPath(Environment.SpecialFolder.System);
  string fwork = Path.Combine(windows, @"..\Microsoft.NET\Framework\v2.0.50727");
  
  ...
  </code></pre>
  
  <p>While this works, I noticed that I have Framework and Framework64, and within Framework itself I have all of the versions up to v4.0.30319 (same with Framework64). So, how do I know which one to use? Should it be based on the .NET Framework version I'm targetting?</p>
  
  <p>Summary:</p>
  
  <ul>
  <li>How do I appropriately guarantee to find the correct path to ildasm.exe?</li>
  <li>How do I appropriately select the correct ilasm.exe to compile?</li>
  </ul>