3

I have a number of tools that are more like scripts that full-fledged programs and in the olden days I would simply call the csc.exe compiler and throw the program.cs in there like this:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe
  /out:NasPath.exe
  /target:exe
  /optimize+
  /debug-
  /platform:x64
  NasPath.cs

I'm pretty certain that .net 4.8.1 will be around on Windows for quite some time but for my learning journey I was curious if there's a simple way to compile such a C# file in net7.0 or if I always need at least a .csproj file for that.

Dee J. Doena
  • 1,631
  • 3
  • 16
  • 26

1 Answers1

0

If you're asking whether the dotnet tool is capable of compiling single Program.cs file into an executable - bypassing the creation of the .csproj file - then the answer is probably no? - I haven't found a way to do that.

On the other hand, the .NET 7.0's .csproj file size can be very small, and even can be created-and-deleted-afterwards from within your scripts:

echo ^<Project Sdk=^"Microsoft.NET.Sdk^"^>^<PropertyGroup^>^<OutputType^>Exe^</OutputType^>^<TargetFramework^>net7.0^</TargetFramework^>^</PropertyGroup^>^</Project^> > MyApp.csproj
"C:\Program Files\dotnet\dotnet.exe" build .
DEL MyApp.csproj
AgentFire
  • 8,944
  • 8
  • 43
  • 90