diff --git a/Packages/com.unity.ide.visualstudio.tests/package.json b/Packages/com.unity.ide.visualstudio.tests/package.json index d3258dd..6bd552d 100644 --- a/Packages/com.unity.ide.visualstudio.tests/package.json +++ b/Packages/com.unity.ide.visualstudio.tests/package.json @@ -3,7 +3,7 @@ "name": "com.unity.ide.visualstudio.tests", "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.21", + "version": "2.0.22", "unity": "2019.4", "unityRelease": "25f1", "dependencies": { diff --git a/Packages/com.unity.ide.visualstudio/CHANGELOG.md b/Packages/com.unity.ide.visualstudio/CHANGELOG.md index 11c0ada..0daa3e5 100644 --- a/Packages/com.unity.ide.visualstudio/CHANGELOG.md +++ b/Packages/com.unity.ide.visualstudio/CHANGELOG.md @@ -1,5 +1,20 @@ # Code Editor Package for Visual Studio +## [2.0.22] - 2023-10-03 + +Integration: + +- Add support for `XDG_DATA_DIRS` and `.desktop` files on Linux for `VS Code` discovery. +- Use compile-time platform-specifics instead of using runtime conditions. + +Project generation: + +- Suppress `USG0001` warnings. +- Mark referenced assemblies as private (to not copy extra files to output directory when building). +- Add Unity capability to SDK-Style projects. +- Prevent circular dependency errors with SDK-Style projects. + + ## [2.0.21] - 2023-09-05 Integration: diff --git a/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/AssemblyNameProvider.cs b/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/AssemblyNameProvider.cs index 5e568de..6e0502c 100644 --- a/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/AssemblyNameProvider.cs +++ b/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/AssemblyNameProvider.cs @@ -151,31 +151,39 @@ public bool IsInternalizedPackagePath(string path) { return false; } + var packageInfo = FindForAssetPath(path); if (packageInfo == null) { return false; } - var packageSource = packageInfo.source; + + var flag = ProjectGenerationFlagFromPackageSource(packageInfo.source); + + return flag != ProjectGenerationFlag.None && !ProjectGenerationFlag.HasFlag(flag); + } + + private static ProjectGenerationFlag ProjectGenerationFlagFromPackageSource(PackageSource packageSource) + { switch (packageSource) { case PackageSource.Embedded: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Embedded); + return ProjectGenerationFlag.Embedded; case PackageSource.Registry: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Registry); + return ProjectGenerationFlag.Registry; case PackageSource.BuiltIn: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.BuiltIn); + return ProjectGenerationFlag.BuiltIn; case PackageSource.Unknown: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Unknown); + return ProjectGenerationFlag.Unknown; case PackageSource.Local: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Local); + return ProjectGenerationFlag.Local; case PackageSource.Git: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Git); + return ProjectGenerationFlag.Git; case PackageSource.LocalTarball: - return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.LocalTarBall); + return ProjectGenerationFlag.LocalTarBall; + default: + return ProjectGenerationFlag.None; } - - return false; } public ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories) diff --git a/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs b/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs index 74afcff..c3c7d4c 100644 --- a/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs +++ b/Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs @@ -79,7 +79,7 @@ public ProjectGeneration() : this(Directory.GetParent(Application.dataPath).Full public ProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNameProvider, IFileIO fileIoProvider, IGUIDGenerator guidGenerator) { ProjectDirectory = FileUtility.NormalizeWindowsToUnix(tempDirectory); - m_ProjectName = Path.GetFileName(ProjectDirectory); + m_ProjectName = string.IsNullOrEmpty(PlayerSettings.productName) ? Path.GetFileName(ProjectDirectory) : PlayerSettings.productName; m_AssemblyNameProvider = assemblyNameProvider; m_FileIOProvider = fileIoProvider; m_GUIDGenerator = guidGenerator; @@ -640,7 +640,7 @@ private static IEnumerable GetOtherArguments(ResponseFileData[] response var key = argument .Substring(1, index - 1) .Trim(); - + if (!names.Contains(key)) continue; diff --git a/Packages/com.unity.ide.visualstudio/Editor/VisualStudioCodeInstallation.cs b/Packages/com.unity.ide.visualstudio/Editor/VisualStudioCodeInstallation.cs index aae57a6..887a159 100644 --- a/Packages/com.unity.ide.visualstudio/Editor/VisualStudioCodeInstallation.cs +++ b/Packages/com.unity.ide.visualstudio/Editor/VisualStudioCodeInstallation.cs @@ -56,13 +56,7 @@ public override string[] GetAnalyzers() return GetAnalyzers(vstuPath); } - public override IGenerator ProjectGenerator - { - get - { - return _generator; - } - } + public override IGenerator ProjectGenerator => _generator; private static bool IsCandidateForDiscovery(string path) { @@ -192,7 +186,7 @@ private static IEnumerable GetXdgCandidates() var desktopFile = IOPath.Combine(dir, "applications/code.desktop"); if (!File.Exists(desktopFile)) continue; - + var content = File.ReadAllText(desktopFile); match = DesktopFileExecEntry.Match(content); } @@ -243,7 +237,7 @@ public override void CreateExtraFiles(string projectDirectory) } catch (IOException) { - } + } } private const string DefaultLaunchFileContent = @"{ @@ -302,99 +296,136 @@ private static void PatchLaunchFile(string launchFile) } } + static int Patch(JSONObject jobj,string key,bool value) + { + if(jobj.GetValueOrDefault(key,null) is JSONNode node && node.IsBoolean) + return 0; + + jobj[key] = value; + return 1; + } + private void CreateSettingsFile(string vscodeDirectory, bool enablePatch) { var settingsFile = IOPath.Combine(vscodeDirectory, "settings.json"); - if (File.Exists(settingsFile)) + JSONObject settings = null; + try { - if (enablePatch) - PatchSettingsFile(settingsFile); + if (File.Exists(settingsFile)) + { + if (!enablePatch) + return; - return; + var content = File.ReadAllText(settingsFile); + settings = JSONNode.Parse(content) as JSONObject; + } } + catch + { - const string excludes = @" ""files.exclude"": { - ""**/.DS_Store"": true, - ""**/.git"": true, - ""**/.vs"": true, - ""**/.gitmodules"": true, - ""**/.vsconfig"": true, - ""**/*.booproj"": true, - ""**/*.pidb"": true, - ""**/*.suo"": true, - ""**/*.user"": true, - ""**/*.userprefs"": true, - ""**/*.unityproj"": true, - ""**/*.dll"": true, - ""**/*.exe"": true, - ""**/*.pdf"": true, - ""**/*.mid"": true, - ""**/*.midi"": true, - ""**/*.wav"": true, - ""**/*.gif"": true, - ""**/*.ico"": true, - ""**/*.jpg"": true, - ""**/*.jpeg"": true, - ""**/*.png"": true, - ""**/*.psd"": true, - ""**/*.tga"": true, - ""**/*.tif"": true, - ""**/*.tiff"": true, - ""**/*.3ds"": true, - ""**/*.3DS"": true, - ""**/*.fbx"": true, - ""**/*.FBX"": true, - ""**/*.lxo"": true, - ""**/*.LXO"": true, - ""**/*.ma"": true, - ""**/*.MA"": true, - ""**/*.obj"": true, - ""**/*.OBJ"": true, - ""**/*.asset"": true, - ""**/*.cubemap"": true, - ""**/*.flare"": true, - ""**/*.mat"": true, - ""**/*.meta"": true, - ""**/*.prefab"": true, - ""**/*.unity"": true, - ""build/"": true, - ""Build/"": true, - ""Library/"": true, - ""library/"": true, - ""obj/"": true, - ""Obj/"": true, - ""Logs/"": true, - ""logs/"": true, - ""ProjectSettings/"": true, - ""UserSettings/"": true, - ""temp/"": true, - ""Temp/"": true - }"; - - var content = @"{ -" + excludes + @", - ""dotnet.defaultSolution"": """ + IOPath.GetFileName(ProjectGenerator.SolutionFile()) + @""" -}"; + } - File.WriteAllText(settingsFile, content); - } + string[] commonHiddenFolderExclude = new [] { + ".DS_Store", + ".git", + ".vs", + ".gitmodules", + ".vsconfig", + }; + + string[] commonFileExtensionsExclude = new []{ + "booproj", + "pidb", + "suo", + "user", + "userprefs", + "unityproj", + "dll", + "exe", + "pdf", + }; + + string[] binaryFileExtensionsExclude = new []{ + "mid", + "midi", + "wav", + "gif", + "ico", + "jpg", + "jpeg", + "png", + "psd", + "tga", + "tif", + "tiff", + "3ds", + "3DS", + "fbx", + "FBX", + "lxo", + "LXO", + "ma", + "MA", + "obj", + "OBJ", + "cubemap", + "flare", + }; + + string[] unityFileExtensionsExclude = new []{ + "asset", + "mat", + "meta", + "prefab", + "unity", + }; + + string[] unityFoldersExclude = new [] { + "Build", + "Library", + "Obj", + "Logs", + "ProjectSettings", + "UserSettings", + "Temp" + }; - private void PatchSettingsFile(string settingsFile) - { try { const string excludesKey = "files.exclude"; const string solutionKey = "dotnet.defaultSolution"; - var content = File.ReadAllText(settingsFile); - var settings = JSONNode.Parse(content); + if(settings == null) + settings = new JSONObject(); var excludes = settings[excludesKey] as JSONObject; if (excludes == null) - return; + settings[excludesKey] = excludes = new JSONObject(); + + int patched = 0; + + foreach(string key in commonHiddenFolderExclude) + patched += Patch(excludes,"**/" + key,true); + + foreach(string key in commonFileExtensionsExclude) + patched += Patch(excludes,"**/*." + key,true); + + foreach(string key in binaryFileExtensionsExclude) + patched += Patch(excludes,"**/*." + key,true); + + foreach(string key in unityFileExtensionsExclude) + patched += Patch(excludes,"**/*." + key,true); + + foreach(string key in unityFoldersExclude) + { + string lower = key.ToLower(); + if(key != lower) + patched += Patch(excludes,lower + "/",excludes.GetValueOrDefault(key + "/",true)); + + patched += Patch(excludes,key + "/",true); + } var patchList = new List(); - var patched = false; // Remove files.exclude for solution+project files in the project root foreach (var exclude in excludes) @@ -411,7 +442,7 @@ private void PatchSettingsFile(string settingsFile) continue; patchList.Add(key); - patched = true; + patched++; } // Check default solution @@ -420,20 +451,23 @@ private void PatchSettingsFile(string settingsFile) if (defaultSolution == null || defaultSolution.Value != solutionFile) { settings[solutionKey] = solutionFile; - patched = true; + patched++; } - if (!patched) + if (patched < 1) return; foreach (var patch in patchList) excludes.Remove(patch); WriteAllTextFromJObject(settingsFile, settings); + + UnityEngine.Debug.Log("patch counter : " + patched); } - catch (Exception) + catch (Exception e) { // do not fail if we cannot patch the settings.json file + UnityEngine.Debug.LogException(e); } } @@ -506,7 +540,7 @@ public override bool Open(string path, int line, int column, string solution) var directory = IOPath.GetDirectoryName(solution); var application = Path; - ProcessRunner.Start(string.IsNullOrEmpty(path) ? + ProcessRunner.Start(string.IsNullOrEmpty(path) ? ProcessStartInfoFor(application, $"\"{directory}\"") : ProcessStartInfoFor(application, $"\"{directory}\" -g \"{path}\":{line}:{column}")); diff --git a/Packages/com.unity.ide.visualstudio/package.json b/Packages/com.unity.ide.visualstudio/package.json index 6665c4e..4fbd89c 100644 --- a/Packages/com.unity.ide.visualstudio/package.json +++ b/Packages/com.unity.ide.visualstudio/package.json @@ -2,13 +2,13 @@ "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.21", + "version": "2.0.22", "unity": "2019.4", "unityRelease": "25f1", "dependencies": { "com.unity.test-framework": "1.1.9" }, "relatedPackages": { - "com.unity.ide.visualstudio.tests": "2.0.21" + "com.unity.ide.visualstudio.tests": "2.0.22" } }