【问题标题】:How to add correct reference in VS Project Template with multiple projects如何在具有多个项目的 VS 项目模板中添加正确的引用
【发布时间】:2020-11-16 12:21:18
【问题描述】:

我正在尝试在 Visual Studio 中创建一个项目模板,该模板在解决方案中有多个项目。

总的来说,它运行良好,我面临的唯一问题是引用解决方案中的其他项目。

正如您在图片中看到的那样,一个项目被正确引用,因为此路径是设置的而不是动态的,其余的都是基于 vstemplate 文件中的项目名称。

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name> Api Template</Name>
    <Description>Base Template for Api Project</Description>
    <Icon>Icon.ico</Icon>
    <ProjectType>CSharp</ProjectType>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
      <ProjectTemplateLink ProjectName="$projectname$.Api" CopyParameters="true">
        Template.Api\Api.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="$projectname$.Application" CopyParameters="true">
        Template.Application\Appilication.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="$projectname$.Infrastructure" CopyParameters="true">
        Template.Infrastructure\Infrastructure.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="$projectname$.Shared" CopyParameters="true">
        Template.Shared\Shared.vstemplate
      </ProjectTemplateLink>
      <SolutionFolder Name="Common">
        <ProjectTemplateLink ProjectName="Mediator.Common" CopyParameters="true">
          Mediatr.Common\MediatorCommon.vstemplate
        </ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="Common.Types" CopyParameters="true">
          Common.Types\CommonTypes.vstemplate
        </ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="Common.Http" CopyParameters="true">
          Common.Http\HttpCommon.vstemplate
        </ProjectTemplateLink>
      </SolutionFolder>
    </ProjectCollection>
  </TemplateContent>
</VSTemplate>

.csproj 文件中的下一个正在构建引用的位置

<ItemGroup>
  <ProjectReference Include="..\Mediator.Common\Mediator.Common.csproj" />
  <ProjectReference Include="..\$projectname$.Application\$projectname$.Application.csproj" />
  <ProjectReference Include="..\$projectname$.Infrastructure\$projectname$.Infrastructure.csproj" />
  <ProjectReference Include="..\$projectname$.Shared\$projectname$.Shared.csproj" />
</ItemGroup>

这是试图创建引用,但我需要它从中间删除“Api”。

我离这个问题还很远

Adding references in Visual Studio project template?

Using CustomParameter with Visual Studio Multi-Project Template

但是,当我在这里查看https://docs.microsoft.com/en-us/visualstudio/ide/template-parameters?view=vs-2019 并尝试在参考中添加任何其他项目时,这是错误的,只是显示为 $value$ 而不是项目或与它有关的任何其他内容。

如何正确引用项目,以便我创建的模板不需要立即干预。

【问题讨论】:

    标签: visual-studio visual-studio-2019 project-template


    【解决方案1】:

    经过大量搜索,尝试失败,我终于偶然发现了这个页面

    https://www.programmingwithwolfgang.com/create-a-net-core-visual-studio-template/

    这让我得到了我需要的答案

    <ItemGroup>
        <ProjectReference Include="..\$ext_projectname$.Application\$ext_projectname$.Application.csproj" />
        <ProjectReference Include="..\$ext_projectname$.Infrastructure\$ext_projectname$.Infrastructure.csproj" />
    </ItemGroup>
    

    我在开始 $ 之后错过了 ext_

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多