问题
I'm trying to use some existing C# code in a WinRT (Windows Store/Metro) project.
This code relied on some xml files generated using XSD.
Unfortunately it seems the old XmlDocument classes aren't available in WinRT... there are some alternatives, but they don't seem to be quite the same - so I need to generate some new files for WinRT.
Is there a way to import an XSD file into a WinRT project so that all the data classes, and enums are generated and can be used in the Metro project?
I've looked around and found nothing particularly helpful - e.g. just http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/88d9b73b-5faa-4204-9d06-dc121e709943.
I've tried to import some XSD files into WinRT projects - but these don't seem to generate anything.
Do I really have to port the generated xsd files across from .Net to WinRT? :(
The schemas I'm importing are quite large and I have quite a lot of existing code that uses the XSD approach - so I really want to avoid having to do a one-time port of all this code by hand unless I really have to...
回答1:
Ok this question is very old but in case others are having the same question / problem as i did, here is a (not completely free) solution:
- Download the xsd2code plugin (https://xsd2code.codeplex.com/) / or with the VS tools downloader
- Register for a 15 days trial (you could also buy it)
- Import the .xsd files in your project
- Right click on them (one after one) and select "run xs2code"
- (Here is the awesome stuff!) As target framework choose WinRT
- Generate the code and be happy!
Sadly i only found this tool (which has only a free 15 days trial) which was capable for doing this (generating code for WinRT / UWP / WinPhone)
来源:https://stackoverflow.com/questions/12770817/using-xsd-files-in-winrt-projects