Code Monkey home page Code Monkey logo

licenseheadermanager's Introduction

License Header Manager for Visual Studio

Manage license headers for your source code files in Visual Studio.

New files will automatically include the license headers defined in the current project.

License Header Manager allows you to:

  • Define license headers per Visual Studio project and per file extension
  • Share license headers between projects via "Add as Link"
  • Add, remove and replace headers at any time for one or all files
  • Put your license headers in #regions
  • Use Expendable Properties like %FileName%, %Project% or %UserName% and many more, which are automatically filled everytime the Header is reinserted

Start right here!

Install License Header Manager from Visual Studio via Tools | Extensions and Updates | Online or directly from Visual Studio Marketplace

ReSharper user? Take a look at this!

Previously located at: https://licensemanager.codeplex.com/

There is also the LicenseHeaderManager.Console project that is a console application which can be used to insert, replace or remove license headers via the command line. It can be supplied with a license header definition, a list of files or a directory as input and a JSON configuration file that controls the behaviour of the LicenseHeaderManager.Core component. The code below illustrates its usage.

Click to show help text
> LicenseHeaderManager.Console.exe --help

LicenseHeaderManager.Console 1.0.0.0
Copyright © 2021

  -m, --mode                         (Default: Add) Specifies whether license headers should be added or removed. Must be one of {Add, Remove}, case-insensitive.

  -l, --license-header-definition    Required. The path to the license header definition file to be used for the update operations.

  -c, --configuration                The path to the JSON file that configures the behaviour of the Core component. If not present, default values will be used.

  -f, --files                        Paths to the files whose headers should be updated, separated by comma (','). Must not be present if "directory" is present.

  -d, --directory                    Path of the directory containing the files whose headers should be updated. Must not be present if "files" is present.

  -r, --recursive                    (Default: false) Specifies whether the directory represented by "directory" should be searched recursively. Ignored if "files" is present instead of "directory".

  --help                             Display this help screen.

  --version                          Display version information.

USAGE:
 Add license headers to one file with a custom configuration:
   LicenseHeaderManager.Console.exe --configuration CoreOptions.json --files file.cs --license-header-definition DefinitionFile.licenseheader
 Remove license headers from multiple files with standard configuration:
   LicenseHeaderManager.Console.exe --files file1.cs,file2.html,file3.xaml --license-header-definition DefinitionFile.licenseheader --mode Remove
 Add license headers to all files in a directory, but not its subdirectories, with custom configuration:
   LicenseHeaderManager.Console.exe --configuration CoreOptions.json --directory C:\SomeDirectory --license-header-definition DefinitionFile.licenseheader
 Remove license headers from all files in a directory and its subdirectories with standard configuration:
   LicenseHeaderManager.Console.exe --directory C:\SomeDirectory --license-header-definition DefinitionFile.licenseheader --mode Remove --recursive

The JSON options that can be supplied with the --configuration flag represent the configuration of the Core component. The expander below shows a JSON representation of the default options that are used when the --configuration is not supplied.

Click to show default Core settings
{
"useRequiredKeywords": true,
"requiredKeywords": "license, copyright, (c), ©",
"licenseHeaderFileText": "extensions: .cs\r\n/* Copyright (c) rubicon IT GmbH\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"),\r\n * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\r\n * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n * \r\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n * \r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \r\n */\r\n\r\nextensions: .xaml\r\n<!--\r\nCopyright (c) rubicon IT GmbH\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"),\r\nto deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\r\nand/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n-->",
"languages": [
  {
    "extensions": [
      ".cs"
    ],
    "lineComment": "//",
    "beginComment": "/*",
    "endComment": "*/",
    "beginRegion": "#region",
    "endRegion": "#endregion",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".c",
      ".cpp",
      ".cxx",
      ".h",
      ".hpp"
    ],
    "lineComment": "//",
    "beginComment": "/*",
    "endComment": "*/",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".vb"
    ],
    "lineComment": "'",
    "beginComment": "",
    "endComment": "",
    "beginRegion": "#Region",
    "endRegion": "#End Region",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".aspx",
      ".ascx"
    ],
    "lineComment": "",
    "beginComment": "<%--",
    "endComment": "--%>",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".htm",
      ".html",
      ".xhtml",
      ".xml",
      ".xaml",
      ".resx",
      ".config",
      ".xsd"
    ],
    "lineComment": "",
    "beginComment": "<!--",
    "endComment": "-->",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": "(<\\?xml(.|\\s)*?\\?>)?(\\s*<!DOCTYPE(.|\\s)*?>)?( |\\t)*(\\n|\\r\\n|\\r)?"
  },
  {
    "extensions": [
      ".css"
    ],
    "lineComment": "",
    "beginComment": "/*",
    "endComment": "*/",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".js",
      ".ts"
    ],
    "lineComment": "//",
    "beginComment": "/*",
    "endComment": "*/",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": "(/// *<reference.*/>( |\\t)*(\\n|\\r\\n|\\r)?)*"
  },
  {
    "extensions": [
      ".sql"
    ],
    "lineComment": "--",
    "beginComment": "/*",
    "endComment": "*/",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".php"
    ],
    "lineComment": "//",
    "beginComment": "/*",
    "endComment": "*/",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".wxs",
      ".wxl",
      ".wxi"
    ],
    "lineComment": "",
    "beginComment": "<!--",
    "endComment": "-->",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".fs"
    ],
    "lineComment": "//",
    "beginComment": "(*",
    "endComment": "*)",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".cshtml",
      ".vbhtml"
    ],
    "lineComment": "",
    "beginComment": "@*",
    "endComment": "*@",
    "beginRegion": "",
    "endRegion": "",
    "skipExpression": ""
  },
  {
    "extensions": [
      ".py"
    ],
    "lineComment": "",
    "beginComment": "\"\"",
    "endComment": "\"\"",
    "beginRegion": null,
    "endRegion": null,
    "skipExpression": null
  }
]
}

