[英]Get list of all resx files in project programmability
I want to get a list of all the resx files available in the project and their path , by any .net entity (and not by System.IO) 我想通过任何.net实体(而不是System.IO)获取项目中可用的所有resx文件及其路径的列表。
When I open a csproj file with notepad , I can see a xml which reflecting the project tree hierarchy included all resx files Can I pass through this data programmability in c# ? 当我用记事本打开csproj文件时,可以看到一个反映项目树层次结构的xml,其中包括所有resx文件。我可以在c#中通过此数据可编程性吗?
It depends, if you want to consider only the resx
files that are included into projects, you have to parse the csproj
files (which are nothing but an XML
file basically) and traverse them in order to retrieve the resx
references. 这取决于是否只考虑项目中包含的
resx
文件,则必须解析csproj
文件(基本上只是XML
文件而已)并遍历它们以检索resx
引用。
In that case, just load all the csproj
within the solution folder: 在这种情况下,只需将所有
csproj
加载到解决方案文件夹中:
var projectFiles = Directory.GetFiles(solutionDir,"*.*",SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".csproj");
and go for the brutal parsing. 然后进行残酷的分析。
If you just want to pick all the resx
files, without considering whether they are included into a project or not: 如果您只想选择所有的
resx
文件,而不考虑它们是否包含在项目中:
var resxFiles = Directory.GetFiles(solutionDir,"*.*",SearchOption.AllDirectories).Where(f => Path.GetExtension(f) == ".resx");
You could also parse your csproj
files using the MSBuild API
(you need to reference the Microsoft.Build.Engine
assembly): 您还可以使用
MSBuild API
解析csproj
文件(您需要引用Microsoft.Build.Engine
程序集):
Project project = new Project();
project.Load(projectFile);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.