且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Visual Studio 项目模板中添加引用?

更新时间:2023-02-27 10:27:28

您可以在解决方案模板中生成 GUID 并将它们传递给项目.因此,您需要解决方案模板中的 ProjectTemplateLink 中的参数 CopyParameters.示例:

You can generate the GUIDs in the solution template and pass them to the projects. Therefor you need the parameter CopyParameters in the ProjectTemplateLink in Solution Template. Example:

<ProjectTemplateLink ProjectName="$safeprojectname$.Data"  CopyParameters="true">

您的项目模板必须替换参数

Your project template has to replace parameters

<Project TargetFileName="Data.vbproj" File="Data.vbproj" ReplaceParameters="true">

现在您可以从项目文件中的解决方案模板访问参数并设置外部guid参数(注意对外部参数的访问有一个$ext_")

Now you can access the parameters from solution template inside the project file and set the external guid parameter (note the acces to the external parameter have a "$ext_")

 <ProjectGuid>{$ext_guid1$}</ProjectGuid>

对于带有引用的项目,您使用 ItemGroup 中的 ProjectReference

For the project with the reference you use the ProjectReference inside ItemGroup

<ItemGroup>
  <ProjectReference Include="..\$ext_safeprojectname$.Data\$ext_safeprojectname$.Data.vbproj">
    <Project>{$ext_guid1$}</Project>
    <Name>$ext_safeprojectname$.Data</Name>
  </ProjectReference>
</ItemGroup>

使用带有 .NET Framework 4.5.2 的 Visual Studio 2017 对我有用

It worked for me using Visual Studio 2017 with .NET Framework 4.5.2