Skip to content

Instantly share code, notes, and snippets.

@sailro
Created January 23, 2015 14:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sailro/f4109a1053420509025b to your computer and use it in GitHub Desktop.
Save sailro/f4109a1053420509025b to your computer and use it in GitHub Desktop.
Persist Source Code Control informations
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using UnityEditor;
using SyntaxTree.VisualStudio.Unity.Bridge;
using UnityEngine;
[InitializeOnLoad]
public class SccFileHook {
class Utf8StringWriter : StringWriter
{
public override Encoding Encoding {
get { return Encoding.UTF8; }
}
}
static SccFileHook()
{
ProjectFilesGenerator.SolutionFileGeneration += (string name, string content) =>
{
// Replace with your custom GlobalSection(TeamFoundationVersionControl)
return Regex.Replace(content, "^Global$", @"Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = http://server:8080/
SccLocalPath0 = .
SccProjectUniqueName1 = ProjectName\ProjectName.csproj
SccProjectName1 = ProjectName
SccLocalPath1 = ProjectName
EndGlobalSection"
, RegexOptions.Multiline);
};
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
var document = XDocument.Parse(content);
//http://alinconstantin.blogspot.fr/2008/02/sak-source-control-strings-in-visual.html
var propertyGroup = document.Descendants().FirstOrDefault(p => p.Name.LocalName == "PropertyGroup");
if (propertyGroup != null) {
var dns = propertyGroup.Name.Namespace;
propertyGroup.Add(new XElement(dns + "SccProjectName", "SAK"));
propertyGroup.Add(new XElement(dns + "SccLocalPath", "SAK"));
propertyGroup.Add(new XElement(dns + "SccAuxPath", "SAK"));
propertyGroup.Add(new XElement(dns + "SccProvider", "SAK"));
}
var str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment