我想根据开发人员在从模板创建 ac# 解决方案时选择的内容来修改 README.md 的内容。我该怎么做?
我知道你可以定义
"symbols": {
"EnableContent":{
"type": "parameter",
"dataType":"bool",
"defaultValue": "true"
}
}
Run Code Online (Sandbox Code Playgroud)
在template.config/template.jsondotnet 新模板中启用可选内容。
在 c# 代码中,您可以使用定义的符号来包含一些代码,如果EnableContent设置为 true(使用 c# 预处理器指令)
#if (EnableContent)
public string foo()
{
return "bar";
}
#endif
Run Code Online (Sandbox Code Playgroud)
在 .cshtml 中它可以像
@*#if (EnableContent)
<p>foobar</p>
#endif*@
Run Code Online (Sandbox Code Playgroud)
有什么方法可以在非 c# 文件中添加类似的决策,比如 Markdown 文件 (.md)?还是这取决于可用的 c# 预处理器指令?如果是这样,在使用 dotnet new 模板的上下文中,是否有任何解决方法可以在 Markdown 文件中使用 c# 预处理器指令。
附:我知道在这个例子中我可以做两个不同版本的 README.md 然后使用源修饰符选择正确的一个
"sources": [
{
"modifiers": [
{
"condition": "(EnableContent)",
"exclude": [ "README1.md" ]
},
{
"condition": "(!EnableContent)",
"exclude": …Run Code Online (Sandbox Code Playgroud)