无法重命名

问题描述 投票:0回答:1

我正在尝试使用自定义名称重命名 sln 文件,同时从 c# 项目模板生成解决方案,我有不同的项目名称,sln 名称也不同,并且希望保持不同。下面是我这样做的目的,名称函数不会将解决方案作为参数而不是字符串读取,因此当它重命名 sln 文件时,会变成 {{solution}}.sln。我想用参数值替换它

我已经尝试了下面的代码,但现在卡住了

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Sanjyot Agureddy",
    "classifications": [
        "Web API",
        "ASP.NET",
        "Clean Architecture"
    ],
    "tags": {
        "language": "C#",
        "type": "project"
    },
    "identity": "application.Services.Sample",
    "name": "ASP.NET Clean Architecture Solution",
    "shortName": "application-sln",
    "sourceName": "application.Services.Sample",
    "preferNameDirectory": false,
    "symbols": {
        "solution": {
            "type": "parameter",
            "defaultValue": "application-service",
            "replaces": "application-sample",
            "description": "The name of the solution file.",
            "dataType": "text",
            "isRequired": true
        }
    },
    "sources": [
        {
            "source": "./",
            "target": "./",
            "exclude": [
                ".vs/**/*",
                ".git/**/*",
                ".template.config/**/*",
                "templates/**/*",
                "**/*.filelist",
                "**/*.user",
                "**/*.lock.json",
                "*.nuspec"
            ],
            "rename": {
                "application-sample.sln": "{{solution}}.sln"
            }
        }
    ]
}

c# project-template
1个回答
0
投票

rename
映射中的占位符不会像您所期望的那样使用双大括号
{{ }}
进行处理。相反,您需要使用与 .NET 模板引擎的令牌替换设置相匹配的语法。

默认情况下,.NET 模板引擎使用语法

__<parameter>__
来替换文件名和内容中的参数。要解决您的问题,您需要调整
template.json
文件以使用此语法。

以下是如何修改

template.json
以在模板实例化期间正确替换解决方案名称:

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Sanjyot Agureddy",
    "classifications": [
        "Web API",
        "ASP.NET",
        "Clean Architecture"
    ],
    "tags": {
        "language": "C#",
        "type": "project"
    },
    "identity": "application.Services.Sample",
    "name": "ASP.NET Clean Architecture Solution",
    "shortName": "application-sln",
    "sourceName": "application-sample",
    "preferNameDirectory": false,
    "targetTokenPrefix": "__",
    "targetTokenSuffix": "__",
    "symbols": {
        "solution": {
            "type": "parameter",
            "defaultValue": "application-service",
            "replaces": "application-sample",
            "description": "The name of the solution file.",
            "dataType": "text",
            "isRequired": true
        }
    },
    "sources": [
        {
            "source": "./",
            "target": "./",
            "exclude": [
                ".vs/**/*",
                ".git/**/*",
                ".template.config/**/*",
                "templates/**/*",
                "**/*.filelist",
                "**/*.user",
                "**/*.lock.json",
                "*.nuspec"
            ],
            "rename": {
                "application-sample.sln": "__solution__.sln"
            }
        }
    ]
}
© www.soinside.com 2019 - 2024. All rights reserved.