Skip to content

Common errors and gotchas

Tyler Hughes edited this page Feb 26, 2015 · 3 revisions

Name cannot begin with the '$' character

Build FAILED.
       "C:\path\VsixConsoleAppTemplate.csproj" (default target) (1) ->
       (ls-PreprocessProjectFiles target) -> 
         C:\path\..\ligershark.templates.targets(815,5): error : Name cannot begin with the '$' character, hexadecimal value 0x24. Line 10, position 6. [C:\path\VsixConsoleAppTemplate.csproj]

This can happen when you have a replacement that modifies the .csproj such that it is no longer valid XML. For example (source)

    <add key="RootNamespace" value="$companynamespace$.$safeprojectname$"/>
    <add key="AssemblyName" value="$companynamespace$.$safeprojectname$"/>

When the replacements are processed the .csproj file ends up having the following.

<$companynamespace$.$safeprojectname$>$safeprojectname$</$companynamespace$.$safeprojectname$>

Resolution

If you do not need to do replacements on the project file, then add *.csproj (or whatever the extension is for your case) to the Exclude list in _preprocess.xml.

You can also make your replacement strings more unique so that there are no conflictions and only the exact lines you intend are replaced.

Caveats for VSTO project templates

There's a couple of amends required for VSTO projects:

  1. Non-file types - VSTO projects include a number of references that are interpreted as actual files, which produces a Could not copy the file build error. For example:
<ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.5">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.VSTORuntime.4.0">
      <Visible>False</Visible>
      <ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
      <Visible>False</Visible>
      <ProductName>Windows Installer 4.5</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>

To ensure that TemplateBuilder sees these items as non-file types you need to add the following to the template-builder.props file under Properties in your VSIX project:

<ItemGroup> 
	<ls-NonFileTypes Include="BootstrapperPackage"/> 
  </ItemGroup>
  1. ProjectExtensions - Project files can contain an optional ProjectExtensions element to provide an area that is ignored by MSBuild. VSTO projects uses this element to include various information about the VSTO host (addin, workbook, worksheet etc.). TemplateBuilder removes the ProjectExtensions element by default, so to make sure it's included, you need to add the following element to the PropertyGroup element to the same file as above (template-builder.props file under Properties in your VSIX project):
<ls-enable-remove-proj-extensions>false</ls-enable-remove-proj-extensions>

TemplateBuilder does not add asset tags when installed

When you add the TemplateBuilder nuget package to your project it sometimes will not add the asset tags. Currently, you can workaround around this issue by opening your source.extension.vsixmanifest file and adding the replacing the <Assets /> with the following code:

<Assets>
  <Asset Type="Microsoft.VisualStudio.ItemTemplate" Path="Output\ItemTemplates"/>
  <Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path="Output\ProjectTemplates" />
</Assets>