title: Better way to get the base directory?
body: <p>I have this code to load a config file and read all the values and it works fine when running the application but of course fails on team city because the appdomain's base directory is where the build script (psake) is started. I know I can change directory to the build dir before executing the tests but I thought it's better to make loading the config file work at all times regardless.</p>
  
  <pre><code>XDocument.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, cfgFile));
  </code></pre>
  
  <p>Is there another way to get the "BaseDirectory" that really works all times? I tried the below as well with same results:</p>
  
  <pre><code>string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
  XDocument.Load(Path.Combine(path, cfgFile));
  </code></pre>
  
  <p><strong>EDIT 1</strong> The problem is the following. My solutions base directory is "C:\Project", all compiled files are copied to "C:\Project\build". Now in the psake build script I have the following code:</p>
  
  <pre><code>task Test -depends PrepareTests {
      try { 
          #$old = pwd
          #cd $build_dir
          &amp;$mspec $mspec_projects --teamcity
          #cd $old
      }
      catch {
          &amp;echo "Error starting test runner"
          Exit 1;
      }      
  }
  </code></pre>
  
  <p>As you can see I commented out the changing of directories which makes the BaseDirectory the location of the build file / solution instead of the build directory regardless of how I try to access it. Kind of confusing if you ask me.</p>
  
  <p><strong>UPDATE</strong> I really like to know if it is possible to get the directory of the assembly regardless of what directory the application that started the app domain is located. How?</p>