Search code examples
c#msbuild

How do you get the current project directory from C# code when creating a custom MSBuild task?


Instead of running an external program with its path hardcoded, I would like to get the current Project Dir. I'm calling an external program using a process in the custom task.

How would I do that? AppDomain.CurrentDomain.BaseDirectory just gives me the location of VS 2008.


Solution

  • You can try one of this two methods.

    string startupPath = System.IO.Directory.GetCurrentDirectory();
    
    string startupPath = Environment.CurrentDirectory;
    

    Tell me, which one seems to you better