Can you compile C# so it doesn't need the .NET Framework at runtime?

前端 未结 8 1256
暖寄归人
暖寄归人 2020-11-28 08:53

Is it possible to force the C# compiler to pull all the referenced calls out of the framework and pack them into dlls or even a single executable?

I like writing qu

相关标签:
8条回答
  • 2020-11-28 09:06

    Some C# features are bound to interfaces of the .NET framework.

    For example:

    yield return requires the IEnumerable interface

    using (x) {} requires the IDisposable interface

    0 讨论(0)
  • 2020-11-28 09:07

    Take a look at the .NET client profile. This will allow you to package a minimum install on the client machine.. which will later be updated by windows update to the full framework.

    This depends, of course, on your app only using libraries that are contained in the client profile ...

    Some info here: http://blogs.windowsclient.net/trickster92/archive/2008/05/21/introducing-the-net-framework-client-profile.aspx

    0 讨论(0)
  • 2020-11-28 09:09

    Look at mkbundle using Mono.

    0 讨论(0)
  • 2020-11-28 09:11

    It's said it is possible, using 3rd-party tools such as http://www.remotesoft.com/linker/

    0 讨论(0)
  • 2020-11-28 09:14

    You ask a loaded question. C# is merely a language and does not require the .NET Framework. The process of compiling it requires a compiler, which may or may not itself take a dependency on the .NET Framework (Microsoft's C# compiler does not -- it is written in native code). Your program will need to reference some assembly where types, classes, and methods can be found for your use. You can remove system.dll and mscorlib.dll from your references list and reference your own assemblies. So you can avoid dependencies on the .NET Framework if you really work at it. But in the end, unless you have a C# compiler that compiles programs to native code you still have a dependency on the CLR.

    That's a very technical way of saying... almost nothing. But it answers your question. :) More practically useful however is how to get your C# programs to run with a minimum of dependencies. mkbundle from mono will actually let you compile it all into an .exe with virtually no dependencies.

    But if you want to stick with the Microsoft .NET Framework, you can achieve a much lighter footprint and faster install of the dependencies you commonly need by using the Client profile of .NET 3.5 SP1. You can read about it here: http://msdn.microsoft.com/en-us/library/cc656912.aspx

    0 讨论(0)
  • 2020-11-28 09:18

    Not possible. Your "compiled" C# application is a language which the .Net CLR interprets (should have said JITed, Reads the IL, compiles to native code, and then invokes the compiled native code) at runtime.

    FYI .net 2.0 is a standard install on xp SP2 and vista, so you won't be paying that much of a penalty.

    You could look into mono, but this still involves running some kind of framework on your target machine.

    0 讨论(0)
提交回复
热议问题