c# - 修改生成的执行程序集路径c#

标签 c# asp.net

我正在以字符串形式获取执行程序集路径,但我不希望整个路径需要使用它的一部分,并且需要从该路径访问另一个文件夹。

假设我需要从文件夹中获取 xml

“E:\Mahi_WorkSpace\TFS\Atrias.WebAutomationTesting\XmlFolder”

我的执行程序集路径在哪里

" E:\Mahi_WorkSpace\TFS \Atrias.WebAutomationTesting\TestResults\t.mahidharreddy_123 2016-10-24 07_39_26\Out"

现在我只需要执行程序集字符串中的“E:\Mahi_WorkSpace\TFS\Atrias.WebAutomationTesting\”

 public string GetStringBody()
    {
         System.CodeDom.Compiler.CompilerParameters parameters = new    CompilerParameters();
         string path=Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
//srting xmlpath=??
         return xmlpath;


    }

最佳答案

试试这个。

字符串路径 = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.TestRunDirectory));

这将为您提供由 Atrias.WebAutomationTesting 创建的 TestResults 文件夹的父目录,我相信这就是您正在寻找的内容。

引用:MSDN: TestContext.TestRunDirectory Property

关于c# - 修改生成的执行程序集路径c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40211449/

相关文章:

c# - 如何调整 NotifyIcon 的大小?

c# - 我必须在我的 3 层架构应用程序中设置 SOAP 引用的位置

c# - 从 Angular 向 Asp.net 发送 post 请求时出现错误 405

c# - Microsoft.Extensions.Caching.Redis 选择与 db0 不同的数据库

asp.net - Visual Studio 不显示 'Manage Bower Packages...' 上下文菜单

C# 异步聚合和分派(dispatch)

c# - SandcaSTLe 错误 BE0073 .NET Framework 4.5

c# - List<T>.ForEach(Action) 和 Sql 事务的奇怪行为

c# - 没有给定的参数对应于所需的形式参数 - .NET 错误

ASP.Net session 状态提供程序故障转移场景