Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:33:56+00:00 2026-06-10T19:33:56+00:00

After some Googling I found this: Use a Visual Studio Macro to Insert Copyright

  • 0

After some Googling I found this: Use a Visual Studio Macro to Insert Copyright Headers into Source Files. It looked promising:

// <copyright file="Sample.cs" company="My Company Name">
// Copyright (c) 2012 All Rights Reserved
// </copyright>
// <author>Leniel Macaferi</author>
// <date>08/30/2012 11:39:58 AM </date>
// <summary>Class representing a Sample entity</summary>

When I tried Tools -> Macros menu option it wasn’t there anymore in VS 2012. Here’s the proof: Macros in Visual Studio 11 Developer Preview. They just dropped this functionality. 🙁

So, I’m just curious to know which option I could use to add the copyright info to all existing source code files in my solution using Visual Studio 2012. Is there any standard way of doing this, using a template file (something related to T4 templates) or a PowerShell script? I could write some code to iterate over the files with .cs extension and add the copyright info but that is not what I’m after. I’d like to know about some tool to automate this process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:33:57+00:00Added an answer on June 10, 2026 at 7:33 pm

    You could create a new snippet and just type cp + double tab to insert the notice where you want (needless to say you can change the keyword to whatever you want).

    The only problem with it is, from what I’m aware, snippets do not support time functions, so getting the current time for your date line seems impossible with this technique. A not so good workaround for this is to make the time fields editable (similar to how the mbox snippet works) and just insert the time manually.

    Here’s an example on how a snippet looks. The bellow snippet will get the class name automatically and insert the copyright notice in the place where you type ‘copyright’ and double tab.

    Method 1

     <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
      <CodeSnippet Format="1.0.0">
        <Header>
          <Title>Copyright</Title>
          <Shortcut>Copyright</Shortcut>
          <Description>Code snippet for Copyright notice</Description>
          <Author>author name</Author>
          <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
          </SnippetTypes>
        </Header>
        <Snippet>
          <Declarations>
            <Literal Editable="false">
              <ID>classname</ID>
              <Function>ClassName()</Function>
            </Literal>
          </Declarations>
          <Code Language="csharp">
            <![CDATA[// <copyright file="$classname$" company="My Company Name">
          // Copyright (c) 2012 All Rights Reserved
          // <author>Leniel Macaferi</author>
          // </copyright>
          ]]>
          </Code>
        </Snippet>
      </CodeSnippet>
    </CodeSnippets>
    

    Method 2

    Also, here’s an example of a program you can make to do that for you.

    List<string> files = new List<string>()
    {
        "c:\\Form1.cs",
        "c:\\Form2.cs",
    };
    
    foreach (string file in files)
    {
        string tempFile = Path.GetFullPath(file) + ".tmp";
    
        using (StreamReader reader = new StreamReader(file))
        {
            using (StreamWriter writer = new StreamWriter(tempFile))
            {
                writer.WriteLine(@"// <copyright file=" + Path.GetFileNameWithoutExtension(file) + @" company=My Company Name>
    // Copyright (c) 2012 All Rights Reserved
    // </copyright>
    // <author>Leniel Macaferi</author>
    // <date> " + DateTime.Now + @"</date>
    // <summary>Class representing a Sample entity</summary>
    ");
    
                string line = string.Empty;
                while ((line = reader.ReadLine()) != null)
                {
                    writer.WriteLine(line);
                }
            }
        }
        File.Delete(file);
        File.Move(tempFile, file);
    }
    

    Some error catching will be required of course. But this should give you the general idea how to construct an UI around it an add the files you will want to process.

    Method 3

    It’s also possible to change the template for your classes that can be usually be found under:

    C:\Program Files (x86)\Microsoft Visual Studio <version>\Common7\IDE\ItemTemplates\CSharp\1033\
    

    Sometimes editing ItemTemplatesCache is also necessary to display the results.

    Here’s an example template based on your question:

    using System;
    using System.Collections.Generic;
    $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
    $endif$using System.Text;
    
    /* <copyright file=$safeitemrootname$ company="My Company Name">
       Copyright (c) 2012 All Rights Reserved
       </copyright>
       <author>Leniel Macaferi</author>
       <date>$time$</date>
       <summary>Class representing a Sample entity</summary>*/
    
    namespace $rootnamespace$
    {
        class $safeitemrootname$
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some googling-fu on making subscript text in crystal report, I found this ,
I found a post-receive hook for Git after some googling that I use to
Inspired by this discussion , after some googling I wasn't able to find an
In one of the C source code files I found the following line (macro):
After much googling and console testing I need some help with arrays in rails.
I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling
After some experience with functional languages, I'm starting to use recursion more in Java
I tried compile apache 2.2, my Visual Studio 2008 returned error on RC. After
After googeling for ages, and reading some stuff about async task in books. I
After some time researching and trying different things I still cannot get my @ExceptionHandler

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.