Antes de nada un saludo a mis amigos Jesus, David y David. Espero que todo os vaya genial, tenemos que quedar para charlar algun dia no? digooooooooo
Bueno, la idea de este post es crear un programilla en C# para quitar las referencias que deja el Source Safe en nuestras soluciones/projectos. He estado leyendo cositas y generalmente la gente lo hace a mano porque unicamente lo tiene que quitar de una solucion con un par de proyectos. Pero, que pasa cuando tenemos... unas 10 soluciones con, digamos tres proyectos cada una? pues que ni te lo piensas, hay que automatizarlo de alguna manera.
Estos son los pasos que he seguido para quitar el binding:
1 - Go to the folder containing the solution files and delete the following:
mssccprj.scc
MyProject.vssscc
vssver.scc
2 - Open MyProject.sln in your favorite text editor and remove the following section:
GlobalSection(SourceCodeControl) = preSolution
...
EndGlobalSection
3 - Go to the folder containing the project files and delete the following:
MyProject.vbproj.vspscc
mssccprj.scc
vssver.scc
4 - Open MyProject.vbproj in your text editor and remove the following lines:
SccProjectName = "SAK"
SccLocalPath = "SAK"
SccAuxPath = "SAK"
SccProvider = "SAK"
Parece que no pero pero recorrerte toda la estructura de carpetas haciendo esto tiene que ser fatal asi que utilizamos un metodo loopDir para recorrerlo y dos funciones removeSolutionBinding y removeProjectBinding para quitar el texto que hace referencia al vss dentro de los ficheros .sln y .csproj:
private static void loopDir(string dir)
{
string[] dirs = Directory.GetDirectories(dir);
string[] files = Directory.GetFiles(dir);
foreach (string s in files)
{
File.SetAttributes(s, FileAttributes.Normal);
if (Path.GetExtension(s) == ".sln" || Path.GetExtension(s)== ".csproj" || Path.GetExtension(s) == ".vbproj")
{
removeBinding(s);
}
else if (Path.GetExtension(s) == ".scc" ||Path.GetExtension(s) == ".vssscc" || Path.GetExtension(s) == ".vspscc")
{
File.Delete(s);
}
}
// loop subdirs
if (dirs.Length > 0)
{
foreach (string d in dirs)
{
// call this method again
loopDir(d);
}
}
}
De esta manera recorremos el arbol de carpetas. Si nos encontramos un fichero de solucion o proyecto llamamos a eliminar binding y sino, si es un fichero de los que hay que eliminar pues lo borramos directamente.
Aqui estan las funciones de eliminar binding:
private static void removeBinding(string f)
{
switch (Path.GetExtension(f))
{
case ".sln":
removeSolutionBinding(f);
break;
default:
removeProjectBinding(f);
break;
}
}
private static void removeSolutionBinding(string s)
{
string line = string.Empty;
bool flag = false;
FileStream fs = new FileStream(s + ".temp", FileMode.CreateNew);
System.IO.StreamWriter sw = new StreamWriter(fs);
//Create reader
System.IO.StreamReader sr = new System.IO.StreamReader(s);
while (sr.Peek() != -1)
{
line = sr.ReadLine();
if (line.IndexOf("GlobalSection(SourceCodeControl)") == -1 && !flag)
sw.WriteLine(line);
else
//do not write endglobalsection line
flag = (line.IndexOf("EndGlobalSection") == -1);
}
sr.Close();
sw.Close();
File.Copy(fs.Name, s, true);
File.Delete(fs.Name);
fs.Close();
}
private static void removeProjectBinding(string s)
{
string line = string.Empty;
bool flag = false;
FileStream fs = new FileStream(s + ".temp", FileMode.CreateNew);
System.IO.StreamWriter sw = new StreamWriter(fs);
//Create reader
System.IO.StreamReader sr = new System.IO.StreamReader(s);
while (sr.Peek() != -1)
{
line = sr.ReadLine();
if (line.IndexOf("SccProjectName") == -1 && !flag)
sw.WriteLine(line);
else
{
flag = (line.IndexOf(">") == -1);
//need to write symbol ">" to close the tag
if (!flag) sw.WriteLine(line);
}
}
sr.Close();
sw.Close();
File.Copy(fs.Name, s, true);
File.Delete(fs.Name);
fs.Close();
}
Unicamente comentar que si tenemos la solucion y todos los projectos en el mismo arbol de directorios todo irá como la seda pero recordad que a veces para montar nuestras aplicaciones en local los projectos web están ubicados en wwwroot por lo que tendreis que seleccionar dentro de wwwroot la carpeta de vuestro projecto para quitar tambien el binding de ahí.
Un saludo amigos ;)
miércoles, octubre 31, 2007
Suscribirse a:
Entradas (Atom)