简体   繁体   中英

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)

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# ?

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.

In that case, just load all the csproj within the solution folder:

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:

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):

Project project = new Project();
project.Load(projectFile);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM