How to handle VSTO prerequisites in SideWaffle project template

本小妞迷上赌 提交于 2019-12-11 20:10:33

问题


I'm building a VSTO project template with SideWaffle following the video from:

How to create Visual Studio project templates with TemplateBuilder and SideWaffle

I added an existing (new) stub VSTO project, set it not to build in both debug and release, but when I hit Ctrl+F5 to launch the Experimental VS instance I get the following three build errors:

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

So questions are:

  1. why are these prerequisites being looked for in the first place and
  2. how can I prevent the error?

(Using Visual Studio 2013 Ultimate (Update 4), SideWaffle 1.15 and TemplateBuilder 1.1.2-beta5)


回答1:


I am pretty sure that I know exactly what is happening here. I've never tested SideWaffle/TemplateBuilder with a VSTO project.

When templates are built there is a step where the contents of the _project.vstemplate.xml are populated using the files from the project file. So all files listed in the project will be added to the xml file if they were not already listed. This is implemented by examining the items listed as elements inside <ItemGroup></ItemGroup>. For example

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

Sometimes these elements point to items which are not files and should not be copied. For example.

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

The way that TemplateBuilder knows which is by an MSBuild item ls-NonFileTypes. The default values for this are defined in the .targets file at https://github.com/ligershark/template-builder/blob/master/tools/ligershark.templates.targets#L75.

Odds are that VSTO projects use some other element name which I have not seen yet which should be added to the default list.

How to workaround it

Take a look at the project file and examine the names of elements under ItemGroup and for those that do not have a file path in the Include attribute if they are not already listed in the default list that's a problem.

In a project which has TemplateBuilder installed there is a new props file at Properties\template-builder.props. Once you determine which item types should be filtered in your project you can add it in that file. For example.

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

or you could also have it declared as (they are equivalent)

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

SideWaffle uses this as well https://github.com/ligershark/side-waffle/blob/master/TemplatePack/Properties/template-builder.props#L30.



来源:https://stackoverflow.com/questions/27924403/how-to-handle-vsto-prerequisites-in-sidewaffle-project-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!