【问题标题】:513 Error Code (exit code) FxCop using C#513 错误代码(退出代码)FxCop 使用 C#
【发布时间】:2012-12-12 12:00:07
【问题描述】:

我有 VS2010,Windows 7 位,FxCop 10.0

我使用 Process.Start 执行 Fxcopcmd.exe,得到 513 "exitcode"(错误代码)值。

以下参考文献中的托德·金说:

在这种情况下,退出代码 513 表示 FxCop 出现分析错误 (0x01) 和程序集引用错误 (0x200)

http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/1191af28-d262-4e4f-95d9-73b682c2044c/

我觉得如果是这样的

    [Flags]
    public enum FxCopErrorCodes
    {
        NoErrors = 0x0,
        AnalysisError = 0x1,  // -fatalerror
        RuleExceptions = 0x2,
        ProjectLoadError = 0x4,
        AssemblyLoadError = 0x8,
        RuleLibraryLoadError = 0x10,
        ImportReportLoadError = 0x20,
        OutputError = 0x40,
        CommandlineSwitchError = 0x80,
        InitializationError = 0x100,
        AssemblyReferencesError = 0x200,
        BuildBreakingMessage = 0x400,
        UnknownError = 0x1000000,
    }

513整数值为0x201(查看int to hex stringEnum.Parse fails to cast string

我如何仅使用 exitcode (513 , 0x201) 值以编程方式知道错误(分析错误 (0x01) 和程序集引用错误 (0x200))?

有关 FxCopCmd 的错误代码和代码分析的更多信息:

【问题讨论】:

标签: c# fxcop exit-code error-code fxcopcmd


【解决方案1】:

您可以使用 AND 位运算来测试枚举的特定值:

FxCopErrorCodes code = (FxCopErrorCodes)0x201;
if ((code & FxCopErrorCodes.InitializationError) == FxCopErrorCodes.InitializationError)
{
    Console.WriteLine("InitializationError");
}

您可以使用以下方式获取整个值列表:

private static IEnumerable<FxCopErrorCodes> GetMatchingValues(FxCopErrorCodes enumValue)
{
    // Special case for 0, as it always match using the bitwise AND operation
    if (enumValue == 0)
    {
        yield return FxCopErrorCodes.NoErrors;
    }

    // Gets list of possible values for the enum
    var values = Enum.GetValues(typeof(FxCopErrorCodes)).Cast<FxCopErrorCodes>();

    // Iterates over values and return those that match
    foreach (var value in values)
    {
        if (value > 0 && (enumValue & value) == value)
        {
            yield return value;
        }
    }
}

【讨论】:

猜你喜欢
  • 2013-09-20
  • 2019-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 2012-03-01
  • 2016-10-26
相关资源
最近更新 更多