Search code examples
c#directoryncrunch

Getting directory based the location of file C#


I'm trying to write a relative path from a file but the only relative paths I can get are from the running app file.

This is causing problems as NCrunch runs its test from a different directory so its failing all my tests because it cant find the files which are relative to my code file.

It's important that this be a relative path as there are several people working on this project so absolute paths don't work.

Is there any way to make the path relative to the .cs file where the code is written?

until now I've been using

 private static readonly string MyDocumentsRoot =      Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        public static readonly string ApplicationRoot = MyDocumentsRoot + @"\Visual Studio 2012\Projects\";

but really need it to be a little more relative


Solution

  • The solution is well documented in NCRUNCH documentation:

    Implicit File Dependencies

    The other solutions, sooner or later, will fail. (I had similar trouble with MSTest, which offers a similar solution).