Created
January 23, 2015 14:12
-
-
Save sailro/f4109a1053420509025b to your computer and use it in GitHub Desktop.
Persist Source Code Control informations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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