OnlyIf token replacement doesn't work.
See original GitHub issueProduct
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:
- Create a template that has multiple instances of some text, like 12345, for instance, or false.
- Add a symbol to it that’s optional for a user.
- Add a fallback symbol that’s constant or generated.
- Add a coalesce symbol to pick out the preferred of the two.
- In the coalesce symbol, add a “replaces”, and fill out the “onlyIf” information, so you can target only one specific instance of that text.
- Pack the template.
- Install the template
- 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:
- Created 5 months ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Not only am I unblocked, I was able to reduce the rules by like 5. It’s a lot more convenient.
The issue was addressed for .NET 8.