gnazim
gnazim

Reputation: 35

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

Upvotes: 1

Views: 713

Answers (1)

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23685

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

Upvotes: 1

Related Questions