Skip to content

Instantly share code, notes, and snippets.

@mviranyi
Forked from MattRix/RXSolutionFixer
Last active August 29, 2015 14:14
Show Gist options
  • Save mviranyi/b55d87557a580c9b47dd to your computer and use it in GitHub Desktop.
Save mviranyi/b55d87557a580c9b47dd to your computer and use it in GitHub Desktop.
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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment