【问题标题】:System cannot find specified file when I'm trying to convert xsd to .cs当我尝试将 xsd 转换为 .cs 时,系统找不到指定的文件
【发布时间】:2015-09-10 21:09:02
【问题描述】:

当我尝试使用 C# 代码将 xsd 转换为 cs 时出现以下错误

错误详情
Microsoft (R) Xml Schemas/DataTypes 支持实用程序 [Microsoft (R) .NET Framework,版本 4.0.30319.17929] 版权所有 (C) 微软公司。版权所有。写入文件 'C:\Program 文件 (x86)\Microsoft Visual Studio 11.0\abc.cs'。错误:错误 为模式“C:\test\safe”生成类。访问路径 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\abc.cs' 是 拒绝。

代码

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        Process p = new Process();
        string xsdFile = "c:\\test\\abc.xsd";

        try
        {
            if (!File.Exists(xsdFile))
            {
                Console.WriteLine("Error. File doesn't exists.");
                Environment.Exit(1);
            }
            String pass = "********";
            p.StartInfo.UserName = "asdasd";
            p.StartInfo.Domain = "asdasd";
            SecureString passWord = new SecureString();
            foreach (char c in pass.ToCharArray())
            {
                passWord.AppendChar(c);
            }

           p.StartInfo.Password = passWord;
            p.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\XSD.exe";
             p.StartInfo.UseShellExecute = false;
              p.StartInfo.WorkingDirectory = @"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin";
              p.StartInfo.Arguments = "/c " + xsdFile;

            p.Start();
            Console.WriteLine(p.StartInfo.WorkingDirectory);
            Console.ReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine(p.StartInfo.WorkingDirectory);
            Console.ReadLine();
        }
    }
}
}

【问题讨论】:

  • 你用过调试器吗..现在来吧..单步执行代码并检查路径和文件名是否存在..!

标签: c# .net xsd


【解决方案1】:

正如它所说...访问被拒绝。 从这个开始:在“发布”模式下手动清理和构建您的应用程序。导航到您的“发布”文件夹并以管理员身份运行您的 EXE。如果这可行,您只需要确保运行该应用程序的用户(可能是您自己)对“C:\Program Files (x86)\Microsoft Visual Studio 11.0\”具有完全读/写访问权限,您也可以使用此链接: How to start a Process as administrator mode in C# 帮助您以管理员身份自动运行新进程。

这也可能只是您所期望的错误:

根据您上面的内容,我假设这不是您预期的输出目录,您应该考虑为 XSD.exe 使用“/outputdir:directory”开关

【讨论】:

    猜你喜欢
    • 2017-12-16
    • 2013-12-30
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多