简体   繁体   English

C#编译器:/ nostdlib选项

[英]C# compiler: /nostdlib option

How is this possible not to include stdlib (mscorlib.dll) to my C# application when compiling it? 在编译时,如何才能将stdlib(mscorlib.dll)包含到我的C#应用​​程序中? As far as I know, all classes inherit System.Object class, which is defined in mscorlib.dll. 据我所知,所有类都继承System.Object类,该类在mscorlib.dll中定义。 What is more - types such as int are just aliases eg for System.Int32, which are also defined in mscorlib. 更重要的是 - 诸如int之类的类型只是例如System.Int32的别名,它们也在mscorlib中定义。 Is this option ever used? 这个选项曾经使用过吗?

Yes, it is used by anybody that compiles a program that doesn't run with the desktop version of the CLR. 是的,编译程序不能与CLR的桌面版本一起运行的任何人都可以使用它。 Like Silverlight, it targets .NETCore, or the Micro Framework. 与Silverlight一样,它的目标是.NETCore或Micro Framework。 They have their own mscorlib.dll, of course with System.Object defined. 他们有自己的mscorlib.dll,当然定义了System.Object。

Here's the compiler command line of a sample Silverlight project: 这是Silverlight项目示例的编译器命令行:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 
/nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE;SILVERLIGHT
/reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\mscorlib.dll" 
  etc...

According to the docs 根据文件

http://msdn.microsoft.com/en-us/library/fa13yay7(VS.80).aspx http://msdn.microsoft.com/en-us/library/fa13yay7(VS.80).aspx

You use it if you are trying to replace the System classes. 如果您尝试替换System类,则使用它。

You may also want to use it if you want to build to deploy against an older framework version. 如果要构建以针对较旧的框架版本进行部署,您可能还希望使用它。 Visual Studio (15, anyway) uses this option when building a project that you configured to target an older framework version. Visual Studio(15,无论如何)在构建您配置为以较旧框架版本为目标的项目时使用此选项。 Instead of using the standard mscore, it uses one from Reference Assemblies/Microsoft/Framework/vx.y 它不使用标准mscore,而是使用Reference Assemblies / Microsoft / Framework / vx.y中的一个

From MSDN - "Use this option if you want to define or create your own System namespace and objects.". MSDN - “如果要定义或创建自己的系统命名空间和对象,请使用此选项。”。 Fair enough - I won't be doing that any time soon, tho'. 足够公平 - 我不会很快这么做,所以。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM