question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it possible to invoke the compiler directly

See original GitHub issue

Not sure whether this belongs in the SDK repo instead.

In the desktop world, most people build with MSBuild on the command line or in VS. But for quick experimentation, learning c#, or custom scripts, one can invoke csc.exe directly. This has the advantage of being very fast, and not needing a project file. In that situation csc adds some default references so you simply run csc Program.cs. It is implicit that you are getting no help resolving references, so this is not a good way to make shipping software, unless you really want something custom and know what you’re doing. When you are done experimenting, you should make a project file. This scenario has worked well since .NET Framework v1.

Can we support this scenario for .NET Core? This would be a supported shortcut for dotnet C:\Program Files\dotnet\sdk\...version..\Roslyn\csc that would also add some basic default references.

cc @ViktorHofer @stephentoub

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:25
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

5reactions
sebgodcommented, Aug 23, 2020

if .NET 5 is considered a replacement for both .NET framework and core, shouldn’t it also expose a proper csc (e.g. via something called dotnet-csc) that allows compiling .cs from the command line, in a portable fashion?

4reactions
jaredparcommented, Aug 23, 2020

My personal goal is to make it possible to use dotnet build and dotnet run for .cs files without needing an explicit project file. That is very different though than allowing direct invocation of the compiler in the form of say dotnet csc hello-world.cs.

The reason for using dotnet build / run vs dotnet csc for a single file application is because at a fundamental level building and running for .NET Framework and .NET Core are very different problem spaces. In .NET Framework there are the following advantages:

  1. While reference assemblies exist, there is really no meaningful difference in compiling against reference vs. implementation assemblies.
  2. Because of (1) above there is no need to every “find the reference assemblies”. When you run csc example.cs on .NET Desktop we can find all of the default references by using the default csc.rsp file and resolving all of the assemblies in typeof(object).Assembly.Loctation
  3. There really isn’t a deployment step to speak of which means you can easily csc /t:exe example.cs and then immediately just run example.exe.

That is why for .NET Framework using csc as the single tool for building is very approachable. For .NET Core though it’s really not that generally useful for customers because they need to solve all of the above problems to successfully use csc.. The logic for those steps are inside dotnet build / run hence that is what I envision us leveraging for the single *.cs file scenarios.

That being said: I would like to make dotnet csc as usable on .NET Core as it is on .NET Framework for the act of compiling. If for nothing else than because it’s how the Roslyn team does a lot of it’s own work 😉. But I don’t think it will be a tool that a ton of customers end up finding that useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make it possible to invoke the compiler directly · Issue #8742
My personal goal is to make it possible to use dotnet build and dotnet run for .cs files without needing an explicit project...
Read more >
Can a compiler produce an executable file directly by itself?
It depends on how you define “compiler” and “itself.” You could write a compiler that, when given no input, creates an executable file...
Read more >
How does code work without getting compiled or interpreted?
Compilers aren't magic - they're just programs, which can be run from the command line. Visual Studio Code has a "Terminal" tab in...
Read more >
Can GCC compile and run a source code without ...
Can GCC compile and run a source code without generating any output file (neither object nor executable), in a manner that is supported...
Read more >
GCC and Make - A Tutorial on how to compile, link ...
You need to use g++ to compile C++ program, as follows. We use the -o option to specify the output file name. //...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found