如何让Visual Studio在每个文件的顶部添加开源许可证

时间:2009-11-04 06:23:38

标签: visual-studio resharper

如何让Resharper在每个文件的顶部添加开源许可证?

3 个答案:

答案 0 :(得分:4)

如果我理解正确,您需要在每个源文件的顶部添加注释,详细说明您的许可模式吗? 如果是,请尝试Visual Studio templates

答案 1 :(得分:2)

你可以使用Visual Assist X创建一个小脚本。它不会自动执行,但您只需在页面顶部键入lic即可输出许可信息。

答案 2 :(得分:1)

这是我为麻省理工学院许可证整理的片段。你打开一个C#代码文件,你输入两次“许可证”命中标签,你就会被默认为年份和版权所有者部分。

以下是describes the process的链接。希望这会有所帮助。

    <?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Simple MIT License</Title>
      <Shortcut>license</Shortcut>
      <Description>
       The standard MIT licnese.
      </Description>
      <Author>Example License</Author>
      <SnippetTypes>       
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>   
    <Snippet>
    <Declarations>
    <Literal>
      <ID>year</ID>
      <ToolTip>Copyright year</ToolTip>
      <Default>year</Default>
    </Literal>
    <Literal>
      <ID>copyrightholders</ID>
      <ToolTip>Replace This With the Copyright Holders name</ToolTip>
      <Default>copyrightholders</Default>
    </Literal>  
  </Declarations>
  <Code Language="CSharp">
    <![CDATA[
    /*
        The MIT License

        Copyright (c) $year$ $copyrightholders$

        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, 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:

        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.

        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, 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.
    */
   ]]>
  </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>