How to resolve Current Directory when running Coded UI

automation, c#, coded-ui-tests, dll

Solution

So far the only place I have found the original path to the test dll is in a private variable in the test context. I ended up using reflection to get the value out and make it usable.

    using System.Reflection;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    public static string CodeBase(
        TestContext testContext)
    {
        System.Type t = testContext.GetType();
        FieldInfo field = t.GetField("m_test", BindingFlags.NonPublic | BindingFlags.Instance);
        object fieldValue = field.GetValue(testContext);
        t = fieldValue.GetType();
        PropertyInfo property = fieldValue.GetType().GetProperty("CodeBase");
        return (string)property.GetValue(fieldValue, null);
    }

I used this to get the path to the DLL that is getting run and use that to then run the application that I know is compiled to the same location as the test was at.

If anyone finds a better way of getting this, please let me know as well.

Problem

I am running a CodedUI test that references a DLL and that DLL refrences a sort of "config" file. While running the test the current Directory returns the one where CodedUI puts the test results files I've used ``` AppDomain.CurrentDomain.BaseDirectory ``` and ``` System.Reflection.Assembly.GetExecutingAssembly().CodeBase ``` and ``` System.Reflection.Assembly.GetExecutingAssembly().Location ``` These all give me the same path What I need is to get the path where the DLL resides because that is where the config file will be built. The location where this will be changes if I am debugging or if I am just running the test (obviously) so I can't use that and navigate backwards or anything like that. Are there any other ways to get the location of the DLL you are referencing?? Edit: I am referencing this config file from inside the DLL that i am referencing.

Original source