如何通过命令提示符运行c#应用程序?

时间:2014-08-28 10:49:58

标签: c#

我有两节课。 Test.cs,Entity.cs。

我已将这两个文件放在一个文件夹中" CommandTest"。

* Test.cs Class

namespace Demo
{
 public class Test
{
 public static Entity entity= new Entity();
 public static void Main(string[] args)
{
Console.WriteLine("Demo");
}

* Entity.cs类

namespace Demo
{
public class Entity
{
Console.WriteLine("entity");
}
}

当我试图通过" Visual Studio命令提示符"来运行它时。 它显示错误,

  

Test.cs(10,28):错误CS0234:类型或命名空间名称'实体'           名称空间中不存在“演示”#39; (你错过了一个集会吗?           引用?)

我不知道为什么显示错误。因为两个类都有相同的命名空间 如何通过命令提示符运行它。

感谢。

2 个答案:

答案 0 :(得分:2)

调用csc时应使用所有文件。它并没有试图找到代码文件本身。试试这个:

csc /out:Test.exe Test.cs Entity.cs

或者,也许更容易:

csc /out:Test.exe *.cs

另外,请阅读相关的MSDN article

不要忘记在方法中添加此代码块:

namespace Demo
{
    public class Entity
    {
        public void SomeMethod() /* here */
        {
            Console.WriteLine("entity");
        }
    }
}

答案 1 :(得分:1)

您需要明确提供所有类的名称。所以在你的情况下你将执行

csc.exe /out:ExecutableName.exe Entity.cs Test.cs
相关问题