在执行程序集相对路径

编程入门 行业动态 更新时间:2024-10-27 03:31:01
本文介绍了在执行程序集相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的工作,在这产生一个文件的应用程序测试方法的单元测试。所以,我决定把预期的文件名为资源/赋权/目录。 中的资源文件夹是在同一级别的单元测试项目的bin文件夹。

I am working on Unit tests that test a method in an application that produces a file. So I decided to put an expected file in a directory called Resource/Empower/. The resource folder is at the same level as the bin folder of the Unit Test project.

现在我想要做的就是文件的路径名称。我不能硬编码,因为我并不完全关于构建服务器上的驱动器知道。

Now what I want to do is get the path of the file name. I cannot hard code because I don't know exactly about the drives on the build server.

那么,如何获得文件的相对路径。比方说,如果文件名是 expectedMasterFileSetUp.txt ?

So how do I get the relative path of the file. Lets say if the file Name is expectedMasterFileSetUp.txt?

我想要的路径资源/Empower/ExpectedMasterFileSetUp.txt

推荐答案

为什么要使用URI?

string AbsolutePathRelativeToEntryPointLocation( string relativePath ) { Assembly entryPoint = Assembly.GetEntryAssembly() ; string basePath = Path.GetDirectoryName( entryPoint.Location ) ; string combinedPath = Path.Combine( basePath , relativePath ) ; string canonicalPath = Path.GetFullPath( combinedPath ) ; return canonicalPath ; }

更多推荐

在执行程序集相对路径

本文发布于:2023-11-13 09:30:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!