【问题标题】:How to handle VSTO prerequisites in SideWaffle project template如何在 SideWaffle 项目模板中处理 VSTO 先决条件
【发布时间】:2015-01-13 14:27:52
【问题描述】:

我正在按照以下视频使用 SideWaffle 构建 VSTO 项目模板:

How to create Visual Studio project templates with TemplateBuilder and SideWaffle

我添加了一个现有(新)存根 VSTO 项目,将其设置为不在调试和发布中构建,但是当我按 Ctrl+F5 启动实验性 VS 实例时,我收到以下三个构建错误:

Could not copy the file "c:\users\john\documents\visual studio 2013\Projects\VisioVstoTemplate\VisioVstoTemplate\.NETFramework,Version=v4.5" because it was not found.  VisioVstoVSIX
Could not copy the file "c:\users\john\documents\visual studio 2013\Projects\VisioVstoTemplate\VisioVstoTemplate\Microsoft.VSTORuntime.4.0" because it was not found.   VisioVstoVSIX
Could not copy the file "c:\users\john\documents\visual studio 2013\Projects\VisioVstoTemplate\VisioVstoTemplate\Microsoft.Windows.Installer.4.5" because it was not found. VisioVstoVSIX

所以问题是:

  1. 为什么首先要寻找这些先决条件以及
  2. 如何防止错误发生?

(使用 Visual Studio 2013 Ultimate(更新 4)、SideWaffle 1.15 和 TemplateBuilder 1.1.2-beta5)

【问题讨论】:

标签: visual-studio-2013 vsto vsix sidewaffle


【解决方案1】:

我很确定我确切地知道这里发生了什么。我从未使用 VSTO 项目测试过 SideWaffle/TemplateBuilder。

在构建模板时,有一个步骤是使用项目文件中的文件填充_project.vstemplate.xml 的内容。因此,如果项目中列出的所有文件尚未列出,它们将被添加到 xml 文件中。这是通过检查列为<ItemGroup></ItemGroup> 中的元素的项目来实现的。例如

<ItemGroup> <Compile Include="App_Start\BundleConfig.cs" /> <Compile Include="App_Start\FilterConfig.cs" /> <Compile Include="App_Start\IdentityConfig.cs" /> </ItemGroup>

有时这些元素指向不是文件且不应复制的项目。例如。

<ItemGroup> <Reference Include="Microsoft.CSharp" /> <Reference Include="System" /> <Reference Include="System.Data" /> </ItemGroup>

TemplateBuilder 知道哪个是通过 MSBuild 项 ls-NonFileTypes 的方式。其默认值在 .targets 文件中定义,地址为 https://github.com/ligershark/template-builder/blob/master/tools/ligershark.templates.targets#L75

奇怪的是 VSTO 项目使用了一些我还没有看到的其他元素名称,应该添加到默认列表中。

如何解决它

查看项目文件并检查ItemGroup 下元素的名称,以及那些在Include 属性中没有文件路径的元素名称,如果它们尚未列出in the default list,这是一个问题。

在安装了 TemplateBuilder 的项目中,在 Properties\template-builder.props 处有一个新的 props 文件。一旦确定应在项目中过滤哪些项目类型,您就可以将其添加到该文件中。例如。

<ItemGroup> <ls-NonFileTypes Include="Service;BootstrapperPackage;"/> </ItemGroup>

或者您也可以将其声明为(它们是等效的)

xml <ItemGroup> <ls-NonFileTypes Include="Service"/> <ls-NonFileTypes Include="BootstrapperPackage"/> </ItemGroup>

SideWaffle 也使用它https://github.com/ligershark/side-waffle/blob/master/TemplatePack/Properties/template-builder.props#L30

【讨论】:

  • 完美!每个错误都有一个 BootstrapperPackage 元素,我可以确认将 '' 添加到 template-builder.props 可以解决问题。我会按要求在 GitHub 上提出问题。谢谢。
猜你喜欢
  • 2015-04-18
  • 1970-01-01
  • 2020-02-05
  • 1970-01-01
  • 2012-04-05
  • 2017-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多