Skip to content

Instantly share code, notes, and snippets.

@rakkarage
Created April 4, 2018 17:44
Show Gist options
  • Save rakkarage/aa5c98b742f3cda22dc7dd76fcb471dc to your computer and use it in GitHub Desktop.
Save rakkarage/aa5c98b742f3cda22dc7dd76fcb471dc to your computer and use it in GitHub Desktop.
modify unity generated project files
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
class Fix : AssetPostprocessor
{
    private static void OnGeneratedCSProjectFiles()
    {
        Debug.Log("Fix.OnGeneratedCSProjectFiles");
        var dir = Directory.GetCurrentDirectory();
        var files = Directory.GetFiles(dir, "*.csproj");
        foreach (var file in files)
            FixProject(file);
    }
    static bool FixProject(string file)
    {
        var text = File.ReadAllText(file);
        var find = "<Reference Include=\"System\" />";
        var replace = "<Reference Include=\"System\" /> <Reference Include=\"System.Net.Http\" />";
        if (text.IndexOf(find) != -1)
        {
            text = Regex.Replace(text, find, replace);
            File.WriteAllText(file, text);
            return true;
        }
        else
            return false;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment