Andy Clarke
Andy Clarke

Reputation: 3262

c# best way to grab a xsd from a referenced project

My application references another a project which has an XSD file in it.

Whats the best way to get that XSD?

I did a bit of googling and found suggestions like load the assembly and get it from that, is there no easier way?

Upvotes: 1

Views: 1152

Answers (2)

Jeff Yates
Jeff Yates

Reputation: 62377

If you've added the XSD as a resource then the easiest way is to make the auto-generated Properties.Resources class publicly visible and reference the auto-generated property. You could also keep Properties.Resources internal and add an InternalsVisibleTo attribute to allow your other assembly to have access.

Other than that approach, you can use the GetManifestResourceStream on the target assembly to extract the XSD information.

Upvotes: 0

driis
driis

Reputation: 164291

If the XSD is an embedded resource in the assembly, then you need to get it from the assembly.

If your project references and uses the assembly, then you won't need to load it again (you don't need 2 copies in memory).

The easiest way to get to the assembly, would be from one of the types defined in it:

Type t = typeof(TypeInOtherAssembly);
Assembly assembly = t.Assembly;
assembly.GetManifestResourceStream(...);

Upvotes: 3

Related Questions