dotnet new 的多项目模板

Lib*_*eph 7 .net c# templates visual-studio visual-studio-templates

我正在创建一个多项目模板,其中包含一些可选项目和解决方案文件夹。我已经通过 github 中的很多不同的文档和代码来实现这一点,但收效甚微。我真的很感激有人能给我一些关于这些问题的澄清吗?

  1. VSTemplate xml 文件是否仍然相关? 这个博客建议在 template.json 文件中进行更改,但是当我在github 中检查示例时,人们使用 VSTemplate 创建项目,并且 SideWaffle 插件仍然创建了 VSTemplate 文件。如果它仍然相关,想知道它与 json 文件有何不同?
  2. 使用上面的 VSTemplate 我试图创建一个多项目模板,使用 ProjectCollection 标签,当我运行 dotnet run 命令时,模板被执行但项目没有被创建。

    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.Abstractions">
      Forms.Plugin.Abstractions\Forms.Plugin.Abstractions.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.iOS">
      Forms.Plugin.iOS\Forms.Plugin.iOS.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.iOSUnified">
      Forms.Plugin.iOSUnified\Forms.Plugin.iOSUnified.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.Android">
      Forms.Plugin.Android\Forms.Plugin.Android.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.WindowsPhone">
      Forms.Plugin.WindowsPhone\Forms.Plugin.WindowsPhone.vstemplate
    </ProjectTemplateLink>
    </ProjectCollection>```
    
    Run Code Online (Sandbox Code Playgroud)

我们可以使用 template.json 文件创建多项目模板吗?

如果有人能帮助我开始,将不胜感激。

Lib*_*eph 6

通过在 template.json 文件中进行更改,我设法使多项目模板正常工作

这是最终的 template.json 文件看起来像

This is my updated template.json file

    {
    "author": "Libin Joseph",
    "classifications": ["Xamarin", "Sample"],
    "name": "Sample Enterprise Template",
    "tags": {
        "language": "C#"
    },
    "identity": "libin.sampletemplate",
    "shortName": "sampletemplate",
    "sourceName": "SampleTemplate",
    "guids": [
        "{41F47D3C-C9E4-45D1-A289-3BDC31E44C19}",
        "{980FBE34-066B-4E87-AFC9-C3205844D980}",
        "{FD448FB5-B24B-4CD2-8E3C-2500CF0E4601}",
        "{D8FC665A-7739-4ADE-85E9-C69AA107EEE6}",
        "{92D25D7D-F637-4634-B939-BB38DE53B606}",
        "{5D52EDF7-47B8-48D2-83B6-104B18568CE4}",
        "{12E171B1-0F36-401A-A171-614F1A1C83E9}",
        "{7A4597AE-2C39-4197-94C9-F5B6B45B2106}"

    ],
    "primaryOutputs": [{
            "path": "SampleTemplate\\SampleTemplate.Android\\SampleTemplate.Android.csproj"
        },
        {
            "path": "SampleTemplate\\SampleTemplate.iOS\\SampleTemplate.iOS.csproj"
        },
        {
            "path": "SampleTemplate\\SampleTemplate\\SampleTemplate.csproj"
        },
        {
            "path": "SampleTemplate.UnitTest\\SampleTemplate.UnitTest.csproj"
        },
        {
            "path": "SampleTemplate.UITest\\SampleTemplate.UITest.csproj"
        },
        {
            "path": "SampleTemplate.Core\\SampleTemplate.Core.csproj"
        }
    ],
    "exclude": ["**/[Bb]in/**", "**/[Oo]bj/**", ".template.config/**/*", "**/*.lock.json"]
    }
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的分享!我有一个问题,“guid”属性中的 Guid 是关于什么的?是 ProjectType guid,还是每个项目的随机 guid,还是其他什么?编辑:没关系,在这里找到答案:https://github.com/dotnet/templated/wiki/Reference-for-template.json。谢谢 ! (2认同)