[英]How to compile C# application through Command Prompt
我有一个文件夹。 在那我有三个cs文件。
Demo.cs
using System;
namespace Demo
{
public class Test
{
public static Entity entity = new Entity();
public static void Main(string[] args)
{
var objectHandler = Activator.CreateInstance(null,
args);
var obj = objectHandler.Unwrap();
entity.GetAnnotation(obj.GetType());
}
}
}
Entity.cs
using System;
namespace Demo
{
public class Entity
{
public void GetAnnotation(Type classname)
{
Attribute[] dataAnnotationlist = Attribute.GetCustomAttributes(propInfo);
foreach (var dataannotationAttribute in dataAnnotationlist)
{
//some operation to get annotation property from Employee.cs class
}
}
}
}
员工
using System.ComponentModel.DataAnnotations;
namespace Demo
{
public class Employee
{
[Display(Name = "name")]
public string name { get; set; }
}
}
我已经使用反射从类文件(Employee.cs)创建了XML文件格式。 但是,尝试通过命令提示符运行时发生错误。 它在Visual Studio中运行。
我想通过将“ Employee.cs”作为字符串参数传递给Main方法的命令提示符来运行Test.cs,Entity.cs。 现在,我通过了硬编码,
System.Runtime.Remoting.ObjectHandle objectHandler = Activator.CreateInstance(null, "Demo.Employee");
它的工作正常,但如何通过命令传递它。
发生的错误是:
Entity.cs(8,29):错误CS0234:类型或名称空间名称'DataAnnotations'在名称空间'System.ComponentModel'中不存在(您是否缺少程序集引用?)Entity.cs(9,19):错误CS0234:类型或名称空间名称'Objects'在名称空间'System.Data'中不存在(您是否缺少程序集引用?)Employee.cs(6,33):错误CS0234:类型或名称空间名称'DataAnnotations'名称空间“ System.ComponentModel”中不存在(您是否缺少程序集引用?)
并且还会显示“ DataAnnotations”和“ Objects”的错误。
我怎么解决这个问题?
更具娱乐性的是,您可以通过csc的命令行参数自己配置所有依赖项。 对于立即出现的错误,您需要使用/r:
命令添加引用,类似于以下内容
csc /out:Test.exe /r:System.ComponentModel.DataAnnotations.dll *.cs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.