anx.framework/Tools/ProjectConverter/AssemblyInfoFixer.cs
SND\AstrorEnales_cp 18152ade3e Implemented Feature #1010 by replacing the MsBuild sln-Parsing with our own parser which
enables us to run the project converter on linux. Updated all projects via ProjectConverter.
2015-03-15 01:11:14 +01:00

62 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ProjectConverter
{
public class AssemblyInfoFixer
{
public static void FixCompanyAndCopyright(string filepath, int yearOfLastChange)
{
FixAllEntries(filepath, "AssemblyCompany", "ANX.Framework Team");
FixAllEntries(filepath, "AssemblyCopyright", "Copyright © ANX.Framework Team 2011 - " + yearOfLastChange);
}
#region FixAllEntries
private static void FixAllEntries(string filepath, string entryName, string newValue)
{
var projectPaths = CollectProjectPaths(filepath);
foreach (string project in projectPaths)
{
string assemblyInfoPath = Path.Combine(Path.GetDirectoryName(project), "Properties//AssemblyInfo.cs");
string text = File.ReadAllText(assemblyInfoPath, Encoding.UTF8);
int index = text.IndexOf("[assembly: " + entryName);
if (index == -1)
continue;
index = text.IndexOf("\"", index) + 1;
int endIndex = text.IndexOf("\"", index);
text = text.Remove(index, endIndex - index).Insert(index, newValue);
File.WriteAllText(assemblyInfoPath, text, Encoding.UTF8);
}
}
#endregion
#region CollectProjectPaths
private static List<string> CollectProjectPaths(string filepath)
{
var projectPaths = new List<string>();
if (filepath.EndsWith(".sln", StringComparison.InvariantCultureIgnoreCase))
{
var solution = VsSolution.Load(filepath);
string basePath = Path.GetDirectoryName(filepath);
foreach (var project in solution.Projects)
if (project.IsCsProject)
projectPaths.Add(Path.Combine(basePath, project.RelativePath));
}
else
projectPaths.Add(filepath);
return projectPaths;
}
#endregion
}
}