Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");


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");
Posted
Updated 21-May-19 9:28am
v2

Probably the safest way is to fetch the executable path: Application.ExecutablePath Property (System.Windows.Forms) | Microsoft Docs[^]
 
Share this answer
 
Comments
irfankhan200 21-May-19 13:39pm    
But I am not reading the path of the currently running application. I want to read the path of exe file of another project(csproj) stored in the disk.
OriginalGriff 21-May-19 13:59pm    
I think you need to think some more about exactly what you are trying to do and why: and then explain in a lot more detail. Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. And if it isn't the executing assembly, or the initial EXE file, what exactly is it, and how do you know which one it should be?
You can use:
Assembly.GetExecutingAssembly().Location
But not for a Windows service, then it's better to use:
string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) ?? string.Empty;
 
Share this answer
 
Comments
irfankhan200 21-May-19 13:40pm    
But I am not reading the path of the currently running application. I want to read the path of exe file of another project(csproj) stored in the disk.
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 :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900