From db5b2763de6f49a7f8ff2fa826ba27d6e6513af9 Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Fri, 12 Apr 2019 00:00:00 +0000 Subject: [PATCH] com.unity.ide.visualstudio@1.0.4 ## [1.0.4] - 2019-04-12 - Fixing null reference issue for callbacks to AssetPostProcessor. - Ensure Path.GetFullPath does not get an empty string. --- CHANGELOG.md | 5 +++++ Editor/ProjectGeneration.cs | 28 ++++++++++++++++++++++++---- Editor/VSEditor.cs | 12 ++++++++---- package.json | 4 ++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f38a7..a6f0afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Code Editor Package for Visual Studio +## [1.0.4] - 2019-04-12 + +- Fixing null reference issue for callbacks to AssetPostProcessor. +- Ensure Path.GetFullPath does not get an empty string. + ## [1.0.3] - 2019-01-01 ### This is the first release of *Unity Package visualstudio_editor*. diff --git a/Editor/ProjectGeneration.cs b/Editor/ProjectGeneration.cs index 09414a6..5a2a10e 100644 --- a/Editor/ProjectGeneration.cs +++ b/Editor/ProjectGeneration.cs @@ -225,6 +225,26 @@ namespace VisualStudioEditor : ScriptingLanguage.None; } + static List SafeGetTypes(System.Reflection.Assembly a) + { + var ret = new List(); + + try + { + ret = a.GetTypes().ToList(); + } + catch (System.Reflection.ReflectionTypeLoadException rtl) + { + ret = rtl.Types.ToList(); + } + catch (Exception) + { + return new List(); + } + + return ret.Where(r => r != null).ToList(); + } + public void GenerateAndWriteSolutionAndProjects() { // Only synchronize islands that have associated source files and ones that we actually want in the project. @@ -357,7 +377,7 @@ namespace VisualStudioEditor static void OnGeneratedCSProjectFiles() { - IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) + IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => SafeGetTypes(x)) .Where(x => typeof(AssetPostprocessor).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); var args = new object[0]; foreach (var type in types) @@ -373,7 +393,7 @@ namespace VisualStudioEditor static bool OnPreGeneratingCSProjectFiles() { - IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) + IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => SafeGetTypes(x)) .Where(x => typeof(AssetPostprocessor).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); bool result = false; foreach (var type in types) @@ -395,7 +415,7 @@ namespace VisualStudioEditor static string OnGeneratedCSProject(string path, string content) { - IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) + IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => SafeGetTypes(x)) .Where(x => typeof(AssetPostprocessor).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); foreach (var type in types) { @@ -416,7 +436,7 @@ namespace VisualStudioEditor static string OnGeneratedSlnSolution(string path, string content) { - IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) + IEnumerable types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => SafeGetTypes(x)) .Where(x => typeof(AssetPostprocessor).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); foreach (var type in types) { diff --git a/Editor/VSEditor.cs b/Editor/VSEditor.cs index 0fdd71c..4246da5 100644 --- a/Editor/VSEditor.cs +++ b/Editor/VSEditor.cs @@ -222,7 +222,7 @@ namespace VisualStudioEditor } catch (Exception e) { - UnityEngine.Debug.LogException(e); + UnityEngine.Debug.LogError($"VS: {e.Message}"); } } @@ -370,7 +370,11 @@ namespace VisualStudioEditor } UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(comAssetPath); var progpath = packageInfo.resolvedPath + comAssetPath.Substring("Packages/com.unity.ide.visualstudio".Length); - var fileInfo = new FileInfo(path).FullName; + string absolutePath = ""; + if (!string.IsNullOrWhiteSpace(path)) + { + absolutePath = Path.GetFullPath(path); + } var solution = GetSolutionFile(path); if (solution == "") @@ -384,7 +388,7 @@ namespace VisualStudioEditor StartInfo = new ProcessStartInfo { FileName = progpath, - Arguments = $"\"{CodeEditor.CurrentEditorInstallation}\" \"{fileInfo}\" {solution} {line}", + Arguments = $"\"{CodeEditor.CurrentEditorInstallation}\" \"{absolutePath}\" {solution} {line}", CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, @@ -409,7 +413,7 @@ namespace VisualStudioEditor var errorOutput = process.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(errorOutput)) { - UnityEngine.Debug.Log("Error: \n" + errorOutput); + Console.WriteLine("Error: \n" + errorOutput); } process.WaitForExit(); diff --git a/package.json b/package.json index 7fab9fd..935fda8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.unity.ide.visualstudio", "displayName": "Visual Studio Editor", "description": "Code editor integration for supporting Visual Studio as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.", - "version": "1.0.3", + "version": "1.0.4", "unity": "2019.2", "unityRelease": "0a7", "dependencies": {}, @@ -12,6 +12,6 @@ "repository": { "type": "git", "url": "git@github.cds.internal.unity3d.com:unity/com.unity.ide.visualstudio.git", - "revision": "073e1c76ae2fa95ff86200e26e9d59f2ebcd2527" + "revision": "89fbb2a14dd60b56c2eb64eac1e574a40a105822" } }