public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath) { if (!RiderPlugin.Enabled) { return; } var toBeConverted = importedAssets.Where(a => a.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) && importedAssets.Any(a1 => a1 == Path.ChangeExtension(a, ".pdb")) && importedAssets.All(b => b != Path.ChangeExtension(a, ".dll.mdb"))) .ToArray(); foreach (var asset in toBeConverted) { var pdb = Path.ChangeExtension(asset, ".pdb"); if (!IsPortablePdb(pdb)) { ConvertSymbolsForAssembly(asset); } else { RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, string.Format("mdb generation for Portable pdb is not supported. {0}", pdb)); } } }
// Set appropriate version private static void FixTargetFrameworkVersion(XElement projectElement, XNamespace xmlns) { var targetFrameworkVersion = projectElement.Elements(xmlns + "PropertyGroup") .Elements(xmlns + "TargetFrameworkVersion") .FirstOrDefault(); // Processing csproj files, which are not Unity-generated #56 if (targetFrameworkVersion != null) { int scriptingRuntime = 0; // legacy runtime try { var property = typeof(EditorApplication).GetProperty("scriptingRuntimeVersion"); scriptingRuntime = (int)property.GetValue(null, null); if (scriptingRuntime > 0) { RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, "Latest runtime detected."); } } catch (Exception) {} if (scriptingRuntime > 0) { targetFrameworkVersion.SetValue("v" + RiderPlugin.TargetFrameworkVersion); } else { targetFrameworkVersion.SetValue("v" + RiderPlugin.TargetFrameworkVersionOldMono); } } }
public static void OnGeneratedCSProjectFiles() { if (!RiderPlugin.Enabled) { return; } var currentDirectory = Directory.GetCurrentDirectory(); var projectFiles = Directory.GetFiles(currentDirectory, "*.csproj"); foreach (var file in projectFiles) { UpgradeProjectFile(file); } var slnFile = Directory.GetFiles(currentDirectory, "*.sln").FirstOrDefault(); if (string.IsNullOrEmpty(slnFile)) { return; } RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, string.Format("Post-processing {0}", slnFile)); string slnAllText = File.ReadAllText(slnFile); const string unityProjectGuid = @"Project(""{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1}"")"; if (!slnAllText.Contains(unityProjectGuid)) { string matchGUID = @"Project\(\""\{[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}\""\)"; // Unity may put a random guid, unityProjectGuid will help VSTU recognize Rider-generated projects slnAllText = Regex.Replace(slnAllText, matchGUID, unityProjectGuid); } var lines = slnAllText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var sb = new StringBuilder(); foreach (var line in lines) { if (line.StartsWith("Project(")) { MatchCollection mc = Regex.Matches(line, "\"([^\"]*)\""); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "mc[1]: "+mc[1].Value); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "mc[2]: "+mc[2].Value); var to = GetFileNameWithoutExtension(mc[2].Value.Substring(1, mc[2].Value.Length - 1)); // remove quotes //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "to:" + to); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, line); var newLine = line.Substring(0, mc[1].Index + 1) + to + line.Substring(mc[1].Index + mc[1].Value.Length - 1); sb.Append(newLine); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, newLine); } else { sb.Append(line); } sb.Append(Environment.NewLine); } File.WriteAllText(slnFile, sb.ToString()); }
private static void UpgradeProjectFile(string projectFile) { RiderPlugin.Log(string.Format("Post-processing {0}", projectFile)); var doc = XDocument.Load(projectFile); var projectContentElement = doc.Root; XNamespace xmlns = projectContentElement.Name.NamespaceName; // do not use var FixTargetFrameworkVersion(projectContentElement, xmlns); SetLangVersion(projectContentElement, xmlns); SetXCodeDllReference("UnityEditor.iOS.Extensions.Xcode.dll", xmlns, projectContentElement); SetXCodeDllReference("UnityEditor.iOS.Extensions.Common.dll", xmlns, projectContentElement); doc.Save(projectFile); }
private static void UpgradeProjectFile(string projectFile) { RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, string.Format("Post-processing {0}", projectFile)); var doc = XDocument.Load(projectFile); var projectContentElement = doc.Root; XNamespace xmlns = projectContentElement.Name.NamespaceName; // do not use var FixTargetFrameworkVersion(projectContentElement, xmlns); SetLangVersion(projectContentElement, xmlns); #if !UNITY_2017_1_OR_NEWER // Unity 2017.1 and later has this features by itself SetManuallyDefinedComilingSettings(projectFile, projectContentElement, xmlns); SetXCodeDllReference("UnityEditor.iOS.Extensions.Xcode.dll", xmlns, projectContentElement); SetXCodeDllReference("UnityEditor.iOS.Extensions.Common.dll", xmlns, projectContentElement); #endif doc.Save(projectFile); }
public static void OnGeneratedCSProjectFiles() { if (!RiderPlugin.Enabled) { return; } var currentDirectory = Directory.GetCurrentDirectory(); var projectFiles = Directory.GetFiles(currentDirectory, "*.csproj"); foreach (var file in projectFiles) { UpgradeProjectFile(file); } var slnFile = Directory.GetFiles(currentDirectory, "*.sln").First(); RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, string.Format("Post-processing {0}", slnFile)); string content = File.ReadAllText(slnFile); var lines = content.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var sb = new StringBuilder(); foreach (var line in lines) { if (line.StartsWith("Project(")) { MatchCollection mc = Regex.Matches(line, "\"([^\"]*)\""); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "mc[1]: "+mc[1].Value); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "mc[2]: "+mc[2].Value); var to = GetFileNameWithoutExtension(mc[2].Value.Substring(1, mc[2].Value.Length - 1)); // remove quotes //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "to:" + to); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, line); var newLine = line.Substring(0, mc[1].Index + 1) + to + line.Substring(mc[1].Index + mc[1].Value.Length - 1); sb.Append(newLine); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, newLine); } else { sb.Append(line); } sb.Append(Environment.NewLine); } File.WriteAllText(slnFile, sb.ToString()); }
private static void ConvertSymbolsForAssembly(string asset) { if (Pdb2MdbDriver == null) { RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, "FailedToConvertDebugSymbolsNoPdb2mdb."); return; } var method = Pdb2MdbDriver.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic); if (method == null) { RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, "WarningFailedToConvertDebugSymbolsPdb2mdbMainIsNull."); return; } var strArray = new[] { Path.GetFullPath(asset) }; method.Invoke(null, new object[] { strArray }); }
public static void OnGeneratedCSProjectFiles() { if (!RiderPlugin.Enabled) { return; } var currentDirectory = Directory.GetCurrentDirectory(); var projectFiles = Directory.GetFiles(currentDirectory, "*.csproj"); foreach (var file in projectFiles) { UpgradeProjectFile(file); } var slnFile = Directory.GetFiles(currentDirectory, "*.sln").First(); RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, string.Format("Post-processing {0}", slnFile)); var content = File.ReadAllText(slnFile); var lines = content.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var sb = new StringBuilder(); foreach (var line in lines) { if (line.StartsWith("Project(")) { var mc = Regex.Matches(line, "\"([^\"]*)\""); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "mc[1]: "+mc[1].Value); //RiderPlugin.Log(RiderPlugin.LoggingLevel.Info, "mc[2]: "+mc[2].Value); sb.Append(line.Replace(mc[1].Value.TrimStart("\"".ToCharArray()).TrimEnd("\"".ToCharArray()), GetFileNameWithoutExtension(mc[2].Value).TrimStart("\"".ToCharArray()).TrimEnd("\"".ToCharArray()))); } else { sb.Append(line); } sb.Append(Environment.NewLine); } File.WriteAllText(slnFile, sb.ToString()); }
private static void UpgradeProjectFile(string projectFile) { RiderPlugin.Log(RiderPlugin.LoggingLevel.Verbose, string.Format("Post-processing {0}", projectFile)); var doc = XDocument.Load(projectFile); var projectContentElement = doc.Root; XNamespace xmlns = projectContentElement.Name.NamespaceName; // do not use var FixTargetFrameworkVersion(projectContentElement, xmlns); FixSystemXml(projectContentElement, xmlns); SetLangVersion(projectContentElement, xmlns); // Unity_5_6_OR_NEWER switched to nunit 3.5 // Fix helps only for Windows, on mac and linux I get https://youtrack.jetbrains.com/issue/RSRP-459932 #if UNITY_5_6_OR_NEWER && UNITY_STANDALONE_WIN ChangeNunitReference(new FileInfo(projectFile).DirectoryName, projectContentElement, xmlns); #endif #if !UNITY_2017_1_OR_NEWER // Unity 2017.1 and later has this features by itself SetManuallyDefinedComilingSettings(projectFile, projectContentElement, xmlns); SetXCodeDllReference("UnityEditor.iOS.Extensions.Xcode.dll", xmlns, projectContentElement); SetXCodeDllReference("UnityEditor.iOS.Extensions.Common.dll", xmlns, projectContentElement); #endif doc.Save(projectFile); }