我不想运行带有硬编码路径的外部程序,而是想获取当前的项目目录。我正在使用自定义任务中的流程调用外部程序。
我该怎么做? AppDomain.CurrentDomain.BaseDirectory 只是给我 VS 2008 的位置。
最佳答案
using System;
using System.IO;
// This will get the current WORKING directory (i.e. \bin\Debug)
string workingDirectory = Environment.CurrentDirectory;
// or: Directory.GetCurrentDirectory() gives the same result
// This will get the current PROJECT bin directory (ie ../bin/)
string projectDirectory = Directory.GetParent(workingDirectory).Parent.FullName;
// This will get the current PROJECT directory
string projectDirectory = Directory.GetParent(workingDirectory).Parent.Parent.FullName;
关于c# - 创建自定义 MSBuild 任务时如何从 C# 代码获取当前项目目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/816566/