XSD.exe更改参数

时间:2015-10-28 09:07:54

标签: xsd xsd.exe

我目前正在使用XSD.exe工具来获取XSD文件类。 但是当我将文件传递给工具时,它会更改路径/文件。

string fileName = "C:\\TEST\\testFILE.xsd";  
Process p = new Process(); 
p.StartInfo = new ProcessStartInfo("C:\\xsd.exe", "/c /language:CS " +   fileName);       
p.StartInfo.RedirectStandardOutput = true;  
p.StartInfo.RedirectStandardError = true;   
p.StartInfo.UseShellExecute = false;  
p.Start();

StringBuilder error = new StringBuilder();
while (!p.HasExited)                                    
    error.Append(p.StandardError.ReadToEnd());
MessageBox.Show(error.ToString());

这是一些示例代码,可以向您显示问题。 输出如下:

Error: Could not find file "c:\test\testfile.xsd

当然没有这样的文件或目录。 你们有任何想法如何解决这个问题吗?

谢谢;)

1 个答案:

答案 0 :(得分:0)

我发现了问题。上面给出的例子中的路径是一个糟糕的选择。事实上,我真正使用的路径包含空格。 XSD.exe使用空格来分隔参数。所以你必须在路径字符串的开头和结尾添加一些额外的引号。

例如:

string cmdPath= String.Format(@"""{0}""", path);