Click here to Skip to main content
15,887,349 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i am writing a Visual Studio Extension and I need to get the OutputFileName or TargetFileName for C++ projects in the solution. For example in a sample solution this OutputFileName or TargetFileName would be ConsoleApplication.dll(note that its case sensitive). I wrote some code as shown below to achieve this but my code is crashing in the lines below. The only line that works is when i try to get Output Path. OutputFileName crashes in both cases as shown in code below. I also tried to cast it to a VCProject using Microsoft.VisualStudio.VCProjectEngine using the external dll but I dont know how to get the OutputFileName or TargetFileName nor do I not know if its going to work.

Examples on the internet show below should work. However it is not working. As I said OutputPath works. Is this because its an unmanaged C++ project and I have to get the path using some other way? I can confirm the projects i am working with are valid C++ unmanaged projects.

EnvDTE.DTE dte2 = Package.GetGlobalService(typeof(DTE)) as DTE;
          Projects projects2 = dte2.Solution.Projects;
string outputPath = projects2 [0].ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString(); //This works
        string outputFileName = projects2 [0].ConfigurationManager.ActiveConfiguration.Properties.Item("OutputFileName").Value.ToString(); //This crashes

       string outputFileName = list[0].Properties.Item("OutputFileName").Value.ToString();//This crashes


What I have tried:

string outputFileName = projects2 [0].ConfigurationManager.ActiveConfiguration.Properties.Item("OutputFileName").Value.ToString(); //This crashes

 string outputFileName = list[0].Properties.Item("OutputFileName").Value.ToString();//This crashes

VCProject vcproject = list[0].Object as VCProject;//How to use this?
Posted
Updated 21-Nov-17 3:56am
v2

1 solution

I found the solution. I did need the Microsoft.VisualStudio.VCProjectEngine DLL which is Visual Studio directory to work with unmanaged code and then write some code to access the property sheets.

Clues were obtained from below links:

envdte - How to iterate programmatically through all projects of Visual Studio 2008 solution considering Solution Folders - Stack Overflow[^]

How to read/write the new Visual C++ project properties | The Visual Studio Blog[^]


[Visual Studio Reference]
 
Share this answer
 
v2

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