本文介绍了API检查项目变量和参考路径在项目文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我工作的一个 .NET应用程序(VS2010)随x没有。解决方案和可变没有。在这些解决方案的项目。我需要检查,如果该项目的属性(具体以一定数量的项目)是同质的,也在生成过程中检查/验证的参考路径。是否有一个 API 这样做吗?如果不是,我怎么去建设一个?I am working on a .net application (VS2010) with x no. of solutions and variable no. of projects in those solutions.I need to check if the project properties (specific to a certain number of projects) are homogenous, and also check/validate the reference paths during the build.Is there an API that does this? If not, how do i go about building one?推荐答案您可以使用的MSBuild框架来做分析和项目文件进行评估。你需要使用的主要类 ProjectCollection 和项目。 You can use MSBuild framework to do the parsing and perform evaluation of the project files. The main classes you need to use are ProjectCollection and Project. 但是,首先你需要处理你的.sln文件。由于API不能直接加载的.sln文件,则需要先在您的.sln文件转换为项目文件,该API可以加载。该方法是这里描述。您将获得转换后.sln.metaproj的文件,这是等价的重$ P $的.sln的psentation,但MSBuild的格式。之后,你可以分析.sln.metaproj文件和引用的项目和评估你需要的属性。此示例打印出OutputPath财产评估调试|解决方案中的所有项目中值为anycpu配置:But first you will need to deal with your .sln files. Since API cannot load .sln files directly, you will need first to convert your .sln files to projects files, that API can load. The method is described here. You will get a .sln.metaproj files after conversion, that are equivalent representation of .sln, but have MSBuild format. After that you can parse .sln.metaproj files and referenced projects and evaluate properties you need. This sample prints out the OutputPath property evaluation for Debug|AnyCPU configuration of all projects in the solution: Dictionary<string, string> globalProperties = new Dictionary<string, string>(); globalProperties.Add("Configuraion", "Debug"); globalProperties.Add("Platform", "AnyCPU"); ProjectCollection pc = new ProjectCollection(globalProperties); Project sln = pc.LoadProject(@"my_directory\My_solution_name.sln.metaproj", "4.0"); foreach (ProjectItem pi in sln.Items) { if (pi.ItemType == "ProjectReference") { Project p = pc.LoadProject(pi.EvaluatedInclude); ProjectProperty pp = p.GetProperty("OutputPath"); if (pp != null) { Console.WriteLine("Project=" + pi.EvaluatedInclude + " OutputPath=" + pp.EvaluatedValue); } } } 这篇关于API检查项目变量和参考路径在项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 21:34