3

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?

5
  • 3
    dotnet build Commented May 31, 2021 at 22:24
  • Have you looked through the docs you linked to? There's a "Hello World" example that spells it out: learn.microsoft.com/en-us/dotnet/core/get-started and learn.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli Commented Jun 1, 2021 at 0: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 stackoverflow.com/a/47697996/569976... Commented Jun 2, 2021 at 2:24
  • Maybe this can help? Commented Jun 2, 2021 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 Commented Jun 2, 2021 at 15:43

1 Answer 1

3

Depending on what your goal is:

  • dotnet run - This will build and run your application directly
  • dotnet test - This will build everything and run your unit tests
  • dotnet publish - This will build your application for deployment
  • dotnet 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 want dotnet publish instead.
Sign up to request clarification or add additional context in comments.

2 Comments

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...
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.