License

MIT-License

licenseheadermanager's People

Contributors

f1x3d avatar floriandecker avatar fschmied avatar gmt2001 avatar iam-mholle avatar michaelketting avatar raffaelfoidl avatar randomengy avatar skleni avatar stefan-ilic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

licenseheadermanager's Issues

Add supported Languages to Default Options

Due to the LicenseHeaderManager now supporting SQL Projects and various other Project Types, we should add as much supported Languages as possible into the Default Options on the Language Page.

Should add:
.sql
.php
.wxs, .wxl, .wxi
.ts
.py
.php
.fs

Add Pre-/Post Update Commands

To improve performance and memory usage when updating big solutions, we should introduce the possibility of configuring pre and post update commands in the Options Menu..

GetHeaderRecursive (ProjectItem) throws StackOverflowException in CustomProjectTypes

This gets triggered when adding LicenseHeader to an Item inside a Folder.

Its because the ProjectItem of Type Microsoft.VisualStudioTools.Project.Automation.OAFolderItem
returns itself instead of the Parent when we are trying to move up the hierarchie with projectItem.Collection.Parent. This leads to infinite recursion -> StackOverflow.

Access to .licenseheader file is denied

Running VS 2015 on Windows 10 and I'm getting the following error message:

"Access to c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE.licenseheader" is denied

I also tried with a manually created .licenseheader file in the above directory, but that was not successful either.

Actual adding of header is not working

