3

I'm creating a windows service in c# .net, and want to deploy it into a system where i don't have .net runtime.
My question is that is that service works without having .net runtime? if no then how it work without having a runtime?

Amit Bisht
  • 4,870
  • 14
  • 54
  • 83

3 Answers3

8

A Windows Service is just an executable that responds to certain calls by the Service Control Manager.

So if you program the service's executable to run on .NET, the machine running the service has to have the .NET runtime installed.

The only alternative to having to install or embed/self-host the .NET runtime would be to not use .NET.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thanks @CodeCaster, but i have a silly doubt that there are already services installed on my system that are windows default services, so how these services work without having runtime(i'm guessing that they are also developed in .net) – Amit Bisht Apr 21 '15 at 09:52
  • 2
    @Co.Aden:- Are you sure that they are developed in the .net framework? (*I really doubt that*) – Rahul Tripathi Apr 21 '15 at 09:53
  • @Co.Aden no, you cannot run .NET applications without some form of a .NET runtime. I also find it hard to believe that you found a Windows machine that doesn't have .NET installed. – CodeCaster Apr 21 '15 at 09:53
  • @RahulTripathi Actually that is my doubt too.. :) – Amit Bisht Apr 21 '15 at 09:56
  • @Co.Aden:- As far as I know and what I have read it is not possible. – Rahul Tripathi Apr 21 '15 at 10:00
  • It _is_ possible to embed the runtime in an executable. More information can be found on this when searching for "embed .NET runtime", "CLR hosting", ".NET static linking" or ".NET Native". It's not very likely though that those techniques were used for the services you found installed on the machine. – CodeCaster Apr 21 '15 at 10:05
  • 2
    It is **NOT** possible to run a .net executable without having the (relevant) .Net Framework installed. _ILMerge_ merges assemblies, it doesn't merge the runtime. _NGen_ bypasses the Just-In-Time compiler, but you still need the runtime. You can do both of these things _and you'd still need the runtime_ – Binary Worrier Apr 21 '15 at 10:18
  • 1
    @BinaryWorrier I didn't mention ILMerge or NGen. In the end the CLR is just a Win32 application that is a runtime that runs bytecode. You can create one executable that contains the runtime and the application's bytecode, so you don't need to install .NET in order to run that executable. See [.NET Native](http://stackoverflow.com/questions/22907111/) (which is not NGen), or [read about embedding the runtime](http://stackoverflow.com/questions/270533/). In both cases you still need the framework libraries, which you can statically link into the executable. – CodeCaster Apr 21 '15 at 11:10
  • 1
    @BinaryWorrier I'm not talking about feasibility or possible licensing issues (nor asking whether you'd really want to), but it most certainly is possible to run a .NET application without having a separately installed runtime. You can't do that with _any_ .NET application though; the application itself will have to contain a runtime (or be started through a host) and relevant framework assemblies. – CodeCaster Apr 21 '15 at 11:13
  • 1
    @BinaryWorrier there also is not so much special about a ".NET executable". A .NET executable is compiled into a [Win32/PE executable that basically asks the installed CLR to run the bytecode included in the executable](http://en.wikipedia.org/wiki/Portable_Executable#.NET.2C_metadata.2C_and_the_PE_format). _That_ is the part that is replaced when embedding or self-hosting the runtime. – CodeCaster Apr 21 '15 at 11:21
3

You need the .Net runtime for this. Otherwise, you'll have to write your code from scratch using c++ (Not managed c++)

Oscar
  • 13,594
  • 8
  • 47
  • 75
1

Yes you need to have the .Net framework as the libraries and references used in the .net windows service might need the framework.

if no then how it work without having a runtime?

You need to install the .Net framework on your system else there is no option to use the windows service on your system.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331