Skip to content

Instantly share code, notes, and snippets.

@techgeek1
Created March 24, 2018 18:23
Show Gist options
  • Save techgeek1/31e777cc47b1d840ae8153554e1218a8 to your computer and use it in GitHub Desktop.
Save techgeek1/31e777cc47b1d840ae8153554e1218a8 to your computer and use it in GitHub Desktop.
Post processor for excluding shader files from the csproj unity 2018 generates
using SyntaxTree.VisualStudio.Unity.Bridge;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using UnityEditor;
using UnityEngine;
// Post processor for excluding shader files from the csproj unity 2018 generates
[InitializeOnLoad]
public class CsprojPostProcessor : MonoBehaviour {
static CsprojPostProcessor() {
ProjectFilesGenerator.ProjectFileGeneration += ModifyProjectFile;
}
private static string ModifyProjectFile(string name, string content) {
XDocument document = XDocument.Parse(content);
var itemGroups = document.Root.Descendants()
.Where(node => node.Name.LocalName == "ItemGroup");
IEnumerable<XElement> shaderGroups = itemGroups.Select(group => {
var child = group.Descendants()
.FirstOrDefault();
if (child != null && child.Name.LocalName == "None")
return group;
return null;
});
foreach(XElement group in shaderGroups) {
group?.RemoveAll();
}
return document.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment