dotnet / dotnet/templating

Modifiers "include" is not working as expected in dotnet 8

Open
#8,003 0 comments 0 reactions 0 assignees View on GitHub
triage:transfer-to-sdk
Dominant language
No language data
Stars
1.7k
Forks
399
Avg merge
3d 5h
Merged PRs (30d)
39

Description

### Product

dotnet CLI (dotnet new)

### Describe The Bug

Given the template sources configuration for a custom template below:
```JSON
....
"sources": [
{
"include": [],
"modifiers": [
{
"condition": "(!someBoolParam)",
"include": [
"**/*"
],
"exclude": [
".fake/**",
".paket/**",
"paket-files/**",
"..."
]
},
{
"condition": "(someBoolParam)",
"include": [
"src/Folder/SubFolder/**/*"
],
"exclude": ["Dockerfile"]
}
]
}
]
....
```

And Given the fact that the directory was already initiated from the template (`someBoolParam == false`)
When the `dotnet new` is executed in the **existing** directory where `someBoolParam == true`,
Then the "include" condition (i.e. "src/Folder/SubFolder/**/*") is ignored and all files in the directory are getting updated except for the excluded file (i.e. "Dockerfile"). Note: "exclude" was added to the example below just to show that "exclude" is working, but "include" is not. If "exclude" is removed, the "include" still does not work.

An example of the warning message displayed in the console:
```
Creating this template will make changes to existing files:
Overwrite ./.dockerignore
Overwrite ./.editorconfig
Overwrite ./.gitattributes
Overwrite ./.gitignore
.............................................
To create the template anyway, run the command with '--force' option:
............................................
```

Such template config **worked as expected** when using **.NET 6** SDK, but **after the update to .NET 8**, **the issue** described above **is started to appear**.

### To Reproduce

Steps:
1. Configure the template using sources from the description
2. Install template
3. Create a service from a template with someBoolParam set to false
4. Create a service from the template again with someBoolParam set to true

### dotnet Info

output
.NET SDK:
Version: 8.0.204
Commit: c338c7548c
Workload version: 8.0.200-manifests.7d36c14f

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.204\

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.4
Architecture: x64
Commit: 2d7eea2529

.NET SDKs installed:
6.0.422 [C:\Program Files\dotnet\sdk]
8.0.204 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.4 [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:
C:\Users\***\***\global.json

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

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

### Visual Studio Version

_No response_

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.