Skip to content

Instantly share code, notes, and snippets.

@sailro
Created June 27, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sailro/9d36c7dee22de04332bea0df69e5a70d to your computer and use it in GitHub Desktop.
Save sailro/9d36c7dee22de04332bea0df69e5a70d to your computer and use it in GitHub Desktop.
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
#if ENABLE_VSTU
using SyntaxTree.VisualStudio.Unity.Bridge;
[InitializeOnLoad]
public class ProjectFileHook
{
// necessary for XLinq to save the xml project file in utf8
class Utf8StringWriter : StringWriter
{
public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
}
static ProjectFileHook()
{
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
// parse the document and make some changes
var document = XDocument.Parse(content);
var ns = document.Root.Name.Namespace;
document.Root
.Descendants()
.First(x => x.Name.LocalName == "ItemGroup")
.Add(new XElement(ns + "Reference", new XAttribute("Include", "System.Net.Http")));
// save the changes using the Utf8StringWriter
var str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
};
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment