rubicon-oss / LicenseHeaderManager

Manage license headers for your source code files in Visual Studio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Manual edit of %CreationYear% is not retained

PRABHAKARNAYAK opened this issue · comments

I have the below line as part of *.licenseheader template. Once I modify the creation date in my *.cs file to previous year and save, it gets modified back to current year.

Copyright © My Company Name %CreationYear% - %CurrentYear%.

Help required.

Hello @PRABHAKARNAYAK I'm sorry, but so far as I understand your question, this behavior is by design. The license header is always updated based on the configuration, not simply inserted once and then left alone.

You could change the creation date of your file using an attribute editor if you need to fix the creation date.

@MichaelKetting can u please help me on how to provide the attribute editor

@PRABHAKARNAYAK I may not point you to specific tools but if you perform a quick internet search for "file attribute editor" you will get a number of hits. Please select a tool that satisfies your installation and security requirements. Alternatively, you can also use .net APIs provided by System.IO.File to update the file attributes, either from within a simple .net application, the Visual Studio Immediate Window, or by calling the static methods on System.IO.File from within Powershell.

@MichaelKetting from where does the tool pick the creation year and fill %CreationYear% value.
Is it from the *.cs file properties.
For a file created in this year (%CreationYear%-%CurrentYear%) it will show me as 2020-2020. It's fine and the cs file is checked in to repository.
Now next year if I modify the same file will the copyright content be modified as 2020-2021.

If it will modify as above than for an old file created last year why is it not showing as 2019-2020.

@Stefan-Ilic , @iam-mholle could you check this please?

@MichaelKetting from where does the tool pick the creation year and fill %CreationYear% value.
Is it from the *.cs file properties.
For a file created in this year (%CreationYear%-%CurrentYear%) it will show me as 2020-2020. It's fine and the cs file is checked in to repository.
Now next year if I modify the same file will the copyright content be modified as 2020-2021.

Hi @PRABHAKARNAYAK,

Yes, we use the file's FileInfo to determine its creation year:

new DocumentHeaderProperty (
"%CreationYear%",
documentHeader => documentHeader.FileInfo != null,
documentHeader => documentHeader.FileInfo.CreationTime.Year.ToString()),

Whereas for the current year, we use Datetime.Now:

new DocumentHeaderProperty (
"%CurrentYear%",
documentHeader => true,
documentHeader => DateTime.Now.Year.ToString()),

You can refer to the Microsoft docs here if you want to read more about it.

I also explicitly tested the scenario you mentioned with a file created last year and the headers were set correctly