Internally, Dafny's .NET compiler generates C# code that it calls the C# compiler to turn into an executable .NET program (or a .dll). You ask Dafny to output this C# program. That's done using the command-line switch /spillTargetCode:1
. In comments at the top of the generated C# program, you'll see what command-line switches to pass to the C# compiler to compile that C# program directly.
If you just want to run your Dafny program, there's no need to ever look at the C# code. Either just invoke Dafny with /compile:1
(which is the default) and then run the resulting .exe file, or invoke Dafny with /compile:3
to verify, compile, and run your program.
I've described these options as if you're running Dafny from the command line. There's also some way to add these command-line switches in the Settings for Dafny in VS Code.
If you want to interface your Dafny other C# code, you can use the {:extern}
attribute on Dafny methods and other Dafny declarations. If do you that, then simply add your own .cs files on the command line when invoking Dafny. For examples, search for "extern
" in the files in Dafny's test suite.
A recent addition to Dafny (so recent it isn't yet available in the binary release of Dafny, but you can get it right away if you build Dafny from source yourself) are compilers for JavaScript and Go. Select these compilers with the command-line switch /compileTarget
.
Rustan