I am working on adding headers to all of the files in one of the frameworks I am working on (https://github.com/XLabs/Xamarin-Forms-Labs) and I am trying to use the LHM to help with this however it is not working. I have created the definition file and added it to my projects however when I go to actually add the header -- nothing happens (no error, no changes to the files, nothing).

Any idea on how I can track down what the issue is?

%Filename% returns lowercase filename

%Filename% currently returns the Filename in all lower and does not retain the correct casing. It is expected that the Filename gets inserted with the correct casing.

Python Tools adding Licenseheader to file in folder throws InvalidOperationException

When trying to add an Licenseheader to a .py file in a Folder in a Python Tools Project, an InvalidOperationException gets thrown with Error message "Operation is not valid due to the current state of the object":
capture

This is due to us trying to access projectItem.Collection. Collection is not implemented by Python Tools in OAFileItem. While the Base class provides an implementation for the root directory, it throws an InvalidOperationException in other cases (see Base Class Implementation, Line 157: https://github.com/Microsoft/PTVS/blob/master/Common/Product/SharedProject/Automation/OAProjectItem.cs ).

This can be fixed by accessing the Parent "Microsoft.VisualStudioTools.Project.Automation.OAFileItem" via the supplied object with reflection - the same fashion as #36 .

1.6.3 update error

Sometimes when right clicking an ProjectItem after updating to 1.7.0, following Error Screen appears
licenseheadermanagererror

It is not reproduceable 100%.

Extension keeps getting disabled

Using VS 2015 Community Edition. Windows 10

I have had LHM for some time and like it a lot but recently when I start VS, LHM is disabled. I enable it restart VS and LHM is there, but next time I start VS LHM is disabled once again.

Add existing License Header Definition File in a WixProj does not add the File as Link

When trying to add an existing License Header Definition File in a WixProj the License Header gets copied into the Project and not added as link.

It seems like the Function projectItems.AddFromFile(string filename) behaves different in this Project type, as we use this function to add the existing file for every project type and the other projects add the file as link. As .wixproj is a custom project type it is possible that their implementation behaves different than other project types. However, this behaviour does not occur in other custom Project Types (tested with PhP Project).

The Project Type seems to support Linked Files somehow, as it is possible to add other existing items as link (with Add -> Add Existing Item -> Add as Link). So there may be a workaround.

Improve Error/Exception Handling

When an Exception gets thrown, the user should be able to see the type and message of the exception and the stacktrace for better error reporting.

License Manager hangs while Updating Files

Hi!

Using Visual Studio 2015 Enterprise Update 2, I've tried many times to get the LicenseHeaderManager to work, but it keeps on hanging. It doesn't matter if I have source files open or closed, nor does mater if I use the generic .licenseheader file or create one of my own.

Any help in this regard would be greatly appreciated....

Sometimes the Trace.Assert error message "Settings update to VERSION didn't work" appears

In rare cases the error message "Settings update to VERSION didn't work" appears. So far i have not found a way to reliably reproduce it, so this error may be only be occurring local.

Maybe it should be considered replacing the Trace.Assert with a MessageBox to have a more consistent User Interaction when handling errors. Also, a Trace.Assert adds various other stuff to the message and looks much more dramatic than a clean MessageBox.

LicenseHeaderManager.Headers.UserInfo threw an exception

When pressing Alt-L to paste in the license header, I get a message "The type initializer for 'LicenseHeaderManager.Headers.UserInfo' threw an exception.
On further inspection the line in the UserInfo initializer with the code "UserPrincipal.Current.DisplayName" is probably the cause of the exception. I'm running VS on a home computer not connected to a domain. This line will throw an exception, because it cannot find a link to an AD.

Introduce Loggging Library

We should introduce a Logging Library (like log4net or NLog) for Debug/Exception Logging.

I would propose using NLog, as we have made some experience with that on another VisualStudio Extension and it seems to have everything we need. We can customize it with a custom Output handler to write to the Visual Studio Output Window.

The only Problem is that it does not find the config file on its own (same problem with log4net) and we have to set it on Package Initialize with this Code (assuming it gets put into the .vsix):

  string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\NLog.config", true);

SQL Project Invalid Path when trying to add licenseheaderfile

When trying to add a new .licensheaderfile in a sql Project, an error Message "URI is invalid" or "Access to path is denied" appears.

This error occurs because the Property "FileName" is used to generate the name and Path of the .licenseheader file. In some Projects, this property contains the FullPath while in sqlproject and custom projects there is only the filename (which - looking at the name of the property - seems to be the correct behaviour.

This can be fixed by using the "FullName" Property instead, as it contains the FullPath in every Project tested so far. Additionally we should include a check if this Property contains the FullPath as expected. For the case that any ProjectType has the wrong value there, we can try the "FileName" Property. If that too does not contain the full path we should abort and fail with a more clear error message.

Write integration tests

Using https://github.com/Microsoft/VisualStudio-TestHost VsTest Host it is fairly easy to write Tests for Visual Studio Extensions.

We should introduce an TestSolution containing different Project Types and Nested Folder. Then we can write automated Tests which add .licenseheader Files and Code Files to the Solution and then trigger Add Licensheader Commands on various Items.

Progress bar when adding/removing License Headers in solution

When adding/removing License header to a whole solution with many Projects, the status bar only shows the information that the License Header Manager is Updating Files, but no Information on the Progress.

Desired Behaviour: "Updating Files..." in the status bar should be replaced by the progress, something like "Updating Project 5/130", updating after every completed Project.

Python Tools Projects GetProjectItemParent throws InvalidOperationException in some cases

Python Tools Projects contains Python Packages which are deposited as OAProjectItem in the Project (see Snippet):
capture

When we are searching for a LicenseHeader in GetLicenseHeaderRecursive, these things throw InvalidOperationExceptions when trying to access the Property "Collection" in Function GetProjectItemParent (similar to #40 ).

We should probably just ignore those ProjectItems.

Inconsistent NewLine behaviour

When adding a new file, LicenseHeaderManager inserts the LicenseHeader without an extra NewLine.

When updating a file, LicenseHeaderManager inserts the LicenseHeader with an extra NewLine.

LicenseHeaderManager should either insert the extra NewLine every time or never.

The system cannot find the file specified.

I'm using version 1.7.0 with VS2015. When trying to add a new license header then I get the error "The system cannot find the file specified".

The project is a C# Class Library located in a folder named Source relative to the solution folder. The name of the project is different from source. It has the format Domain.Product. When adding a new license header definition file, it suggests the name as Source.licenseheader. I have tried renaming it to Domain.Product.licenseheader. But I get the error no matter what.

Any ideas how to resolve this?

.SQL files fail in VS 2013

Add the extension to VS 2013 Ultimate with SSDT project. Right click SSAS project node => License Headers => Add new license header definition file. Single extension (.sql) with simple header definition.

Edit a .SQL file. Go to EDIT menu => Advanced => ? No command visible for inserting header.
Go back to project node - right click => License Headers => Options... => General => Link 'Add License Header' command to Before Edit.FormatDocument (Ctrl-E + Ctrl-D) => ? Nothing happens. Try linking to other commands => Nothing happens.

Command line version

A command-line version that applies (and possibly also generate the .licenseheader) the header to all files in a project or solution would be a very welcomed addition. In fact, ideally, the extension would invoke the command-line version behind the scenes and display the output to the result pane in Visual Studio. It would also enable maximum code reuse and behavior parity between the extension and the command-line version.

Header not working with linked files

I'm working with linked files,
i.e.: My files "test.cs, test2.cs, etc", are outside of my project and I'm just linking then to my project.

I guess that this plug-in only update files inside the project and that's the why it's not working.

Well, has anyway? with linked files?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.