简体   繁体   中英

How to handle VSTO prerequisites in SideWaffle project template

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)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM