With mono you'd compile and run C# code by doing csc test.cs && mono test.exe. How would you do it with the official .NET SDK on Ubuntu?
1 Answer
Depending on what your goal is:
dotnet run- This will build and run your application directlydotnet test- This will build everything and run your unit testsdotnet publish- This will build your application for deploymentdotnet build- This will build your application (for development only). Generally, you don' want to use this: one of the others on this list will be a better way to do what you want. If you want to share this with users, you wantdotnet publishinstead.
2 Comments
neubert
When I try
dotnet build test.cs I get /home/neubert/test.cs(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.. I guess compiling individual *.cs files isn't possible with dotnet per stackoverflow.com/a/47697996/569976. Oh well...omajid
The recent versions of .NET don't support compiling/running single files. They expect you to be using a project. There's currently an active proposal for enabling single file programs that you can execute directly - similar to running a shell script - but that's just in the design phase right now.
dotnet builddotnet build test.csI get/home/neubert/test.cs(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.. I guess compiling individual *.cs files isn't possible with dotnet per stackoverflow.com/a/47697996/569976...csc test.csisn't anywhere close. I can memorizecsc filename.ext- I'm not going to memorize that other one. I suppose I could alias it but idk that feels like too much effort lol