我想要一个用于 Visual Studio 的宏来设置程序集属性。有没有为此的代码模板?在 VS 内还是在互联网上?我正在寻找设置公司名称,商标等。
更新:
好的,这就是我刚刚用 C# 编写/破解的内容。我以为可能有一个片段。
class Program
{
/// <summary>
///
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
string rootDir = args[0];
string qualifyingFileName = args[1];
string disqualifyingPathNamePart = args[2];
string assAttrib = args[3];
string assAttribReplace = args[4];
bool removeComments = bool.Parse(args[5]);
bool removeEmptyLines = bool.Parse(args[6]);
bool IsCSharp = false;
IEnumerable<string> assFiles = Directory.EnumerateFiles(rootDir, qualifyingFileName, SearchOption.AllDirectories);
foreach (string ass in assFiles)
{
try
{
if (ass.Contains(disqualifyingPathNamePart)) { continue; }
IsCSharp = ass.EndsWith(".cs");
List<string> assFileLines = new List<string>();
assFileLines.AddRange(File.ReadAllLines(ass));
for (int i = assFileLines.Count - 1; i >= 0; i--)
{
if (assFileLines[i].Trim().StartsWith(IsCSharp ? "using" : "Imports")) { assFileLines.RemoveAt(i); continue; }
if (assFileLines[i].Trim().StartsWith("Option")) { assFileLines.RemoveAt(i); continue; }
if ((removeComments) && (assFileLines[i].Trim().StartsWith(IsCSharp ? "//" : "'"))) { assFileLines.RemoveAt(i); continue; }
if ((removeEmptyLines) && (assFileLines[i].Trim().Length == 0)) {
assFileLines.RemoveAt(i); continue;
}
if (!assFileLines[i].Contains(assAttrib)) { continue; }
assFileLines[i] = assAttribReplace;
}
if (IsCSharp)
{
assFileLines.Insert(0, "using System;");
assFileLines.Insert(1, "using System.Resources;");
assFileLines.Insert(2, "using System.Reflection;" );
assFileLines.Insert(3, "using System.Runtime.InteropServices;");
assFileLines.Insert(4, "");
}
else
{
assFileLines.Insert(0, "Option Strict On");
assFileLines.Insert(1, "Option Explicit On");
assFileLines.Insert(2, "");
assFileLines.Insert(3, "Imports System");
assFileLines.Insert(4, "Imports System.Resources");
assFileLines.Insert(5, "Imports System.Reflection");
assFileLines.Insert(6, "Imports System.Runtime.InteropServices");
assFileLines.Insert(7, "");
}
File.WriteAllLines(ass, assFileLines);
}
catch { }
}
Console.WriteLine("Finito");
Console.ReadLine();
}
}
用法:一个包含以下语句的批处理文件:
> macros.exe D:\Devzone AssemblyInfo.cs 3PL AssemblyCompany > "[assembly: AssemblyCompany(\"Your company name\")]" true true > > macros.exe D:\Devzone AssemblyInfo.cs 3PL AssemblyCopyright > "<Assembly: AssemblyCopyright(\"Copyright © 2003-2013. Your company > name. All Rights Reserved.\")>" true true > > macros.exe D:\Devzone AssemblyInfo.vb 3PL AssemblyCopyright > "<Assembly: AssemblyCopyright(\"Copyright © 2003-2013. Your company > name. All Rights Reserved.\")>" true true