c# - 创建自定义 MSBuild 任务时如何从 C# 代码获取当前项目目录?

标签 c# msbuild

我不想运行带有硬编码路径的外部程序,而是想获取当前的项目目录。我正在使用自定义任务中的流程调用外部程序。

我该怎么做? 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/

相关文章:

c# - Autofixture.Automoq - 泛型使 bool 始终为真

svn - 如何加快我们的 TeamCity 构建速度?

msbuild - AfterTarget 未在 AfterBuild 中触发

c# - MSBuild web.config 转换不工作

c# - C# 数据行的问题

c# - 客户端 - 服务器 WebSocket 握手

msbuild - 出现编译错误时立即停止MSBuild处理

MSBuild 和 IgnoreStandardErrorWarningFormat

c# - linq 中等效的 SQL 限制

c# - 如何在 C# 中为插件函数指定默认值