在C#中检索项目引用 [英] Retrieving project references in C#

查看:126
本文介绍了在C#中检索项目引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用c#代码浏览项目文件,即.csproj文件使用FileOpenDialog使用以下代码

Hi,

I am using c# code to browse project files i.e .csproj file using FileOpenDialog using the following code

OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Project Files|*.csproj;";
if (dlg.ShowDialog() == DialogResult.OK)
{                
     string filePath = dlg.FileName;         
     Microsoft.Build.Evaluation.Project project = new 
                Microsoft.Build.Evaluation.Project(dlg.FileName);
}





现在我想获取已加载项目中所有项目引用的列表,但不知道如何要做到这一点。



我很感激提前回复。



我是什么尝试过:



我正在探索MSBuild API,但无法获得任何有用的东西。



Now I want to get the list of all the project references in the loaded project, but do not know how to do this.

I am thankful to any response in advance.

What I have tried:

I am exploring MSBuild API but could not get any thing useful.

推荐答案

此时,您可以使用调试器来探索项目变量的内容:在初始化<$的行上放置一个断点c $ c> project 变量,然后启动调试会话。在对话框中选择一个文件,然后按打开。 IDE应该返回并等待您发出调试指令。按 F10 执行项目初始化。从这里,您将能够观察存储在 Project 对象中的所有值。有许多属性是值的集合;引用可能在其中一个内部。

如果调试器有问题,可以询问更多详细信息。
At this point, what you can do is using the debugger to explore the content of the project variable: put a breakpoint on the line where you are initializing the project variable, and launch a debug session. Select a file in the dialog and press Open. The IDE should come back and wait for you to issue debug instructions. Press F10 to execute the project initialization. From here you will be able to watch all values stored in the Project object. There are a bunch of properties which are collections of values; references may be inside one of them.
You can ask further details if you have issues with the debugger.


这篇关于在C#中检索项目引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