Can you run a .net class from the command line?

  • Thread starter Thread starter Robert Dobson
  • Start date Start date
R

Robert Dobson

I'm currently looking to port a Java project to .Net and
one thing I've not yet figured out is if you can run .Net
classes from the command line without going through all
the trouble of creating separate projects and building
them into executables.

In java you can just type "java.exe mypackage.MyClass" and
it runs as long as there is a "public static void main
(String[])" method in the class.

I realized in .Net the class is inside a DLL so the syntax
might be trickier, like "dotnet.exe my.dll
mypackage.MyClass" or some such.

Thanks.
 
In .NET you just run the compiled executable:
C:\> MyPackage.exe

In order to get the executable, you compile it with csc
csc /target:exe /r:referenced_libraries MyPackage.cs
 
I see no reason why you couldn't just write a simple dotnet.exe to do just
that, using reflection.
I don't know of an existing way to do it, but I wouldn't be surprised if one
exists.
 
One of the advantages of .NET over a scripted language like Java is the fact
that it's compiled. Why wouldn't you just compile it? How is it so much
trouble to 'create separate projects and build them into executables'? If
you are trying to run a DLL file, guess what? It's compiled. So if you
want to actually EXECUTE something, it would make a hell of a lot more sense
to compile it into an EXE not a DLL. If what you want to do (like make a
class library) then yes it will compile as a DLL but you still need an EXE
to make an instance of those classes and use them.
 
Where to begin?

Java is no more a scripting language than C# is.

Please don't get Javascript (SCRIPT) confused with Java (VM COMPILED, just
like C#). It leads to endless misinformation.

Stephen said:
One of the advantages of .NET over a scripted language like Java is the fact
that it's compiled. Why wouldn't you just compile it? How is it so much
trouble to 'create separate projects and build them into executables'? If
you are trying to run a DLL file, guess what? It's compiled. So if you
want to actually EXECUTE something, it would make a hell of a lot more sense
to compile it into an EXE not a DLL. If what you want to do (like make a
class library) then yes it will compile as a DLL but you still need an EXE
to make an instance of those classes and use them.

Robert Dobson said:
I'm currently looking to port a Java project to .Net and
one thing I've not yet figured out is if you can run .Net
classes from the command line without going through all
the trouble of creating separate projects and building
them into executables.

In java you can just type "java.exe mypackage.MyClass" and
it runs as long as there is a "public static void main
(String[])" method in the class.

I realized in .Net the class is inside a DLL so the syntax
might be trickier, like "dotnet.exe my.dll
mypackage.MyClass" or some such.

Thanks.
 
Back
Top