.NET
How Anvil runs .NET projects with dotnet run, installs .NET SDKs side by side and keeps NuGet's packages in its own folder.
What Anvil detects
A folder with a .csproj, .fsproj or .sln at its top. PHP, Rust and Go
are recognized first; see the detection table.
Anvil runs dotnet run --urls http://127.0.0.1:$PORT on a private port and
proxies <name>.test to it.
Installing .NET
Settings › Languages › .NET › Install, or with the channel:
anvil runtime install dotnet 10.0Channels: 10.0, 9.0, 8.0. Anvil downloads the channel's newest SDK from Microsoft, checked against the SHA-512 in Microsoft's release list.
All SDKs go side by side into ~/.anvil/runtimes/dotnet (sdk/<version>,
runtimes in shared/). Installing a channel adds only what's missing. The
dotnet program comes from the newest channel installed.
Choosing the version
Anvil doesn't pin .NET; the Settings tab has no version setting. dotnet
picks an SDK from global.json (with its rollForward), else the newest
installed. If no installed SDK fits, the application's log shows a
"compatible .NET SDK was not found" error; install the channel in
Settings › Languages › .NET or with
anvil runtime install dotnet <channel>, then start again.
anvil app runtime refuses a .NET application: ".NET picks its SDK from the
project's global.json; Anvil doesn't pin it". A .NET pin saved by an older
Anvil is ignored. See Microsoft's
Select the .NET version to use.
Running an application
The server doesn't start on its own: Start in the Dev tab, or
anvil app start myapi while the desktop app is open (this also starts dev
processes marked Dev start). To start it with Anvil, turn on Start with
Anvil in Settings or run anvil app autostart myapi true (off by default;
with the CLI alone, restart anvil start). It runs until stopped or Anvil
quits; while stopped, <name>.test shows a "not running" page.
Start command and port: Start command and Port in Settings, or:
anvil app command myapi 'dotnet watch run --urls http://127.0.0.1:$PORT'
anvil app port myapi 41500No value resets to the default. The automatic port is derived from the name, in 41000–44999, moving up on collision.
| Variable | Value |
|---|---|
PORT | The application's private port |
ASPNETCORE_URLS | http://127.0.0.1:<port> |
HOST, HOSTNAME | 127.0.0.1 |
DOTNET_ROOT | ~/.anvil/runtimes/dotnet |
DOTNET_CLI_HOME | ~/.anvil/cache/dotnet |
NUGET_PACKAGES | ~/.anvil/cache/nuget |
DOTNET_CLI_TELEMETRY_OPTOUT, DOTNET_NOLOGO | 1 |
PATH | ~/.anvil/runtimes/dotnet first |
In your terminal
No dotnet terminal command. Anvil's is ~/.anvil/runtimes/dotnet/dotnet;
set the variables above to use Anvil's caches.
Caches and files
CLI first-run files go to ~/.anvil/cache/dotnet, NuGet packages to
~/.anvil/cache/nuget; ~/.dotnet and ~/.nuget are untouched. The
project's bin and obj show as rebuildable in
Storage. Anvil writes nothing else into a .NET
project.
New applications
anvil new dotnet myapiOr New… (⌘N) in the app, under Other. Needs .NET installed. Runs
dotnet new web -o <name>. Takes --git/--no-git and
--https/--no-https; see
New applications.
Differences from production
dotnet runuses the Debug configuration.- CLI telemetry and the first-run logo are off.
Removing a version
Hover the version in Settings › Languages › .NET and click Uninstall,
or anvil runtime uninstall dotnet 9.0. This deletes that channel's SDK
folders (sdk/9.0.*); its runtimes in shared/ and the dotnet program
stay. Nothing blocks it; a project whose global.json needs a removed SDK
fails to start with dotnet's error until you reinstall the channel.