[英]How to Run c# application through Command Prompt?
I have Two classes. 我有两节课。 Test.cs, Entity.cs.
Test.cs,Entity.cs。
I have put this two files in one folder "CommandTest". 我将这两个文件放在一个文件夹“ CommandTest”中。
*Test.cs Class * Test.cs类
namespace Demo
{
public class Test
{
public static Entity entity= new Entity();
public static void Main(string[] args)
{
Console.WriteLine("Demo");
}
*Entity.cs class * Entity.cs类
namespace Demo
{
public class Entity
{
Console.WriteLine("entity");
}
}
When I am Trying to run it through "Visual Studio Command Prompt". 当我尝试通过“ Visual Studio命令提示符”运行它时。 It shows Error,
它显示错误,
Test.cs(10,28): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'Demo' (are you missing an assembly reference?)
Test.cs(10,28):错误CS0234:类型或名称空间名称“ Entity”在名称空间“ Demo”中不存在(您是否缺少程序集引用?)
I am not getting why it is shows error. 我不明白为什么它显示错误。 Because both class have same namespace.
因为两个类具有相同的名称空间。 How can I run it through Command Prompt.
如何通过命令提示符运行它。
Thanks. 谢谢。
You should use all files when calling csc
. 调用
csc
时应使用所有文件。 It doesn't try to find the code files itself. 它不会尝试查找代码文件本身。 Try this:
尝试这个:
csc /out:Test.exe Test.cs Entity.cs
Or, maybe easier: 或者,也许更容易:
csc /out:Test.exe *.cs
Also, read the related MSDN article . 另外,请阅读相关的MSDN文章 。
Don't forget to add this code block in a method too: 也不要忘记在方法中添加此代码块:
namespace Demo
{
public class Entity
{
public void SomeMethod() /* here */
{
Console.WriteLine("entity");
}
}
}
you need to provide name of all classes explicitly. 您需要明确提供所有类的名称。 so in your case you will execute
因此,在您的情况下,您将执行
csc.exe /out:ExecutableName.exe Entity.cs Test.cs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.