Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the macro value of project's TargetPath via DTE

I need to get the absolute output path of the project's assembly via DTE. I tried doing this using this method, where I would access the OutputPath property, combining it with the assembly name, however this produces the relative path, such as:

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

Using Path.GetFullPath is not good for me, because my project might be executing from another location.

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

Actual question is - how do I get the absolute output path of the project?

like image 802
Igal Tabachnik Avatar asked Nov 02 '25 17:11

Igal Tabachnik


1 Answers

I don't know how to programmatically access the "$(TargetPath)", I agree that that could've been the best solution.

However, the approach you mentioned should still be workable,since the OutputPath property is relative to the folder in which the project file resides. (Please let me know if I'm missing some scenario where this is not the case?)

So you can do something similar to 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
                                  });
    }

(the overload of Path.Combine used here is only available in .NET 4.0 but you could always backport it)

like image 127
Omer Raviv Avatar answered Nov 04 '25 14:11

Omer Raviv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!