Customize project files created by VSTU

Visual Studio Tools for Unity provides a Unity-style callback during project file generation. Register with the VisualStudioIntegration.ProjectFileGeneration event to modify the project file whenever it's regenerated.


How to customize the Visual Studio project files generated by Visual Studio Tools for Unity.


using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

using UnityEngine;
using UnityEditor;

using SyntaxTree.VisualStudio.Unity.Bridge;

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);
            document.Root.Add(new XComment("FIX ME"));

            // save the changes using the Utf8StringWriter
            var str = new Utf8StringWriter();

            return str.ToString();

See also

Example: Log callback