com.unity.ide.visualstudio@2.0.22

## [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.
This commit is contained in:
Unity Technologies
2023-10-03 00:00:00 +00:00
parent 9fed958a9e
commit b28f5a3cbf
15 changed files with 203 additions and 80 deletions

View File

@@ -66,13 +66,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static bool IsCandidateForDiscovery(string path)
{
if (VisualStudioEditor.IsOSX)
return Directory.Exists(path) && Regex.IsMatch(path, ".*Code.*.app$", RegexOptions.IgnoreCase);
if (VisualStudioEditor.IsWindows)
return File.Exists(path) && Regex.IsMatch(path, ".*Code.*.exe$", RegexOptions.IgnoreCase);
#if UNITY_EDITOR_OSX
return Directory.Exists(path) && Regex.IsMatch(path, ".*Code.*.app$", RegexOptions.IgnoreCase);
#elif UNITY_EDITOR_WIN
return File.Exists(path) && Regex.IsMatch(path, ".*Code.*.exe$", RegexOptions.IgnoreCase);
#else
return File.Exists(path) && path.EndsWith("code", StringComparison.OrdinalIgnoreCase);
#endif
}
[Serializable]
@@ -99,17 +99,23 @@ namespace Microsoft.Unity.VisualStudio.Editor
{
var manifestBase = GetRealPath(editorPath);
if (VisualStudioEditor.IsWindows) // on Windows, editorPath is a file, resources as subdirectory
manifestBase = IOPath.GetDirectoryName(manifestBase);
else if (VisualStudioEditor.IsOSX) // on Mac, editorPath is a directory
manifestBase = IOPath.Combine(manifestBase, "Contents");
else // on Linux, editorPath is a file, in a bin sub-directory
manifestBase = Directory.GetParent(manifestBase)?.Parent?.FullName;
#if UNITY_EDITOR_WIN
// on Windows, editorPath is a file, resources as subdirectory
manifestBase = IOPath.GetDirectoryName(manifestBase);
#elif UNITY_EDITOR_OSX
// on Mac, editorPath is a directory
manifestBase = IOPath.Combine(manifestBase, "Contents");
#else
// on Linux, editorPath is a file, in a bin sub-directory
var parent = Directory.GetParent(manifestBase);
// but we can link to [vscode]/code or [vscode]/bin/code
manifestBase = parent?.Name == "bin" ? parent.Parent?.FullName : parent?.FullName;
#endif
if (manifestBase == null)
return false;
var manifestFullPath = IOPath.Combine(manifestBase, @"resources", "app", "package.json");
var manifestFullPath = IOPath.Combine(manifestBase, "resources", "app", "package.json");
if (File.Exists(manifestFullPath))
{
var manifest = JsonUtility.FromJson<VisualStudioCodeManifest>(File.ReadAllText(manifestFullPath));
@@ -138,30 +144,29 @@ namespace Microsoft.Unity.VisualStudio.Editor
{
var candidates = new List<string>();
if (VisualStudioEditor.IsWindows)
{
var localAppPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs");
var programFiles = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
#if UNITY_EDITOR_WIN
var localAppPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs");
var programFiles = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
foreach (var basePath in new[] {localAppPath, programFiles})
{
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code", "Code.exe"));
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code Insiders", "Code - Insiders.exe"));
}
}
else if (VisualStudioEditor.IsOSX)
foreach (var basePath in new[] {localAppPath, programFiles})
{
var appPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
candidates.AddRange(Directory.EnumerateDirectories(appPath, "Visual Studio Code*.app"));
}
else
{
candidates.Add("/usr/bin/code");
candidates.Add("/bin/code");
candidates.Add("/usr/local/bin/code");
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code", "Code.exe"));
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code Insiders", "Code - Insiders.exe"));
}
#elif UNITY_EDITOR_OSX
var appPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
candidates.AddRange(Directory.EnumerateDirectories(appPath, "Visual Studio Code*.app"));
#elif UNITY_EDITOR_LINUX
// Well known locations
candidates.Add("/usr/bin/code");
candidates.Add("/bin/code");
candidates.Add("/usr/local/bin/code");
foreach (var candidate in candidates)
// Preference ordered base directories relative to which desktop files should be searched
candidates.AddRange(GetXdgCandidates());
#endif
foreach (var candidate in candidates.Distinct())
{
if (TryDiscoverInstallation(candidate, out var installation))
yield return installation;
@@ -169,6 +174,41 @@ namespace Microsoft.Unity.VisualStudio.Editor
}
#if UNITY_EDITOR_LINUX
private static readonly Regex DesktopFileExecEntry = new Regex(@"Exec=(\S+)", RegexOptions.Singleline | RegexOptions.Compiled);
private static IEnumerable<string> GetXdgCandidates()
{
var envdirs = Environment.GetEnvironmentVariable("XDG_DATA_DIRS");
if (string.IsNullOrEmpty(envdirs))
yield break;
var dirs = envdirs.Split(':');
foreach(var dir in dirs)
{
Match match = null;
try
{
var desktopFile = IOPath.Combine(dir, "applications/code.desktop");
if (!File.Exists(desktopFile))
continue;
var content = File.ReadAllText(desktopFile);
match = DesktopFileExecEntry.Match(content);
}
catch
{
// do not fail if we cannot read desktop file
}
if (match == null || !match.Success)
continue;
yield return match.Groups[1].Value;
break;
}
}
[System.Runtime.InteropServices.DllImport ("libc")]
private static extern int readlink(string path, byte[] buffer, int buflen);
@@ -475,13 +515,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static ProcessStartInfo ProcessStartInfoFor(string application, string arguments)
{
if (!VisualStudioEditor.IsOSX)
return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect: false);
#if UNITY_EDITOR_OSX
// wrap with built-in OSX open feature
arguments = $"-n \"{application}\" --args {arguments}";
application = "open";
return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect:false, shell: true);
#else
return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect: false);
#endif
}
public static void Initialize()