gpt4 book ai didi

c# - 在 C# 中指定路径时如何返回一个级别?

转载 作者:太空狗 更新时间:2023-10-30 00:42:45 27 4
gpt4 key购买 nike

我想以编程方式在 Visual Studio 的“扩展”文件夹中安装一个文件夹。我能得到的最接近的是使用 VS100COMNTOOLS 环境变量。我想要做的是从“工具”文件夹返回一级,进入 IDE/Extensions,比如 VS100COMNTOOLS..\IDE\Extensions。这是我的代码:

namespace TemplatesCustomAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{

var vspath = Environment.GetEnvironmentVariable("VS100COMNTOOLS");

session["VSINSTALLATIONFOLDER"] = string.Format(@"{0}\..\IDE\Extensions", vspath);



return ActionResult.Success;
}
}
}

最佳答案

使用Path.GetFullPath :

var pathWithParent = string.Format(@"{0}\..\IDE\Extensions", vspath);
session["VSINSTALLATIONFOLDER"] = Path.GetFullPath(pathWithParent);

尽管我也更愿意使用 Path.Combine:

var pathWithParent = Path.Combine(vspath, @"\..\IDE\Extensions");

关于c# - 在 C# 中指定路径时如何返回一个级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13843794/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com