Last active
March 20, 2017 14:07
-
-
Save drZool/2ebca2e90e9fa9edf151c8c4fc86cd07 to your computer and use it in GitHub Desktop.
Asset post processor to change .NET framework version from 3.5 to 4. and possibly mark the projects as unsafe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //#define ALLOW_UNSAFE //Uncomment this if you need to be in unsafe mode | |
| using System.IO; | |
| using UnityEngine; | |
| using UnityEditor; | |
| using System.Collections; | |
| using System.Text.RegularExpressions; | |
| class ProjectFileMod : AssetPostprocessor | |
| { | |
| private static void OnGeneratedCSProjectFiles () | |
| { | |
| foreach (var filePath in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csproj")) | |
| UpgradeTargetFrameworkVersion (filePath); | |
| } | |
| private static void UpgradeTargetFrameworkVersion (string filePath) | |
| { | |
| string content = File.ReadAllText (filePath); | |
| string searchString = "<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>"; | |
| bool changed = false; | |
| if (content.IndexOf (searchString) != -1) { | |
| content = Regex.Replace (content, searchString, "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>"); | |
| changed = true; | |
| } | |
| #if ALLOW_UNSAFE | |
| string append = "</DefineConstants>"; //HACK, find this location to inject the AllowUnsafeBlock | |
| string allowString = "<AllowUnsafeBlocks>true</AllowUnsafeBlocks>"; | |
| if (content.IndexOf (append) != -1 && content.IndexOf (allowString) == -1) { | |
| content = Regex.Replace (content, append, append + "\n\t" + allowString); | |
| changed = true; | |
| } | |
| #endif | |
| if (changed) { | |
| File.WriteAllText (filePath, content); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment