本文介绍了Visual Studio扩展无法从ENVDTE.DTE VSIX for C ++项目获取outputfilename / targetfile名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编写Visual Studio扩展,我需要在解决方案中获取C ++项目的OutputFileName或TargetFileName。例如,在示例解决方案中,此OutputFileName或TargetFileName将是ConsoleApplication.dll(请注意其区分大小写)。我写了一些如下所示的代码来实现这一点,但是我的代码在下面的行中崩溃了。唯一可行的方法是当我尝试获取输出路径时。 OutputFileName在两种情况下都崩溃,如下面的代码所示。我还尝试使用外部dll使用Microsoft.VisualStudio.VCProjectEngine将其转换为VCProject,但我不知道如何获取OutputFileName或TargetFileName,也不知道它是否会起作用。



以下互联网上的示例应该有效。但它不起作用。正如我所说的OutputPath有效。这是因为它是一个非托管的C ++项目,我必须使用其他方式获取路径吗?我可以确认我正在使用的项目是有效的C ++非托管项目。



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?

推荐答案


这篇关于Visual Studio扩展无法从ENVDTE.DTE VSIX for C ++项目获取outputfilename / targetfile名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 04:02