// 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) { return; } if (UnityUtils.ScriptingRuntime > 0) { var version = PluginSettings.TargetFrameworkVersion; if (!PluginSettings.OverrideTargetFrameworkVersion) { if (PluginSettings.SystemInfoRiderPlugin.operatingSystemFamily == OperatingSystemFamilyRider.Windows) { var versions = PluginSettings.GetInstalledNetFrameworks(); if (versions.Any()) { version = versions.OrderBy(v => new Version(v)).Last(); } } } targetFrameworkVersion.SetValue("v" + version); } else { var version = PluginSettings.TargetFrameworkVersionOldMono; if (!PluginSettings.OverrideTargetFrameworkVersionOldMono) { if (PluginSettings.SystemInfoRiderPlugin.operatingSystemFamily == OperatingSystemFamilyRider.Windows) { var versions = PluginSettings.GetInstalledNetFrameworks(); if (versions.Any()) { version = versions.OrderBy(v => new Version(v)).First(); } } } targetFrameworkVersion.SetValue("v" + version); } }
// Set appropriate version private static bool FixTargetFrameworkVersion(XElement projectElement, XNamespace xmlns) { return(SetOrUpdateProperty(projectElement, xmlns, "TargetFrameworkVersion", s => { if (UnityUtils.ScriptingRuntime > 0) { if (PluginSettings.OverrideTargetFrameworkVersion) { return "v" + PluginSettings.TargetFrameworkVersion; } } else { if (PluginSettings.OverrideTargetFrameworkVersionOldMono) { return "v" + PluginSettings.TargetFrameworkVersionOldMono; } } if (string.IsNullOrEmpty(s)) { ourLogger.Verbose("TargetFrameworkVersion in csproj is null or empty."); return string.Empty; } var version = string.Empty; try { version = s.Substring(1); // for windows try to use installed dotnet framework // Unity 2018.1 doesn't require installed dotnet framework, it references everything from Unity installation if (PluginSettings.SystemInfoRiderPlugin.operatingSystemFamily == OperatingSystemFamilyRider.Windows && UnityUtils.UnityVersion < new Version(2018, 1)) { var versions = PluginSettings.GetInstalledNetFrameworks(); if (versions.Any()) { var versionOrderedList = versions.OrderBy(v1 => new Version(v1)); var foundVersion = UnityUtils.ScriptingRuntime > 0 ? versionOrderedList.Last() : versionOrderedList.First(); // Unity may require dotnet 4.7.1, which may not be present var fvIsParsed = VersionExtensions.TryParse(foundVersion, out var fv); var vIsParsed = VersionExtensions.TryParse(version, out var v); if (fvIsParsed && vIsParsed && (UnityUtils.ScriptingRuntime == 0 || UnityUtils.ScriptingRuntime > 0 && fv > v)) { version = foundVersion; } else if (foundVersion == version) { ourLogger.Verbose("Found TargetFrameworkVersion {0} equals the one set-by-Unity itself {1}", foundVersion, version); } else if (ourLogger.IsVersboseEnabled()) { var message = $"Rider may require \".NET Framework {version} Developer Pack\", which is not installed."; Debug.Log(message); } } } } catch (Exception e) { ourLogger.Log(LoggingLevel.WARN, "Fail to FixTargetFrameworkVersion", e); } return "v" + version; } )); }