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?
Asked
Active
Viewed 1,253 times
2

neubert
- 15,947
- 24
- 120
- 212
-
3[`dotnet build`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build) – Guru Stron May 31 '21 at 22:24
-
Have you looked through the docs you linked to? There's a "Hello World" example that spells it out: https://learn.microsoft.com/en-us/dotnet/core/get-started and https://learn.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli – omajid Jun 01 '21 at 00:01
-
@GuruStron - 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 https://stackoverflow.com/a/47697996/569976... – neubert Jun 02 '21 at 02:24
-
Maybe [this](https://stackoverflow.com/a/47697996/2501279) can help? – Guru Stron Jun 02 '21 at 13:02
-
@GuruStron - yah - that was in the link I posted. But the proposed remediation is ~300 bytes long whereas `csc test.cs` isn't anywhere close. I can memorize `csc 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 – neubert Jun 02 '21 at 15:43
1 Answers
2
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 publish
instead.

omajid
- 14,165
- 4
- 47
- 64
-
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 https://stackoverflow.com/a/47697996/569976. Oh well... – neubert Jun 02 '21 at 02:25
-
1The 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](https://github.com/dotnet/designs/pull/213/files) 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. – omajid Jun 02 '21 at 14:33