Skip to content

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Sep 24, 2025

The current logic has few unfortunate pieces:

  • All directories down are searched for the requested json file. This doesn't make sense for our usages in test templates that needs to update/create global.json. To preserve compatibility, a flag is added instead of breaking the existing behavior. This is controlled now by includeAllDirectoriesInSearch.
  • Only one level up is currently searched. This is again an unfortunate behavior. This is controlled now by includeAllParentDirectoriesInSearch.
  • The logic that goes "up" in the directories is updated to not go further than the detected repo root (when detect repo root option is enabled, thus, the option is renamed. Note that the option is already new in .NET 10 RC2 so the rename isn't problematic)

Additionally:

  • A code path where the post action fails doesn't log any errors. Added PostAction_ModifyJson_Error_NullJson for this case.
  • Fix a small bug if allowPathCreationArgument isn't parse-able as boolean.

The test templates for MSTest are now updated to use the logic that we think is correct regarding how to search the directories for global.json.

Notes:

  1. We still keep the original behavior as the "default" behavior to avoid risking breaking people relying on the original behavior.
  2. One additional pain point of the original behavior (which is still kept) is when enumerating all sub directories, then nothing is found, then we look up one level up again and enumerate all sub directories, this is duplicate work for enumerating.
  3. As for test templates, we don't need to look down into sub-directories at all. The idea of this PR is to add template options so that it becomes generic enough for various needs. If a configuration file needs to be looked down, this is available (and remains the default), but otherwise (e.g, for looking global.json), templates can choose to only look in parent directories. etc.

Doc PR: dotnet/templating#9375

@Youssef1313 Youssef1313 merged commit b62cacf into release/10.0.1xx Sep 26, 2025
28 checks passed
@Youssef1313 Youssef1313 deleted the dev/ygerges/json-postaction branch September 26, 2025 08:08
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.

2 participants