dotnet / templating

This repo contains the Template Engine which is used by dotnet new
https://docs.microsoft.com/dotnet/
MIT License
1.61k stars 368 forks source link

`copyOnly` doesn't work #7350

Open deadmann opened 9 months ago

deadmann commented 9 months ago

Product

dotnet CLI (dotnet new)

Describe The Bug

"sources": [ { "exclude": [ "/[Bb]in/", "/[Oo]bj/", "/*.filelist", "*/.user", "/*.lock.json" ], "copyOnly": [ "/node_modules/", "/[Nn]uget.[Cc]onfig" ], "modifiers": [ { "condition": "(!EnablePayment)", "exclude": [ "src/business/Domain/Entities/Payment.cs", "src/business/Domain/Entities/Invoice.cs", "src/business/Application/Payment/**", "src/data-access/Infrastructure/Common/Settings/PayHubEnvironmentSetting.cs", "src/presentation/WebApi/Common/Consts/EndPoints/PaymentController.cs", "src/presentation/WebApi/Controllers/PaymentController.cs", "src/presentation/WebApi/Models/WebHookNotifyModel.cs", "tests/Appstract.IntegrationTests/PaymentTests.cs"

      ]
    },
    {
      "condition": "(!CreateDockerfile)",
      "exclude": [ "**/Dockerfile" ]
    },
    {
      "condition": "(!GenerateDockerCompose)",
      "exclude": [ "**/docker-compose.y*ml"]
    },
    {
      "condition": "(!GenerateKubernetes)",
      "exclude": [ "deployment/chart/**" ]
    },
    {
      "condition": "(!GenerateAzurePipeline)",
      "exclude": [ "deployment/pipeline/**" ]
    }
  ]
}

]

To Reproduce

Steps:

  1. create template.json file in .template.config
  2. return to the root directory
  3. install: dotnet new install .\ --force
  4. use VS to create new project
  5. the Nuget.Config file had been replaced with sourceName

dotnet Info

