clockworklabs/SpacetimeDB · error · anyhow::Error

--dotnet-version is only supported for C# projects (--lang c

Error message

--dotnet-version is only supported for C# projects (--lang csharp)

What it means

The `--dotnet-version` init flag targets the C# server template's .NET SDK major version and nothing else. init rejects the combination when the flag is set but the resolved server language is not C# — including templates that have no server module at all (server_lang of None). For C# projects the flag is otherwise optional; the CLI picks a default SDK when it's absent.

Source

Thrown at crates/cli/src/subcommands/init.rs:556

        config.spacetimedb_token().is_none()
    };

    let is_server_only = options.server_only;

    let project_name = get_project_name(options, is_interactive).await?;
    let project_path = get_project_path(options, &project_name, is_interactive, is_server_only).await?;
    let local_database_name = get_local_database_name(options, &project_name, is_interactive)?;

    let mut template_config = if is_interactive {
        get_template_config_interactive(options, project_name, project_path.clone()).await?
    } else {
        get_template_config_non_interactive(options, project_name, project_path.clone()).await?
    };

    template_config.use_local = use_local;

    if options.dotnet_version.is_some() && template_config.server_lang != Some(ServerLanguage::Csharp) {
        anyhow::bail!("--dotnet-version is only supported for C# projects (--lang csharp)");
    }

    // For C# projects, resolve the target .NET version before scaffolding.
    let dotnet_major = if template_config.server_lang == Some(ServerLanguage::Csharp) {
        let dotnet_major = options.dotnet_version.unwrap_or_else(resolve_default_dotnet_major);
        println!("Targeting .NET SDK {dotnet_major}.");
        Some(dotnet_major)
    } else {
        None
    };

    ensure_empty_directory(
        &template_config.project_name,
        &template_config.project_path,
        is_server_only,
    )?;
    init_from_template(
        &template_config,

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Remove `--dotnet-version` from the invocation
  2. Add `--lang csharp` (or pick a C# template) if you really want to pin the SDK
  3. For C#, omit the flag entirely and let init resolve the default .NET SDK

Example fix

# before
spacetime init my-app --non-interactive --project-name my-app --lang rust --dotnet-version 8

# after
spacetime init my-app --non-interactive --project-name my-app --lang rust

# after (C# with pinned SDK)
spacetime init my-app --non-interactive --project-name my-app --lang csharp --dotnet-version 8
Defensive patterns

Strategy: validation

Validate before calling

# Only forward --dotnet-version for csharp server stacks:
DOTNET_ARGS=()
if [[ -n "$DOTNET_VERSION" ]]; then
  case "${LANG_ARG,,}" in
    csharp|c#) DOTNET_ARGS=(--dotnet-version "$DOTNET_VERSION") ;;
    *) echo "skipping --dotnet-version: lang=${LANG_ARG:-<template default>} is not csharp" >&2 ;;
  esac
fi
spacetime init --non-interactive --project-name my-app --lang "$LANG_ARG" "${DOTNET_ARGS[@]}"

Prevention

When it happens

Trigger: `spacetime init my-app --lang rust --dotnet-version 8`; `--dotnet-version` combined with a `--template` whose stack is not C#; keeping the flag from a C# quickstart while switching languages.

Common situations: Copy-pasted flag sets from C# docs; iterating over languages in a scaffold script; template choices that changed after the flag was added to a command.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/b1392147d92be6f3. Report an issue: GitHub.