Getting TargetPath Project Macro Value via DTE

I need to get the absolute output path of the project assembly through the DTE. I tried to do this using this method , where I would access the OutputPath property by combining it with the assembly name, however this creates a relative path, such as:

..\..\Output\AnyCPU\Debug\MyAssembly.dll

Using Path.GetFullPath not suitable for me, because my project can be executed from another place.

I noticed that the $ (TargetPath) macro (on the Build Events tab in the project properties) contains the full build path. How can I access this value programmatically from the DTE?

Actual question: how to get the absolute path to the output of the project?

+3
source share
1 answer

I don’t know how to programmatically access "$ (TargetPath)", I agree that this could be a better solution.

However, the approach you mentioned should still be workable, since the OutputPath property refers to the folder in which the project file is located. (Please let me know if I am missing a script where this is not the case?)

So you can do something like this:

  private static string GetProjectExecutable(Project startupProject, Configuration config) { string projectFolder = Path.GetDirectoryName(startupProject.FileName); string outputPath = (string)config.Properties.Item("OutputPath").Value; string assemblyFileName = (string)startupProject.Properties.Item("AssemblyName").Value + ".exe"; return Path.Combine(new[] { projectFolder, outputPath, assemblyFileName }); } 

(overloading the Path.Combine used here is only available in .NET 4.0, but you can always download it)

+2
source

All Articles