{"record":{"id":"81efe18dc5fe9e32","repo":"clockworklabs/SpacetimeDB","slug":"invalid-c-template-missing-net8-0-net10-0-target","errorCode":null,"errorMessage":"Invalid C# template: missing net8.0/net10.0 TargetFrameworks property","messagePattern":"Invalid C# template: missing net8\\.0/net10\\.0 TargetFrameworks property","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/init.rs","lineNumber":1891,"sourceCode":"        _ => unreachable!(\"unsupported .NET version should have been validated before init\"),\n    }\n}\n\nfn csharp_csproj_for_target(content: &str, dotnet_major: u8) -> anyhow::Result<String> {\n    let target_framework = match dotnet_major {\n        8 => \"net8.0\",\n        10 => \"net10.0\",\n        _ => unreachable!(\"unsupported .NET version should have been validated before init\"),\n    };\n    let target_framework_property = format!(\"<TargetFramework>{target_framework}</TargetFramework>\");\n    if content.contains(\"<TargetFrameworks>net8.0;net10.0</TargetFrameworks>\") {\n        return Ok(content.replace(\n            \"<TargetFrameworks>net8.0;net10.0</TargetFrameworks>\",\n            &target_framework_property,\n        ));\n    }\n\n    anyhow::bail!(\"Invalid C# template: missing net8.0/net10.0 TargetFrameworks property\")\n}\n\nfn configure_csharp_project_files(project_path: &Path, dotnet_major: u8) -> anyhow::Result<()> {\n    let global_json_path = project_path.join(\"global.json\");\n    std::fs::write(&global_json_path, csharp_global_json(dotnet_major))?;\n\n    let csproj_path = project_path.join(\"StdbModule.csproj\");\n    let csproj = std::fs::read_to_string(&csproj_path)?;\n    std::fs::write(&csproj_path, csharp_csproj_for_target(&csproj, dotnet_major)?)?;\n\n    Ok(())\n}\n\nfn csproj_has_package_reference(content: &str, include: &str, version: &str) -> bool {\n    fn element_has_package_reference(element: &xmltree::Element, include: &str, version: &str) -> bool {\n        if element.name == \"PackageReference\"\n            && element.attributes.get(\"Include\").map(String::as_str) == Some(include)\n            && element.attributes.get(\"Version\").map(String::as_str) == Some(version)","sourceCodeStart":1873,"sourceCodeEnd":1909,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/fdd647dfac506d0967cc4492e9fce380706c94cb/crates/cli/src/subcommands/init.rs#L1873-L1909","documentation":"While pinning the .NET version, the CLI rewrites the csproj by finding the exact marker `<TargetFrameworks>net8.0;net10.0</TargetFrameworks>` and replacing it with a single `<TargetFramework>net8.0|net10.0</TargetFramework>`. If the embedded C# template's csproj no longer contains that marker (template drift, tampered install, or a modified template in a fork), rewriting fails and init aborts.","triggerScenarios":"Using --lang csharp with --dotnet-version on a CLI whose embedded template csproj changed shape; forked CLI with edited templates; partially updated install.","commonSituations":"Template refactors between CLI versions; custom forks that restyle the csproj; corrupted installation.","solutions":["Update/reinstall the official CLI so embedded templates match the rewrite logic","Falling back to the default (no --dotnet-version) lets generation proceed with the multi-target csproj","If building from source, restore the marker in templates or update the matcher, then rebuild","Report as a bug if reproducible on an official release"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a stable official CLI release instead of custom builds for day-to-day init","Fork maintainers: keep the net8.0;net10.0 TargetFrameworks marker intact when editing templates"],"tags":["spacetime-init","csharp","dotnet","template","csproj"],"backgroundTag":"template-content-mismatch","analyzedSha":"fdd647dfac506d0967cc4492e9fce380706c94cb","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}