output └─Δ dotnet --info .NET SDK: Version: 8.0.100 Commit: 57efcf1350 Workload version: 8.0.100-manifests.8d38d0cc Runtime Environment: OS Name: Windows OS Version: 10.0.20348 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100\ .NET workloads installed: Workload version: 8.0.100-manifests.8d38d0cc [android] Installation Source: VS 17.8.34330.188 Manifest Version: 34.0.43/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.43\WorkloadManifest.json Install Type: Msi [ios] Installation Source: VS 17.8.34330.188 Manifest Version: 17.0.8478/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.0.8478\WorkloadManifest.json Install Type: Msi [maui-windows] Installation Source: VS 17.8.34330.188 Manifest Version: 8.0.3/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.3\WorkloadManifest.json Install Type: Msi [maccatalyst] Installation Source: VS 17.8.34330.188 Manifest Version: 17.0.8478/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.0.8478\WorkloadManifest.json Install Type: Msi Host: Version: 8.0.0 Architecture: x64 Commit: 5535e31a71 .NET SDKs installed: 6.0.413 [C:\Program Files\dotnet\sdk] 7.0.403 [C:\Program Files\dotnet\sdk] 8.0.100 [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.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [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.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0 [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: D:\Projects\Structure\Appstract\Appstract\app\backend\global.json Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download

Visual Studio Version

2022

Additional context

template.json

{
  "$schema": "https://json.schemastore.org/template",
  "author": "Hassan Faghihi",
  "classifications": [ "Web", "MVC"],
  "identity": "Appstract.Backend",
  "name": "Appstract - Backend",
  "description": "This is the backend template for Appstract project.",
  "shortName": "appstract-backend",
  "sourceName": "Appstract",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "preferNameDirectory": true,
  "symbols": {
    "Framework": {
      "type": "parameter",
      "description": "The target framework for the project",
      "datatype": "choice",
      "replaces": "{TargetFramework}",
      "defaultValue": "net7.0",
      "choices": [
        {
          "choice": "net7.0",
          "description": "Stable"
        },
        {
          "choice": "net8.0"
        }
      ]
    },
    "EnablePayment": {
      "type": "parameter",
      "description": "Includes Payment",
      "displayName": "Enable Payment",
      "datatype": "bool",
      "defaultValue": "true"
    },

    "CreateDockerfile": {
      "type": "parameter",
      "displayName": "Create `Dockerfile`",
      "datatype": "bool",
      "defaultValue": "true"
    },
    "CreateDockerCompose": {
      "type": "parameter",
      "displayName": "Create `docker-compose`",
      "datatype": "bool",
      "defaultValue": "true",
      "description": "Enabling this feature, requires `CreateDockerfile` to be enable"
    },
    "CreateKubernetes": {
      "type": "parameter",
      "displayName": "Create Kubernetes Helm-charts configuration",
      "datatype": "bool",
      "defaultValue": "true",
      "description": "Enabling this feature, requires `CreateDockerfile` to be enable"
    },
    "CreateAzurePipeline": {
      "type": "parameter",
      "displayName": "Create Azure pipeline configuration",
      "datatype": "bool",
      "defaultValue": "true",
      "description": "Enabling this feature, requires `CreateDockerfile` to be enable"
    },

    "GenerateNotEnablePayment": {
      "type": "computed",
      "value": "EnablePayment == false"
    },
    "GenerateDockerCompose": {
      "type": "computed",
      "value": "(CreateDockerCompose == true && CreateDockerfile == true)"
    },
    "GenerateKubernetes": {
      "type": "computed",
      "value": "(CreateKubernetes ==true && CreateDockerfile == true)"
    },
    "GenerateAzurePipeline": {
      "type": "computed",
      "value": "(CreateAzurePipeline == true && CreateDockerfile == true)"
    }
  },
  "sources": [
    {
      "exclude": [
        "**/[Bb]in/**",
        "**/[Oo]bj/**",
        "**/*.filelist",
        "**/*.user",
        "**/*.lock.json"
      ],
      "copyOnly": [
        "**/node_modules/**",
        "/[Nn]uget.[Cc]onfig"
      ],
      "modifiers": [
        {
          "condition": "(!EnablePayment)",
          "exclude": [
            "src/business/Domain/Entities/Payment.cs",
            "src/business/Domain/Entities/Invoice.cs",
            "src/business/Application/Payment/**",
            "src/data-access/Infrastructure/Common/Settings/PayHubEnvironmentSetting.cs",
            "src/presentation/WebApi/Common/Consts/EndPoints/PaymentController.cs",
            "src/presentation/WebApi/Controllers/PaymentController.cs",
            "src/presentation/WebApi/Models/WebHookNotifyModel.cs",
            "tests/Appstract.IntegrationTests/PaymentTests.cs"

          ]
        },
        {
          "condition": "(!CreateDockerfile)",
          "exclude": [ "**/Dockerfile" ]
        },
        {
          "condition": "(!GenerateDockerCompose)",
          "exclude": [ "**/docker-compose.y*ml"]
        },
        {
          "condition": "(!GenerateKubernetes)",
          "exclude": [ "deployment/chart/**" ]
        },
        {
          "condition": "(!GenerateAzurePipeline)",
          "exclude": [ "deployment/pipeline/**" ]
        }
      ]
    }
  ]
}

Nuget.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear/>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
        <add key="appstract-maxtld-registery"
             value="https://gitlab-registry.maxtld.com/api/v4/projects/29/packages/nuget/index.json"/>
    </packageSources>
    <packageSourceCredentials>
        <appstract-maxtld-registery>
            <add key="Username" value="%GITLAB_NUGET_USERNAME%"/>
            <add key="ClearTextPassword" value="%GITLAB_NUGET_PASSWORD%"/>
        </appstract-maxtld-registery>
    </packageSourceCredentials>
    <activePackageSource>
        <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json"/>
        <add key="Appstract Nuget Repo"
             value="https://gitlab-registry.maxtld.com/api/v4/projects/29/packages/nuget/index.json"/>
    </activePackageSource>
</configuration>
deadmann commented 9 months ago

It must have been putted inside the modifiers array

"modifiers": [
        {
          "copyOnly": [
            "**/node_modules/**",
            "[Nn]uget.[Cc]onfig"
          ]
        },
        ...
    ]

that fixed, still my excludes doesn't works

"modifiers": [
        {
          "exclude": [
            "Appstract.sln",
            "**/[Bb]in/**/*",
            "**/[Oo]bj/**/*",
            "**/*.filelist",
            "**/*.user",
            "**/*.lock.json"
          ]
        },
        ...
    ]