title: How to add reference to Outlook VSTO in a dynamic CSharpCodeProvider script
body: <p>I am trying to use an xml file to determine which outlook properties be should be included in a workflow executed via VSTO addin code. </p>
  
  <p>Example </p>
  
  <p>The xml might state that the <code>Subject</code> of the current <code>Outlook.MailItem</code> is required by the workflow. I haven't been able to use reflection to get the <code>Subject</code> property using its string name "Subject" because the <code>MailItem</code> is an interface and not a class.</p>
  
  <p>I thought the solution might be to create and compile dynamic C# code that returns the required property by name... </p>
  
  <p><strong>Problem</strong>: I have been unable to work out how to find the location of the running  Microsoft.Office.Interop.Outlook.dll so that I can add it as a reference to the dynamic compiler. I have tried a number of combinations, the last effort is shown below.</p>
  
  <pre><code>CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
  CompilerParameters parameters = new CompilerParameters();
  parameters.GenerateExecutable = false;
  parameters.GenerateInMemory = true;
  parameters.IncludeDebugInformation = false;
  parameters.ReferencedAssemblies.Add(Assembly.GetAssembly(typeof(Outlook.MailItem)).Location);
  </code></pre>