Skip to content

Issue: XML Conditional Processing Not Working in .slnx Files #8784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
StevenTCramer opened this issue Mar 2, 2025 · 3 comments
Open

Issue: XML Conditional Processing Not Working in .slnx Files #8784

StevenTCramer opened this issue Mar 2, 2025 · 3 comments

Comments

@StevenTCramer
Copy link

Is your feature request related to a problem? Please describe.

Issue: XML Conditional Processing Not Working in .slnx Files

Problem Description

I'm trying to use XML conditional processing format in a .slnx file within a .NET template, but it doesn't work as expected. Since .slnx files are XML-based, I expected the standard XML conditional processing syntax to work, but it seems the templating engine doesn't recognize .slnx files as XML for conditional processing purposes.

Steps to Reproduce

  1. Create a .NET template with a .slnx file
  2. Add conditional processing directives to the .slnx file using XML comment syntax:
    <!--#if (api)-->
    <Folder Name="/05-ContainerApps/Api/">
      <!-- Projects inside this folder -->
    </Folder>
    <!--#endif-->
  3. Generate a project from the template with the condition set to false (e.g., --api false)
  4. Observe that the conditional sections are not processed correctly - the comment directives are included in the output file, but the content between them is not excluded

Expected Behavior

When generating a project with --api false, the entire section (including the conditional directives and the content between them) should be excluded from the generated .slnx file.

Actual Behavior

The conditional directives (<!--#if (api)--> and <!--#endif-->) are included in the output file as literal text, and the content between them is also included regardless of the condition value.

Environment

  • .NET SDK version: 9.0.200
  • OS: Windows 11 Pro

Additional Context

The .slnx file format is relatively new and appears to be an XML-based solution file format. Since it's XML-based, I expected it to work with the standard XML conditional processing syntax as described in the documentation: https://github.com/dotnet/templating/wiki/Conditional-processing-and-comment-syntax#xml-based-formats

I believe this issue occurs because the .slnx extension is not mapped to XML for conditional processing purposes in the templating engine.

Possible Solution

The templating engine could be updated to recognize .slnx files as XML-based files for conditional processing purposes, similar to how it handles .csproj, .vbproj, and other XML-based files.

Alternatively, if there's a different recommended approach for handling conditional content in .slnx files, documentation on this would be helpful.

Describe the solution you'd like.

The templating engine could be updated to recognize .slnx files as XML-based files for conditional processing purposes, similar to how it handles .csproj, .vbproj, and other XML-based files.

Additional context

No response

@baronfel
Copy link
Member

baronfel commented Mar 2, 2025

This seems entirely reasonable to me - would you be willing to make a contribution?

@StevenTCramer
Copy link
Author

This seems entirely reasonable to me - would you be willing to make a contribution?

Yes I am willing. Will give it a try on the weekend to see if I can find it. Then report back.

@karl-sjogren
Copy link
Contributor

A fix for this has been merged to main but for a work around until the fix is released you can use this SpecialCustomOperation in your template.

{
  "$schema": "http://json.schemastore.org/template",
  "SpecialCustomOperations": {
    "**.slnx": {
      "operations": [
        {
          "type": "conditional",
          "configuration": {
            "actionableIf": [ "<!--#if" ],
            "actionableElse": [ "#else", "<!--#else" ],
            "actionableElseif": [ "#elseif", "<!--#elseif", "#elif", "<!--#elif" ],
            "endif": [ "#endif", "<!--#endif" ],
            "trim" : "true",
            "wholeLine": "true",
            "evaluator": "C++"
          }
        },
        {
          "type": "balancednesting",
          "configuration": {
            "startToken": "<!--",
            "realEndToken": "-->",
            "pseudoEndToken": "-- >",
            "id": "fixPseudoNestedComments",
            "resetFlag": "_TestResetFlag_"
          }
        }
      ]
    }
  }
}

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

No branches or pull requests

3 participants