在C#中检索构建输出文件夹 [英] Retrieving build output folder in C#

查看:72
本文介绍了在C#中检索构建输出文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想得到项目构建输出文件夹的名称,例如,如果构建配置是Debug,那么它应该是bin / Debug或者如果构建配置是然后释放它应该是bin / Release。



我使用了以下代码

Hi,

I want to get the name of project build output folder e.g if Build configuration is Debug then it should be bin/Debug or if Build configuration is Release then it should be bin/Release.

I have used following code

Microsoft.Build.Evaluation.Project project =
               new  Microsoft.Build.Evaluation.Project(projectfilename);
               string assemblyPath = project.GetPropertyValue("OutputPath");





但我总是得到assembleyPath =bin / Debug配置是什么。



我很感激提前回复。



我尝试过的事情:



我使用了以下代码



But I am always getting assembleyPath = "bin/Debug" what ever the configuration is.

I am thankful to any response in advance.

What I have tried:

I have used following code

Microsoft.Build.Evaluation.Project project =
               new  Microsoft.Build.Evaluation.Project(projectfilename);
               string assemblyPath = project.GetPropertyValue("OutputPath");

推荐答案

可能最安全的方法是获取可执行文件路径:Application.ExecutablePath属性(System.Windows.Forms)| Microsoft Docs [ ^ ]
Probably the safest way is to fetch the executable path: Application.ExecutablePath Property (System.Windows.Forms) | Microsoft Docs[^]


您可以使用:
Assembly.GetExecutingAssembly().Location

但不适用于Windows服务,那么最好使用:

But not for a Windows service, then it's better to use:

string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) ?? string.Empty;


我找到了一些示例,说明如何使用 project.GetPropertyValue()

Project.GetPropertyValue,Microsoft。 Build.Evaluation C#(CSharp)Code-Beispiele - HotExamples [ ^ ]

希望您觉得这个答案更有帮助:)
I found some examples that show how to use project.GetPropertyValue():
Project.GetPropertyValue, Microsoft.Build.Evaluation C# (CSharp) Code-Beispiele - HotExamples[^]
Hope you find this answer more helpful :)


这篇关于在C#中检索构建输出文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