From b132c03a8a8f18403daa24fb837ba896e2b1d491 Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Mon, 21 Mar 2022 00:00:00 +0000 Subject: [PATCH] com.unity.ide.visualstudio@2.0.15 ## [2.0.15] - 2022-03-21 Integration: - Improved project generation performance. - Added support for keeping file/folder structure when working with external packages. - Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor. --- CHANGELOG.md | 10 +++ .../COMIntegration/Release/COMIntegration.exe | Bin 293376 -> 293376 bytes Editor/FileUtility.cs | 2 +- .../Contents/MacOS/AppleEventIntegration | Bin 153504 -> 153504 bytes Editor/ProjectGeneration/ProjectGeneration.cs | 74 ++++++++++++------ Editor/VisualStudioEditor.cs | 27 ++----- package.json | 11 ++- 7 files changed, 76 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64d70b7..ba42643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Code Editor Package for Visual Studio +## [2.0.15] - 2022-03-21 + +Integration: + +- Improved project generation performance. +- Added support for keeping file/folder structure when working with external packages. +- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor. + + + ## [2.0.14] - 2022-01-14 Integration: diff --git a/Editor/COMIntegration/Release/COMIntegration.exe b/Editor/COMIntegration/Release/COMIntegration.exe index e3959c418cf800ff3cdba0ffef644c7ee9492fcd..829c5cf1900af4244bdf8d6078cc3a4d3fa8159f 100644 GIT binary patch delta 42 scmZqpBG~XnaDxCN%Z$kuNzEdR?IMgI%(PvEk=f${Saf^BMdk%704?hdO8@`> delta 42 tcmZqpBG~XnaDxCN%Y+*b6PraC+eH{bm}$ERBeTZ^u;})Li_8mF002-`5ETFb diff --git a/Editor/FileUtility.cs b/Editor/FileUtility.cs index 9e1a66d..4a4d9a9 100644 --- a/Editor/FileUtility.cs +++ b/Editor/FileUtility.cs @@ -39,7 +39,7 @@ public static string NormalizePathSeparators(this string path) return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString()); } - public static string NormalizeWindowsToUnix(string path) + public static string NormalizeWindowsToUnix(this string path) { if (string.IsNullOrEmpty(path)) return path; diff --git a/Editor/Plugins/AppleEventIntegration.bundle/Contents/MacOS/AppleEventIntegration b/Editor/Plugins/AppleEventIntegration.bundle/Contents/MacOS/AppleEventIntegration index ee672b65b0d4a6da3ea4dae26a0d0a828dd62829..2af7832b6b5755d131e2ab4fb50dafded3a0cb49 100644 GIT binary patch delta 110 zcmV-!0FnQouL+>939v}S1PYTlVzW%d6$~IX&d3A=^lE5?FpkyhVwUCuKyx&2Og*kA z2f42k(Zi~PfzY>s&;h?Q1PYTlVz)#D0<8=noTvPqNca2H2)C)nPf2$V%939v}S1W4H7VY5uc6$~KsrKo|Kdn!vuV4k8Q-jh9RLoGk8u)jZ1 zao47>U(_vwfzY>s&;h?Q1W4H7VYfsC0<8=nwg5P<@))Cf1V94es26$+r(NdkA~;68 QX7Ln>iMsj5vw_f$Mi_}R-T(jq diff --git a/Editor/ProjectGeneration/ProjectGeneration.cs b/Editor/ProjectGeneration/ProjectGeneration.cs index 2a14ae1..df9b2da 100644 --- a/Editor/ProjectGeneration/ProjectGeneration.cs +++ b/Editor/ProjectGeneration/ProjectGeneration.cs @@ -55,8 +55,8 @@ public class ProjectGeneration : IGenerator static readonly string[] k_ReimportSyncExtensions = { ".dll", ".asmdef" }; - string[] m_ProjectSupportedExtensions = Array.Empty(); - string[] m_BuiltinSupportedExtensions = Array.Empty(); + HashSet m_ProjectSupportedExtensions = new HashSet(); + HashSet m_BuiltinSupportedExtensions = new HashSet(); readonly string m_ProjectName; readonly IAssemblyNameProvider m_AssemblyNameProvider; @@ -217,8 +217,8 @@ public bool HasSolutionBeenGenerated() private void SetupProjectSupportedExtensions() { - m_ProjectSupportedExtensions = m_AssemblyNameProvider.ProjectSupportedExtensions; - m_BuiltinSupportedExtensions = EditorSettings.projectGenerationBuiltinExtensions; + m_ProjectSupportedExtensions = new HashSet(m_AssemblyNameProvider.ProjectSupportedExtensions); + m_BuiltinSupportedExtensions = new HashSet(EditorSettings.projectGenerationBuiltinExtensions); } private bool ShouldFileBePartOfSolution(string file) @@ -246,24 +246,30 @@ private static string GetExtensionWithoutDot(string path) public bool IsSupportedFile(string path) { - var extension = GetExtensionWithoutDot(path); + return IsSupportedFile(path, out _); + } + + private bool IsSupportedFile(string path, out string extensionWithoutDot) + { + extensionWithoutDot = GetExtensionWithoutDot(path); // Dll's are not scripts but still need to be included - if (extension == "dll") + if (extensionWithoutDot == "dll") return true; - if (extension == "asmdef") + if (extensionWithoutDot == "asmdef") return true; - if (m_BuiltinSupportedExtensions.Contains(extension)) + if (m_BuiltinSupportedExtensions.Contains(extensionWithoutDot)) return true; - if (m_ProjectSupportedExtensions.Contains(extension)) + if (m_ProjectSupportedExtensions.Contains(extensionWithoutDot)) return true; return false; } + private static ScriptingLanguage ScriptingLanguageFor(Assembly assembly) { var files = assembly.sourceFiles; @@ -271,12 +277,17 @@ private static ScriptingLanguage ScriptingLanguageFor(Assembly assembly) if (files.Length == 0) return ScriptingLanguage.None; - return ScriptingLanguageFor(files[0]); + return ScriptingLanguageForFile(files[0]); } - internal static ScriptingLanguage ScriptingLanguageFor(string path) + internal static ScriptingLanguage ScriptingLanguageForExtension(string extensionWithoutDot) { - return GetExtensionWithoutDot(path) == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None; + return extensionWithoutDot == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None; + } + + internal static ScriptingLanguage ScriptingLanguageForFile(string path) + { + return ScriptingLanguageForExtension(GetExtensionWithoutDot(path)); } public void GenerateAndWriteSolutionAndProjects() @@ -336,7 +347,7 @@ private Dictionary GenerateAllAssetProjectParts() continue; } - if (IsSupportedFile(asset) && ScriptingLanguage.None == ScriptingLanguageFor(asset)) + if (IsSupportedFile(asset, out var extensionWithoutDot) && ScriptingLanguage.None == ScriptingLanguageForExtension(extensionWithoutDot)) { // Find assembly the asset belongs to by adding script extension and using compilation pipeline. var assemblyName = m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset); @@ -354,7 +365,7 @@ private Dictionary GenerateAllAssetProjectParts() stringBuilders[assemblyName] = projectBuilder; } - projectBuilder.Append(" ").Append(k_WindowsNewline); + IncludeAsset(projectBuilder, "None", asset); } } @@ -366,6 +377,26 @@ private Dictionary GenerateAllAssetProjectParts() return result; } + private void IncludeAsset(StringBuilder builder, string tag, string asset) + { + var filename = EscapedRelativePathFor(asset, out var packageInfo); + + builder.Append($" <{tag} Include=\"").Append(filename); + if (Path.IsPathRooted(filename) && packageInfo != null) + { + // We are outside the Unity project and using a package context + var linkPath = SkipPathPrefix(asset.NormalizePathSeparators(), packageInfo.assetPath.NormalizePathSeparators()); + + builder.Append("\">").Append(k_WindowsNewline); + builder.Append(" ").Append(linkPath).Append("").Append(k_WindowsNewline); + builder.Append($" ").Append(k_WindowsNewline); + } + else + { + builder.Append("\" />").Append(k_WindowsNewline); + } + } + private void SyncProject( Assembly assembly, Dictionary allAssetsProjectParts, @@ -479,17 +510,16 @@ private string ProjectText(Assembly assembly, projectBuilder.Append(@" ").Append(k_WindowsNewline); foreach (string file in assembly.sourceFiles) { - if (!IsSupportedFile(file)) + if (!IsSupportedFile(file, out var extensionWithoutDot)) continue; - var extension = Path.GetExtension(file).ToLower(); - var fullFile = EscapedRelativePathFor(file); - if (".dll" != extension) + if ("dll" != extensionWithoutDot) { - projectBuilder.Append(" ").Append(k_WindowsNewline); + IncludeAsset(projectBuilder, "Compile", file); } else { + var fullFile = EscapedRelativePathFor(file, out _); references.Add(fullFile); } } @@ -564,7 +594,7 @@ private static string XmlEscape(string s) private void AppendReference(string fullReference, StringBuilder projectBuilder) { - var escapedFullPath = EscapedRelativePathFor(fullReference); + var escapedFullPath = EscapedRelativePathFor(fullReference, out _); projectBuilder.Append(" ").Append(k_WindowsNewline); projectBuilder.Append(" ").Append(escapedFullPath).Append("").Append(k_WindowsNewline); projectBuilder.Append(" ").Append(k_WindowsNewline); @@ -924,13 +954,13 @@ private string GetProjectActiveConfigurations(string projectGuid) projectGuid); } - private string EscapedRelativePathFor(string file) + private string EscapedRelativePathFor(string file, out UnityEditor.PackageManager.PackageInfo packageInfo) { var projectDir = ProjectDirectory.NormalizePathSeparators(); file = file.NormalizePathSeparators(); var path = SkipPathPrefix(file, projectDir); - var packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.Replace('\\', '/')); + packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.NormalizeWindowsToUnix()); if (packageInfo != null) { // We have to normalize the path, because the PackageManagerRemapper assumes diff --git a/Editor/VisualStudioEditor.cs b/Editor/VisualStudioEditor.cs index 20e3d3b..4284d65 100644 --- a/Editor/VisualStudioEditor.cs +++ b/Editor/VisualStudioEditor.cs @@ -63,6 +63,8 @@ private static IVisualStudioInstallation[] DiscoverInstallations() internal static bool IsEnabled => CodeEditor.CurrentEditor is VisualStudioEditor && UnityInstallation.IsMainUnityEditorProcess; + // this one seems legacy and not used anymore + // keeping it for now given it is public, so we need a major bump to remove it public void CreateIfDoesntExist() { if (!_generator.HasSolutionBeenGenerated()) @@ -260,7 +262,7 @@ private bool IsProjectGeneratedFor(string path, out ProjectGenerationFlag missin return true; // We only want to check for cs scripts - if (ProjectGeneration.ScriptingLanguageFor(path) != ScriptingLanguage.CSharp) + if (ProjectGeneration.ScriptingLanguageForFile(path) != ScriptingLanguage.CSharp) return true; // Even on windows, the package manager requires relative path + unix style separators for queries @@ -357,31 +359,14 @@ bool OpenOSXApp(string path, int line, int column) absolutePath = Path.GetFullPath(path); } - string solution = GetOrGenerateSolutionFile(path); + var solution = GetOrGenerateSolutionFile(path); return OpenVisualStudio(CodeEditor.CurrentEditorInstallation, solution, absolutePath, line); } private string GetOrGenerateSolutionFile(string path) { - var solution = GetSolutionFile(path); - if (solution == "") - { - _generator.Sync(); - solution = GetSolutionFile(path); - } - - return solution; - } - - string GetSolutionFile(string path) - { - var solutionFile = _generator.SolutionFile(); - if (File.Exists(solutionFile)) - { - return solutionFile; - } - - return ""; + _generator.Sync(); + return _generator.SolutionFile(); } } } diff --git a/package.json b/package.json index b9269f1..22a1ac7 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,24 @@ "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": "2.0.14", + "version": "2.0.15", "unity": "2019.4", "unityRelease": "25f1", "dependencies": { "com.unity.test-framework": "1.1.9" }, "relatedPackages": { - "com.unity.ide.visualstudio.tests": "2.0.14" + "com.unity.ide.visualstudio.tests": "2.0.15" + }, + "upm": { + "changelog": "Integration:\n\n- Improved project generation performance.\n- Added support for keeping file/folder structure when working with external packages.\n- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor." }, "upmCi": { - "footprint": "8aa1049966a0586c636698ec81d764940b1dbe44" + "footprint": "d5d60c3083dbc14a4be33dc1f8c4e7fe147ffb74" }, "repository": { "url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git", "type": "git", - "revision": "f1e8af5df9e2507088a8622d173c9a7d5a03a882" + "revision": "ca1ece42f5a2c5484ba15a15bb975ccc1f6a1a3c" } }