Quickstart: Hello, G#
Run a small program, understand its parts, then make a change. If you have not installed G# yet, follow the installation guide first.
The program
Replace your project's Program.gs with the checked-in samples/HelloWorld.gs example:
// file: HelloWorld.gs
package HelloWorld
import System
Console.WriteLine("Hello, world!")
There are three ideas here:
package HelloWorldgives the source a package identity.import Systembrings a .NET namespace into scope.Console.WriteLinecalls the familiar .NET console API. Top-level statements become the executable entry point, so you do not need to declareMain.
Run it with the SDK
From the project directory:
dotnet run
Expected output:
Hello, world!
Change the message and run it again. dotnet run builds the project when needed; a separate dotnet build is useful when you want to compile without executing.
Next: follow the Tour's basics chapter, or build a small data model.
Run it with gsc directly
The SDK is the recommended project workflow. If you are working with a source-built compiler, you can also execute the sample directly:
dotnet path/to/gsc.dll samples/HelloWorld.gs
The compiler prints:
Hello, world!
Success.
Use /out when you want an assembly rather than immediate execution:
dotnet path/to/gsc.dll samples/HelloWorld.gs /out:artifacts/HelloWorld.dll /target:exe /tfm:net10.0
dotnet artifacts/HelloWorld.dll
The saved program prints Hello, world! without the compiler's Success. line. See the compiler reference for advanced invocation options.