通过控制台界面访问编译器时包含库

时间:2012-08-06 15:15:23

标签: c# windows visual-studio console

this例子的启示下,我决定扩展Factorial课程。

using System;
using System.Numerics;

namespace Functions
{
    public class Factorial
    {
        public static BigInteger CalcRecursively(int number)
        {
            if (number > 1)
                return (BigInteger)number * CalcRecursively(number - 1);
            if (number <= 1)
                return 1;

            return 0;
        }

        public static BigInteger Calc(int number)
        {
            BigInteger rValue=1;

            for (int i = 0; i < number; i++)
            {
                rValue = rValue * (BigInteger)(number - i);                
            }

            return rValue;

        }      
    }
}

我使用过System.Numerics,默认情况下不包含它。因此,命令
csc /target:library /out:Functions.dll Factorial.cs DigitCounter.cs输出:

Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

Factorial.cs(2,14): error CS0234: The type or namespace name 'Numerics' does not
        exist in the namespace 'System' (are you missing an assembly reference?)
DigitCounter.cs(2,14): error CS0234: The type or namespace name 'Numerics' does
        not exist in the namespace 'System' (are you missing an assembly
        reference?)
Factorial.cs(8,23): error CS0246: The type or namespace name 'BigInteger' could
        not be found (are you missing a using directive or an assembly
        reference?)
Factorial.cs(18,23): error CS0246: The type or namespace name 'BigInteger' could
        not be found (are you missing a using directive or an assembly
        reference?)
DigitCounter.cs(8,42): error CS0246: The type or namespace name 'BigInteger'
        could not be found (are you missing a using directive or an assembly
        reference?)

行。我错过了一个装配参考。我想“它一定很简单。整个系统应该是两个System.Numerics.dll文件 - 我需要的是添加到命令/链接:[System.Numerics.dll的x86版本的路径]”。搜索结果冻结了我的灵魂:enter image description here

正如你所看到的(或不是),有比我预测的更多的文件!而且,它们的大小和内容不同。我应该包括哪一个?为什么有五个文件,虽然只有两个存在点? / link:命令是否正确?或者我的思路可能完全错了?

1 个答案:

答案 0 :(得分:6)

我一般都发现使用

/r:System.Numerics.dll

让编译器只需在GAC中找到程序集,这通常是您想要的方式。 (当然,前几天我需要System.Numerics用于控制台应用程序时很好......)