xsd 到 class (C#) 在 visual studio 2019

xsd to class (C#) in visual studio 2019

我正在学习教程,它一步打开 "VS2012 arm cross tools command prompt" 并执行

xsd file.xsd /classes

我在我的电脑上找不到 "VS2012 arm cross tools command prompt"(我猜是因为我使用的是 VS2019)所以我改为打开 "Developer command prompt for VS 2019",但是当我 运行 命令时,我得到一个错误:

"xsd" is not recognized as an internal or external command, program or executable batch file

有人能告诉我如何在 VS 2019 中从 xsd 文件创建 class 吗?谢谢你的时间。

安装 Windows SDK 后。以下内容可能对您有所帮助……它是 .NET Core。浏览到 xsd.exe 并在 VS 2019 中添加对它的引用。

class Program
{
    static void Main(string[] args)
    {
        var rgs = new string[]
        {
            @"PathToYourDLL\My.dll",
            "/type:ClassNameToGen"
        };

        AppDomain.CurrentDomain.FirstChanceException += (s, e) =>
        {
            string error = e.Exception.ToString();

            var typeLoadException = e.Exception as ReflectionTypeLoadException;

            if (typeLoadException != null)
            {
                foreach (var exception in typeLoadException.LoaderExceptions)
                {
                    error += Environment.NewLine + Environment.NewLine + exception.ToString();
                }
            }

            Console.WriteLine(error);
        };

        XsdTool.Xsd.Main(rgs);

        Console.ReadLine();
    }
}