Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created December 16, 2020 05:10
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 kyubuns/aab83e03f896fcb58a0c0ef8469bc4b1 to your computer and use it in GitHub Desktop.
Save kyubuns/aab83e03f896fcb58a0c0ef8469bc4b1 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Xml.Linq;
using UnityEditor;
public class EnableNullable : AssetPostprocessor
{
private static string OnGeneratedCSProject(string path, string content)
{
var document = XDocument.Parse(content);
if (document.Root == null) throw new Exception($"document.Root == null");
XNamespace xNamespace = "http://schemas.microsoft.com/developer/msbuild/2003";
// ReSharper disable once PossibleNullReferenceException
var propertyGroup = document
.Element(xNamespace + "Project")
.Elements(xNamespace + "PropertyGroup")
.First();
propertyGroup.Add(new XElement(xNamespace + "Nullable", "enable"));
return document.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment