我希望根据开发人员在从模板创建C#解决方案时选择的内容来修改README.md的内容。我该怎么做?
我知道可以定义
"symbols": {
"EnableContent":{
"type": "parameter",
"dataType":"bool",
"defaultValue": "true"
}
}
在 template.config/template.json
中启用 dotnet new 模板的可选内容。
在 C# 代码中,如果将 EnableContent
设置为 true(使用 C# 预处理器指令),则可以使用定义的符号来包含一些代码。
#if (EnableContent)
public string foo()
{
return "bar";
}
#endif
而在 .cshtml 文件中,它可以被用作:
Translated text:而在 .cshtml 文件中,它可以被用作:
@*#if (EnableContent)
<p>foobar</p>
#endif*@
有没有办法在非C#文件中添加类似的决策制定,例如markdown文件(.md)?或者这是否取决于可用的C#预处理器指令?如果是这样,是否有任何解决方法可以在使用dotnet new的模板的上下文中在markdown文件中使用C#预处理器指令。
附言:我知道在这个例子中我可以做两个不同版本的README.md文件,然后使用源代码修改器选择正确的版本。
"sources": [
{
"modifiers": [
{
"condition": "(EnableContent)",
"exclude": [ "README1.md" ]
},
{
"condition": "(!EnableContent)",
"exclude": [ "README2.md" ]
}
]
}
在template.config/template.json
中,但我的需求比那更复杂。