question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OnlyIf token replacement doesn't work.

See original GitHub issue

Product

dotnet CLI (dotnet new)

Describe The Bug

I’m writing up a template and it seems like “onlyIf” doesn’t actually do anything.

I’m creating a default template for a hosted Project in our company, and I have the project with a port of “12345”

So I have a json file that looks like this:

  "hostingManifest": {
    "defaultPort": 12345,
    "isPublic": false
  }
}

The number 12345 appears in multiple places.

So I have the following replacements in my template config:

       "default-port": {
            "type": "parameter",
            "datatype":"int",
            "description": "The default port number. If not provided, a new random port will be found.",
            "defaultValue": "0"
        },
        "GeneratedPort": {
            "type": "generated",
            "generator": "port",
            "datatype": "int"
        },
        "OverrideDefaultPort": {
            "type": "generated",
            "generator": "coalesce",
            "parameters": {
                "sourceVariableName": "default-port",
                "fallbackVariableName": "GeneratedPort"
            },
            "replaces": "12345",
            "onlyIf": {
                "after": "defaultPort",
                "before": "}"
            }
        },

and it doesn’t work. every instance of 12345 is replaced instead of just this one instance of 12345.

I also tested it with a bunch of junk.

            "onlyIf": {
                "after": "kjhsdfhjsdf",
                "before": "asdfljksdfljk"
            }

and found that it replaces all instances of 12345 too.

It’s especially problematic when it replaces every instance of “false” because I’m trying to configure “isPublic”. I’ve resorted to having to add like 3 new symbols and a bunch of templated code to do an explicit find and replace of something like "MySuperUniqueDescriptor": 0,\r\n "defaultPort": 12345 and replace it with a generated join between constant symbol and ref symbol.

To Reproduce

Steps:

  1. Create a template that has multiple instances of some text, like 12345, for instance, or false.
  2. Add a symbol to it that’s optional for a user.
  3. Add a fallback symbol that’s constant or generated.
  4. Add a coalesce symbol to pick out the preferred of the two.
  5. In the coalesce symbol, add a “replaces”, and fill out the “onlyIf” information, so you can target only one specific instance of that text.
  6. Pack the template.
  7. Install the template
  8. Create a new project with that template

Expected: I expect my one instance of text has been replaced.

Actual: Every instance of that text will have been replaced.

dotnet Info

.NET SDK: Version: 7.0.203 Commit: 5b005c19f5

Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.203\

Host: Version: 7.0.5 Architecture: x64 Commit: 8042d61b17

.NET SDKs installed: 6.0.408 [C:\Program Files\dotnet\sdk] 7.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Visual Studio Version

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
EdLichtmancommented, May 3, 2023

Not only am I unblocked, I was able to reduce the rules by like 5. It’s a lot more convenient.

0reactions
YuliiaKovalovacommented, May 10, 2023

The issue was addressed for .NET 8.

Read more comments on GitHub >

github_iconTop Results From Across the Web

9 - Custom token not being replaced - Drupal Answers
Token replacement is on node save, not when it's rendered. Calling token replace in hook_node_presave did it.
Read more >
java - Replace token in file before building, but keep ...
You only need to replace @VERSION@ tokens before releasing your software to the public. Here I defined a task compileForRelease that ...
Read more >
Fix token system confusion, with new function Token
The token result is the entered HTML text with tokens replaced. The caller is responsible for choosing the right escaping / sanitization. That ......
Read more >
Various issues with refresh token rotation #3940
I'm following the suggested setup to refresh tokens https://next-auth.js.org/tutorials/refresh-token-rotation which works fine.
Read more >
Various issues with refresh token rotation #2071
I'm following the suggested setup to refresh tokens https://next-auth.js.org/tutorials/refresh-token-rotation which works fine.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found