Make it possible to invoke the compiler directly
See original GitHub issueNot 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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:25
- Comments:25 (15 by maintainers)
Top GitHub Comments
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?My personal goal is to make it possible to use
dotnet build
anddotnet 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 saydotnet csc hello-world.cs
.The reason for using
dotnet build / run
vsdotnet 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: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 intypeof(object).Assembly.Loctation
csc /t:exe example.cs
and then immediately just runexample.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 usecsc.
. The logic for those steps are insidedotnet 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.