I am coming from Go language and wanted to know if it's possible to add build flags that assign values to variables at build time. For example, in Go we can do something like
// main.go
package main
import "fmt"
var world = ""
func main() {
fmt.Println("Hello,", world)
}
And using go build -ldflags "-X main.world=world" main.go
will output Hello, world
. Is there something like this that can be done in C# when using dontnet build
or dotnet publish
?
What I wanted to do was, have an endpoint in ASP.Net Core that would print out the version number and SHA code. But I want them to come in at build time. I could probably use the appsettings.json
but I am not sure if that's the right way or not.