如何通过命令提示符编译C#应用程序
我有一个文件夹。我有三个cs文件 Demo.cs如何通过命令提示符编译C#应用程序,c#,C#,我有一个文件夹。我有三个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.CreateInstanc
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());
}
}
}
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; }
}
}
实体.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());
}
}
}
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
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());
}
}
}
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文件格式。
但尝试运行命令提示符时出错。它在VisualStudio中运行
我想使用命令提示符运行Test.cs、Entity.cs,并将“Employee.cs”作为字符串参数传递给Main方法。
现在,我通过了硬编码as
System.Runtime.Remoting.ObjectHandle objectHandler = Activator.CreateInstance(null, "Demo.Employee");
工作正常,但如何通过命令传递
发生的错误是:
cs(8,29):错误CS0234:类型或命名空间名称
命名空间中不存在“DataAnnotations”
'System.ComponentModel'(是否缺少程序集引用?)Entity.cs(9,19):错误CS0234:类型或命名空间名称
“对象”
命名空间“System.Data”中不存在(是否缺少
程序集引用?)Employee.cs(6,33):错误CS0234:类型或命名空间名称“DataAnnotations”不正确
命名空间“System.ComponentModel”中不存在(是否缺少
装配参考?)
它还显示了“数据注释”和“对象”的错误
如何解决这个问题?一个简单的选择
更有趣的是通过csc的命令行参数自己配置所有依赖项。对于您的即时错误,您需要使用与以下类似的/r:
命令添加引用
csc /out:Test.exe /r:System.ComponentModel.DataAnnotations.dll *.cs
有关csc命令行参数的更多详细信息,请查看帮助
csc/?
或MSDN和。什么是“尝试通过命令提示符运行时”?可以显示您使用的命令吗?System.Data.DataAnnotations
命名空间的成员在System.ComponentModel.DataAnnotations.dll程序集中声明。是否引用了它?csc/out:Test.exe Test.cs Entity.cs Employee.css是的,我在项目中添加了此dll,但在命令提示符下显示错误。我更新了标题“run”->“compile”,因为看起来您实际上是在编译文件,而不是运行。请随意改进/恢复。我试着工作,但如何使用命令将类作为参数传递给Test.cs中的Main方法prompt@user3582190您正在查找test.exe arg1
?如何从命令行运行可执行文件,并将参数传递给它,这在SO上是无关紧要的。如果这是你的真实问题-考虑更多的信息……是的,我正在寻找Test.EXARG1,但是这里我把类名传递为一个AgMut.Test.CS“demo.Engress”,它显示了错误,未处理的异常:Soal.AguMutnulLeExpRe:值不能为NULL。参数名称:System.Activator.CreateInstance(activationContext activationContext activationContext,String[]activationCustomData)处的System.Runtime.Hosting.ApplicationActivator.CreateInstance(activationContext activationContext,Strin g[]activationCustomData)处的Demo.Test.Main(String[]args)