Target
For integration tests I want to load a custom XML configuration. This XML is located in a folder inside my integration test project.
For further targets I want to use the new DNX projects. I know they are still in preview.
Local tests work fine. The problem is now, that I cannot use relative paths, because of the test system the current directory information is not the project folder of my project. The same issue with AppVeyor.
The build agent is started in another folder and so the relative path information is wrong and fails. No suprise here.
I've tried to solve this with this snippet:
public abstract class IntegrationTestBase
{
public static string CurrentPath()
{
string codeBase = typeof (IntegrationTestBase).Assembly.Location;
UriBuilder uri = new UriBuilder( codeBase );
string path = Uri.UnescapeDataString( uri.Path );
return Path.GetDirectoryName( path );
}
}
Problem
The problem here is: because of the new DNX Runtime this returns not the location of my project and/or assembly, it returns the runtime folder:
C:/Users/ben/.dnx/runtimes/dnx-clr-win-x86.1.0.0-rc1-update1/bin/Microsoft.Dnx.Loader.dll
Same behavior if I ask for CodeBase or Executing/CallingAssembly.
With "old" simple C# projects and MsTest, I get the path as expected.
Environment.CurrentDirectory
does not work on AppVeyor, because process is not started in project folder and then this command returns another path (the path of the started project).
Question
What is the correct way to work with relative paths here?
Environment
- VS 2015 Update 1
- DNX Project templates
- xUnit configuration
- AppVeyor build system