Skip to content

Add --allow-prerelease and --no-sdk-version options to dotnet new globaljson template#54133

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-allow-prerelease-option
Draft

Add --allow-prerelease and --no-sdk-version options to dotnet new globaljson template#54133
Copilot wants to merge 4 commits intomainfrom
copilot/add-allow-prerelease-option

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

dotnet new globaljson had no way to set allowPrerelease in the generated global.json, requiring users to manually look up the field name and add it by hand. Additionally, the template always included an SDK version, preventing users from creating a minimal global.json with only allowPrerelease set.

Template changes

  • Added AllowPrerelease choice parameter ("true" / "false") to template.json with defaultValue: "" (omitted from output when unspecified — fully backward compatible) and defaultIfOptionWithoutValue: "true"
  • Added NoSdkVersion bool parameter to template.json with defaultValue: "false" — when set, the SDK version is omitted from the generated global.json
  • Mapped to --allow-prerelease and --no-sdk-version CLI options in dotnetcli.host.json
  • Restructured template conditionals to handle JSON trailing-comma validity across all combinations of the three optional fields (rollForward, allowPrerelease, version)
  • Updated all 14 localization files with English placeholder strings for both new parameters

Usage

# Suppress prerelease SDKs with a specific version
dotnet new globaljson --allow-prerelease false

# Suppress prerelease SDKs without specifying a version (primary use case)
dotnet new globaljson --allow-prerelease false --no-sdk-version

# Explicit flag without value defaults to true
dotnet new globaljson --allow-prerelease

Output for --allow-prerelease false:

{
  "sdk": {
    "allowPrerelease": false,
    "version": "9.0.100"
  }
}

Output for --allow-prerelease false --no-sdk-version:

{
  "sdk": {
    "allowPrerelease": false
  }
}

Tests

  • Added 5 new AllCommonItemsCreate test cases covering --allow-prerelease false, --allow-prerelease true, combined with --sdk-version, --no-sdk-version alone, and --allow-prerelease false --no-sdk-version
  • Added corresponding approval snapshot files
  • Updated globaljson help text snapshot to include both new options

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/3a08d95c-8aa4-40b3-827d-65843a267b72

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
@Mrxx99
Copy link
Copy Markdown
Contributor

Mrxx99 commented Apr 29, 2026

Why does file generated with
dotnet new globaljson --allow-prerelease false
include the SDK version? My use case was to just specify allow prerelease false without SDK version because I wanted to be on the latest SDK that is not prerelease. I know I can just remove the SDK version after creation, but the intention for the issue #32500 (that I created) was just avoiding prereleas

@marcpopMSFT
Copy link
Copy Markdown
Member

Hmm, I missed in the original request that you didn't even want an sdk value. The current behavior includes a default value for that. We could add a --no-sdk flag but then that would have to have error checking with --sdk-version. I'm not sure we'd want --sdk-version without a value to do that as that's most likely a typo (as I expect this to be the less common scenario). We could allow --sdk-version false and somehow make that not provide a version but that's a bit odd as version expects a version.

@baronfel any thoughts on a direction to go to have allow-prerelease with no version?

@baronfel
Copy link
Copy Markdown
Member

baronfel commented May 4, 2026

A --no-sdk-version could be a bit more explicit here, and it would make the conditions a bit easier to write since we have a constrained condition language in the templates.

@marcpopMSFT
Copy link
Copy Markdown
Member

@copilot can we add a --no-sdk-version option that won't include the SDK version as there is a scenario where a customer might want all-prerelease of false but not specify a version.

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/bb7321e2-df28-4dc1-8781-6a48f9437b42

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot can we add a --no-sdk-version option that won't include the SDK version as there is a scenario where a customer might want all-prerelease of false but not specify a version.

Added --no-sdk-version in commit f08d4fa. When specified, the SDK version is omitted from the generated global.json, enabling the primary use case:

dotnet new globaljson --allow-prerelease false --no-sdk-version

Output:

{
  "sdk": {
    "allowPrerelease": false
  }
}

The template conditional logic handles all combinations of --roll-forward, --allow-prerelease, and --no-sdk-version while maintaining valid JSON (no trailing commas).

Copilot AI changed the title Add --allow-prerelease option to dotnet new globaljson template Add --allow-prerelease and --no-sdk-version options to dotnet new globaljson template May 5, 2026
@marcpopMSFT
Copy link
Copy Markdown
Member

@copilot when i'm testing this, I end up with an error creating the global.json and it ends halfway through.

/workspaces/test $ dotnet new globaljson --allow-prerelease false
Template "global.json file" could not be created.
Failed to create template.
Details: Error while processing file /content/GlobalJson/global.json
Unable to cast object of type 'System.String' to type 'System.Boolean'.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 6, 2026

@copilot when i'm testing this, I end up with an error creating the global.json and it ends halfway through.

...

Fixed in commit 4d1ae57. The root cause was that the template engine's And operator uses a direct C# (bool)x cast, which fails when a bool-typed parameter value is stored as the string "false". The fix changes NoSdkVersion from datatype: "bool" to datatype: "choice" (consistent with the other optional parameters AllowPrerelease, RollForward, and TestRunner), and updates all conditions to use string equality comparisons (NoSdkVersion=="" / NoSdkVersion!="") which are safe regardless of the underlying storage type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet new globaljson should have allowPrerelease option

4 participants