Created
November 24, 2014 19:33
-
-
Save MattRix/daf67d66227c61501397 to your computer and use it in GitHub Desktop.
This upgrades your csproj files to .NET 4.0 so you can use default parameters (etc) while building in MonoDevelop
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
using UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
using System.Collections.Generic; | |
using System.Collections; | |
using System; | |
class RXSolutionFixer : AssetPostprocessor | |
{ | |
private static void OnGeneratedCSProjectFiles() //secret method called by unity after it generates the solution | |
{ | |
string currentDir = Directory.GetCurrentDirectory(); | |
string[] csprojFiles = Directory.GetFiles(currentDir, "*.csproj"); | |
foreach(var filePath in csprojFiles) | |
{ | |
FixProject(filePath); | |
} | |
} | |
static bool FixProject(string filePath) | |
{ | |
string content = File.ReadAllText(filePath); | |
string searchString = "<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>"; | |
string replaceString = "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>"; | |
if(content.IndexOf(searchString) != -1) | |
{ | |
content = Regex.Replace(content,searchString,replaceString); | |
File.WriteAllText(filePath,content); | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} |
That looks amazing! ^^
A work colleague tried something similar and ended up in a infinite loop of fixing and reloading the project 😵 This looks rather correct!
That worked like a charm. Thank you.
Thank you so much! Unity kept syncing with MonoDevelop, reverting back to 3.5 and sometimes crashing it in the process. Completely absurd! This worked perfectly though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice clean solution, thank you for posting!