Skip to content

Skip Expressions

FlorianDecker edited this page Apr 12, 2017 · 2 revisions

You might want to use languages that require a special file header at the very beginning of the file. Consider the following XML file for example:

<?xml version="1.0" encoding="utf-8" ?>
<Root>
  <SomeTag SomeAttribute="true"/>
</Root>

If you want to add a license header, it needs to be inserted after the line in order to keep the xml valid:

<?xml version="1.0" encoding="utf-8" ?>
<!-- license header -->
<Root>
  <SomeTag SomeAttribute="true"/>
</Root>

For LHM to be able to correctly insert license headers in this case, it needs to be aware of the headers. In version 1.2 or higher you can define these headers yourself in the Tools/Options/License Header Manager/Languages menu in Visual Studio (in previous versions, the behaviour was hardcoded for XML files only).

For each language you can specify a regular expression that matches the header of the file. The following skip expressions are predefined after you upgrade to version 1.2:

.htm, .html, .xhtml, .xml, .xaml, .resx, .config, .xsd:

(<\?xml(.|\s)*?\?>)?(\s*<!DOCTYPE(.|\s)*?>)?(\n|\r\n|\r)

This expression will detect and skip XML declarations as well as HTML DocTypes (they are combined in one expression for compatibility reasons).

js, .ts:

/// *<reference.*/>( |\t)*(\n|\r\n|\r)?

In order to provide Intellisense support in .js files, Visual Studio needs the references to be specified in such comments at the beginning of the file.