Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# compiler: /nostdlib option

Tags:

c#

.net

mscorlib

How is this possible not to include stdlib (mscorlib.dll) to my C# application when compiling it? As far as I know, all classes inherit System.Object class, which is defined in mscorlib.dll. What is more - types such as int are just aliases e.g. for System.Int32, which are also defined in mscorlib. Is this option ever used?

like image 984
Marc Andreson Avatar asked Aug 01 '10 18:08

Marc Andreson


3 Answers

Yes, it is used by anybody that compiles a program that doesn't run with the desktop version of the CLR. Like Silverlight, it targets .NETCore, or the Micro Framework. They have their own mscorlib.dll, of course with System.Object defined.

Here's the compiler command line of a sample Silverlight project:

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...
like image 172
Hans Passant Avatar answered Oct 22 '22 08:10

Hans Passant


According to the docs

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

You use it if you are trying to replace the System classes.

like image 32
Lou Franco Avatar answered Oct 22 '22 07:10

Lou Franco


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. Instead of using the standard mscore, it uses one from Reference Assemblies/Microsoft/Framework/vx.y

like image 1
Elroy Flynn Avatar answered Oct 22 '22 06:10

Elroy Flynn