XML code analysis like Roslyn for Visual Studio

267 Views Asked by At

Is there a way to enforce set of rules on xml file included in .NET project?

In my case I would like to throw compiler error if some settings are not set in hbm.xml file (nHibernate mapping).

I know about xsd files, but I would need to do an overriding of existing nHibernate schema, which in its current form is complicated (it requires xml 1.1).

[Edit]:
To be specific: I want to define a rule that gives a compilation error, when an nhibernate hbm file doesn't contain specific property set (dynamic-update="true").

2

There are 2 best solutions below

1
Oskar Berggren On BEST ANSWER

Another option is to write unit tests loads the XML files and performs the checks you want. They could look at classes too, perhaps using reflection to automatically applythe same checks to new classes.

1
Paulo Morgado On

Roslyn is the technology behind the C# and VB compilers. It only deals with C# and VB source files.

You can add MSBuild tasks to your project to validate your XML files.