com.unity.ide.visualstudio@2.0.5

## [2.0.5] - 2020-10-30

Integration:

Disable legacy pdb symbol checking for Unity packages
This commit is contained in:
Unity Technologies
2020-10-30 00:00:00 +00:00
parent 32027b422b
commit 08ab0fbd80
25 changed files with 1429 additions and 1105 deletions

4
Editor/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,4 @@
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("Unity.VisualStudio.EditorTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d791d407901442e49862d3aa783ce8af
timeCreated: 1602756877

View File

@@ -15,7 +15,10 @@ namespace Microsoft.Unity.VisualStudio.Editor
{
internal static class Discovery
{
public static IEnumerable<VisualStudioInstallation> GetVisualStudioInstallations()
internal const string ManagedWorkload = "Microsoft.VisualStudio.Workload.ManagedGame";
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
{
if (VisualStudioEditor.IsWindows)
{
@@ -45,7 +48,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
return false;
}
public static bool TryDiscoverInstallation(string editorPath, out VisualStudioInstallation installation)
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation)
{
installation = null;
@@ -61,7 +64,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
// On Mac we use the .app folder, so we need to access to main assembly
if (VisualStudioEditor.IsOSX)
fvi = Path.Combine(editorPath, "Contents", "Resources", "lib", "monodevelop", "bin", "VisualStudio.exe");
if (!File.Exists(fvi))
return false;
@@ -82,7 +85,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
}
#region VsWhere Json Schema
#pragma warning disable CS0649
#pragma warning disable CS0649
[Serializable]
internal class VsWhereResult
{
@@ -95,7 +98,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
public IEnumerable<VisualStudioInstallation> ToVisualStudioInstallations()
{
foreach(var entry in entries)
foreach (var entry in entries)
{
yield return new VisualStudioInstallation()
{
@@ -123,7 +126,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
public string productDisplayVersion; // non parseable like "16.3.0 Preview 3.0"
public string buildVersion;
}
#pragma warning restore CS3021
#pragma warning restore CS3021
#endregion
private static IEnumerable<VisualStudioInstallation> QueryVsWhere()

View File

@@ -49,6 +49,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString());
}
public static string NormalizeWindowsToUnix(string path)
{
if (string.IsNullOrEmpty(path))
return path;
return path.Replace(WinSeparator, UnixSeparator);
}
internal static bool IsFileInProjectDirectory(string fileName)
{
var basePath = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));

View File

@@ -7,28 +7,29 @@ using System.IO;
namespace Microsoft.Unity.VisualStudio.Editor
{
public sealed class Image : IDisposable {
public sealed class Image : IDisposable
{
long position;
Stream stream;
Image (Stream stream)
Image(Stream stream)
{
this.stream = stream;
this.position = stream.Position;
this.stream.Position = 0;
}
bool Advance (int length)
bool Advance(int length)
{
if (stream.Position + length >= stream.Length)
return false;
stream.Seek (length, SeekOrigin.Current);
stream.Seek(length, SeekOrigin.Current);
return true;
}
bool MoveTo (uint position)
bool MoveTo(uint position)
{
if (position >= stream.Length)
return false;
@@ -37,65 +38,65 @@ namespace Microsoft.Unity.VisualStudio.Editor
return true;
}
void IDisposable.Dispose ()
void IDisposable.Dispose()
{
stream.Position = position;
}
ushort ReadUInt16 ()
ushort ReadUInt16()
{
return (ushort) (stream.ReadByte ()
| (stream.ReadByte () << 8));
return (ushort)(stream.ReadByte()
| (stream.ReadByte() << 8));
}
uint ReadUInt32 ()
uint ReadUInt32()
{
return (uint) (stream.ReadByte ()
| (stream.ReadByte () << 8)
| (stream.ReadByte () << 16)
| (stream.ReadByte () << 24));
return (uint)(stream.ReadByte()
| (stream.ReadByte() << 8)
| (stream.ReadByte() << 16)
| (stream.ReadByte() << 24));
}
bool IsManagedAssembly ()
bool IsManagedAssembly()
{
if (stream.Length < 318)
return false;
if (ReadUInt16 () != 0x5a4d)
if (ReadUInt16() != 0x5a4d)
return false;
if (!Advance (58))
if (!Advance(58))
return false;
if (!MoveTo (ReadUInt32 ()))
if (!MoveTo(ReadUInt32()))
return false;
if (ReadUInt32 () != 0x00004550)
if (ReadUInt32() != 0x00004550)
return false;
if (!Advance (20))
if (!Advance(20))
return false;
if (!Advance (ReadUInt16 () == 0x20b ? 222 : 206))
if (!Advance(ReadUInt16() == 0x20b ? 222 : 206))
return false;
return ReadUInt32 () != 0;
return ReadUInt32() != 0;
}
public static bool IsAssembly (string file)
public static bool IsAssembly(string file)
{
if (file == null)
throw new ArgumentNullException ("file");
throw new ArgumentNullException("file");
using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read))
return IsAssembly (stream);
using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
return IsAssembly(stream);
}
public static bool IsAssembly (Stream stream)
public static bool IsAssembly(Stream stream)
{
if (stream == null)
throw new ArgumentNullException (nameof(stream));
throw new ArgumentNullException(nameof(stream));
if (!stream.CanRead)
throw new ArgumentException (nameof(stream));
throw new ArgumentException(nameof(stream));
if (!stream.CanSeek)
throw new ArgumentException (nameof(stream));
throw new ArgumentException(nameof(stream));
using (var image = new Image (stream))
return image.IsManagedAssembly ();
using (var image = new Image(stream))
return image.IsManagedAssembly();
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 058b02c03ea09473aab4dc5fc50af1ef
guid: 543eb5eeeb1d5424ca8876b93fad5326
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19B88</string>
<string>19H2</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
@@ -14,6 +14,8 @@
<string>6.0</string>
<key>CFBundleName</key>
<string>AppleEventIntegration</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSupportedPlatforms</key>
@@ -25,17 +27,21 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>10E125</string>
<string>12A7300</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<string>10.15.6</string>
<key>DTSDKBuild</key>
<string>18E219</string>
<string>19G68</string>
<key>DTSDKName</key>
<string>macosx10.14</string>
<string>macosx10.15</string>
<key>DTXcode</key>
<string>1020</string>
<string>1201</string>
<key>DTXcodeBuild</key>
<string>10E125</string>
<string>12A7300</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 Unity. All rights reserved.</string>
</dict>

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 680cf1008b4284eddbb82ec4d76644a1
guid: 29239d79a3471495e9d270601006dad7
DefaultImporter:
externalObjects: {}
userData:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ba4355216f6c44abbb17503872c42c97
guid: e811c7e1c1e9a4b50b237772d317959f
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 4e53c7f7b5c7e4a3d890cb596ed56c22
guid: 9c3599bc139404df2955d3ffd39d60d6
DefaultImporter:
externalObjects: {}
userData:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 11ca2399a9422473eb66bca747f3ad52
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict/>
<key>files2</key>
<dict/>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3379e8bd711774041a330f218af69b7a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,3 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
@@ -7,181 +12,175 @@ using UnityEditor.PackageManager;
namespace Microsoft.Unity.VisualStudio.Editor
{
public interface IAssemblyNameProvider
{
string[] ProjectSupportedExtensions { get; }
string ProjectGenerationRootNamespace { get; }
ProjectGenerationFlag ProjectGenerationFlag { get; }
public interface IAssemblyNameProvider
{
string[] ProjectSupportedExtensions { get; }
string ProjectGenerationRootNamespace { get; }
ProjectGenerationFlag ProjectGenerationFlag { get; }
string GetAssemblyNameFromScriptPath(string path);
string GetAssemblyNameFromScriptPath(string path);
string GetAssemblyName(string assemblyOutputPath, string assemblyName);
bool IsInternalizedPackagePath(string path);
IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution);
IEnumerable<string> GetAllAssetPaths();
UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath);
ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories);
void ToggleProjectGeneration(ProjectGenerationFlag preference);
}
IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution);
IEnumerable<string> GetAllAssetPaths();
UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath);
ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories);
void ToggleProjectGeneration(ProjectGenerationFlag preference);
}
public class AssemblyNameProvider : IAssemblyNameProvider
{
ProjectGenerationFlag m_ProjectGenerationFlag = (ProjectGenerationFlag)EditorPrefs.GetInt(
"unity_project_generation_flag",
(int)(ProjectGenerationFlag.Local | ProjectGenerationFlag.Embedded));
public class AssemblyNameProvider : IAssemblyNameProvider
{
ProjectGenerationFlag m_ProjectGenerationFlag = (ProjectGenerationFlag)EditorPrefs.GetInt(
"unity_project_generation_flag",
(int)(ProjectGenerationFlag.Local | ProjectGenerationFlag.Embedded));
public string[] ProjectSupportedExtensions => EditorSettings.projectGenerationUserExtensions;
public string[] ProjectSupportedExtensions => EditorSettings.projectGenerationUserExtensions;
public string ProjectGenerationRootNamespace => EditorSettings.projectGenerationRootNamespace;
public string ProjectGenerationRootNamespace => EditorSettings.projectGenerationRootNamespace;
public ProjectGenerationFlag ProjectGenerationFlag
{
get => m_ProjectGenerationFlag;
private set
{
EditorPrefs.SetInt("unity_project_generation_flag", (int)value);
m_ProjectGenerationFlag = value;
}
}
public ProjectGenerationFlag ProjectGenerationFlag
{
get => m_ProjectGenerationFlag;
private set
{
EditorPrefs.SetInt("unity_project_generation_flag", (int)value);
m_ProjectGenerationFlag = value;
}
}
public string GetAssemblyNameFromScriptPath(string path)
{
return CompilationPipeline.GetAssemblyNameFromScriptPath(path);
}
public string GetAssemblyNameFromScriptPath(string path)
{
return CompilationPipeline.GetAssemblyNameFromScriptPath(path);
}
public IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution)
{
foreach (var assembly in CompilationPipeline.GetAssemblies())
{
if (assembly.sourceFiles.Any(shouldFileBePartOfSolution))
{
var options = new ScriptCompilerOptions()
{
ResponseFiles = assembly.compilerOptions.ResponseFiles,
AllowUnsafeCode = assembly.compilerOptions.AllowUnsafeCode,
ApiCompatibilityLevel = assembly.compilerOptions.ApiCompatibilityLevel
};
public IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution)
{
foreach (var assembly in CompilationPipeline.GetAssemblies())
{
if (assembly.sourceFiles.Any(shouldFileBePartOfSolution))
{
var options = new ScriptCompilerOptions
{
ResponseFiles = assembly.compilerOptions.ResponseFiles,
AllowUnsafeCode = assembly.compilerOptions.AllowUnsafeCode,
ApiCompatibilityLevel = assembly.compilerOptions.ApiCompatibilityLevel
};
yield return new Assembly(assembly.name, @"Temp\Bin\Debug\",
assembly.sourceFiles, new[] { "DEBUG", "TRACE" }.Concat(assembly.defines).Concat(EditorUserBuildSettings.activeScriptCompilationDefines).ToArray(),
assembly.assemblyReferences,
assembly.compiledAssemblyReferences,
assembly.flags,
yield return new Assembly(assembly.name, @"Temp\Bin\Debug\",
assembly.sourceFiles, new[] { "DEBUG", "TRACE" }.Concat(assembly.defines).Concat(EditorUserBuildSettings.activeScriptCompilationDefines).ToArray(),
assembly.assemblyReferences,
assembly.compiledAssemblyReferences,
assembly.flags,
#if UNITY_2020_2_OR_NEWER
options,
assembly.rootNamespace);
#else
options);
options);
#endif
}
}
}
}
if (ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
{
foreach (var assembly in CompilationPipeline.GetAssemblies(AssembliesType.Player).Where(assembly => assembly.sourceFiles.Any(shouldFileBePartOfSolution)))
{
var options = new ScriptCompilerOptions()
{
ResponseFiles = assembly.compilerOptions.ResponseFiles,
AllowUnsafeCode = assembly.compilerOptions.AllowUnsafeCode,
ApiCompatibilityLevel = assembly.compilerOptions.ApiCompatibilityLevel
};
if (ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
{
foreach (var assembly in CompilationPipeline.GetAssemblies(AssembliesType.Player).Where(assembly => assembly.sourceFiles.Any(shouldFileBePartOfSolution)))
{
var options = new ScriptCompilerOptions
{
ResponseFiles = assembly.compilerOptions.ResponseFiles,
AllowUnsafeCode = assembly.compilerOptions.AllowUnsafeCode,
ApiCompatibilityLevel = assembly.compilerOptions.ApiCompatibilityLevel
};
yield return new Assembly(assembly.name, @"Temp\Bin\Debug\Player\",
assembly.sourceFiles,
new[] { "DEBUG", "TRACE" }.Concat(assembly.defines).ToArray(),
assembly.assemblyReferences,
assembly.compiledAssemblyReferences,
assembly.flags,
yield return
new Assembly(assembly.name, @"Temp\Bin\Debug\Player\",
assembly.sourceFiles,
new[] { "DEBUG", "TRACE" }.Concat(assembly.defines).ToArray(),
assembly.assemblyReferences,
assembly.compiledAssemblyReferences,
assembly.flags,
#if UNITY_2020_2_OR_NEWER
options,
assembly.rootNamespace);
options,
assembly.rootNamespace);
#else
options);
options);
#endif
}
}
}
}
}
}
public string GetCompileOutputPath(string assemblyName)
{
if (assemblyName.EndsWith(".Player", StringComparison.Ordinal))
{
return @"Temp\Bin\Debug\Player\";
}
else
{
return @"Temp\Bin\Debug\";
}
}
public string GetCompileOutputPath(string assemblyName)
{
return assemblyName.EndsWith(".Player", StringComparison.Ordinal) ? @"Temp\Bin\Debug\Player\" : @"Temp\Bin\Debug\";
}
public IEnumerable<string> GetAllAssetPaths()
{
return AssetDatabase.GetAllAssetPaths();
}
public IEnumerable<string> GetAllAssetPaths()
{
return AssetDatabase.GetAllAssetPaths();
}
public UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath)
{
return UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath);
}
public UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath)
{
return UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath);
}
public bool IsInternalizedPackagePath(string path)
{
if (string.IsNullOrEmpty(path.Trim()))
{
return false;
}
var packageInfo = FindForAssetPath(path);
if (packageInfo == null)
{
return false;
}
var packageSource = packageInfo.source;
switch (packageSource)
{
case PackageSource.Embedded:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Embedded);
case PackageSource.Registry:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Registry);
case PackageSource.BuiltIn:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.BuiltIn);
case PackageSource.Unknown:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Unknown);
case PackageSource.Local:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Local);
case PackageSource.Git:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Git);
case PackageSource.LocalTarball:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.LocalTarBall);
}
public bool IsInternalizedPackagePath(string path)
{
if (string.IsNullOrEmpty(path.Trim()))
{
return false;
}
var packageInfo = FindForAssetPath(path);
if (packageInfo == null)
{
return false;
}
var packageSource = packageInfo.source;
switch (packageSource)
{
case PackageSource.Embedded:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Embedded);
case PackageSource.Registry:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Registry);
case PackageSource.BuiltIn:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.BuiltIn);
case PackageSource.Unknown:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Unknown);
case PackageSource.Local:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Local);
case PackageSource.Git:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.Git);
case PackageSource.LocalTarball:
return !ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.LocalTarBall);
}
return false;
}
return false;
}
public ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories)
{
return CompilationPipeline.ParseResponseFile(
responseFilePath,
projectDirectory,
systemReferenceDirectories
);
}
public ResponseFileData ParseResponseFile(string responseFilePath, string projectDirectory, string[] systemReferenceDirectories)
{
return CompilationPipeline.ParseResponseFile(
responseFilePath,
projectDirectory,
systemReferenceDirectories
);
}
public void ToggleProjectGeneration(ProjectGenerationFlag preference)
{
if (ProjectGenerationFlag.HasFlag(preference))
{
ProjectGenerationFlag ^= preference;
}
else
{
ProjectGenerationFlag |= preference;
}
}
public void ToggleProjectGeneration(ProjectGenerationFlag preference)
{
if (ProjectGenerationFlag.HasFlag(preference))
{
ProjectGenerationFlag ^= preference;
}
else
{
ProjectGenerationFlag |= preference;
}
}
public void ResetProjectGenerationFlag()
{
ProjectGenerationFlag = ProjectGenerationFlag.None;
}
public void ResetProjectGenerationFlag()
{
ProjectGenerationFlag = ProjectGenerationFlag.None;
}
public string GetAssemblyName(string assemblyOutputPath, string assemblyName)
{

View File

@@ -1,31 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.IO;
using System.Text;
namespace Microsoft.Unity.VisualStudio.Editor
{
public interface IFileIO
{
bool Exists(string fileName);
public interface IFileIO
{
bool Exists(string fileName);
string ReadAllText(string fileName);
void WriteAllText(string fileName, string content);
}
string ReadAllText(string fileName);
void WriteAllText(string fileName, string content);
}
class FileIOProvider : IFileIO
{
public bool Exists(string fileName)
{
return File.Exists(fileName);
}
class FileIOProvider : IFileIO
{
public bool Exists(string fileName)
{
return File.Exists(fileName);
}
public string ReadAllText(string fileName)
{
return File.ReadAllText(fileName);
}
public string ReadAllText(string fileName)
{
return File.ReadAllText(fileName);
}
public void WriteAllText(string fileName, string content)
{
File.WriteAllText(fileName, content, Encoding.UTF8);
}
}
}
public void WriteAllText(string fileName, string content)
{
File.WriteAllText(fileName, content, Encoding.UTF8);
}
}
}

View File

@@ -1,21 +1,26 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
namespace Microsoft.Unity.VisualStudio.Editor
{
public interface IGUIDGenerator
{
string ProjectGuid(string projectName, string assemblyName);
string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage);
}
public interface IGUIDGenerator
{
string ProjectGuid(string projectName, string assemblyName);
string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage);
}
class GUIDProvider : IGUIDGenerator
{
public string ProjectGuid(string projectName, string assemblyName)
{
return SolutionGuidGenerator.GuidForProject(projectName + assemblyName);
}
class GUIDProvider : IGUIDGenerator
{
public string ProjectGuid(string projectName, string assemblyName)
{
return SolutionGuidGenerator.GuidForProject(projectName + assemblyName);
}
public string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage)
{
return SolutionGuidGenerator.GuidForSolution(projectName, scriptingLanguage);
}
}
}
public string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage)
{
return SolutionGuidGenerator.GuidForSolution(projectName, scriptingLanguage);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
namespace Microsoft.Unity.VisualStudio.Editor
{

View File

@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace Microsoft.Unity.VisualStudio.Editor

View File

@@ -7,7 +7,6 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using Unity.CodeEditor;
@@ -18,14 +17,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
[InitializeOnLoad]
public class VisualStudioEditor : IExternalCodeEditor
{
private static readonly VisualStudioInstallation[] _installations;
private static readonly IVisualStudioInstallation[] _installations;
internal static bool IsOSX => Application.platform == RuntimePlatform.OSXEditor;
internal static bool IsWindows => !IsOSX && Path.DirectorySeparatorChar == '\\' && Environment.NewLine == "\r\n";
internal static bool IsWindows => !IsOSX && Path.DirectorySeparatorChar == FileUtility.WinSeparator && Environment.NewLine == "\r\n";
CodeEditor.Installation[] IExternalCodeEditor.Installations => _installations
.Select(i => i.ToCodeEditorInstallation())
.ToArray();
.ToArray();
private readonly IGenerator _generator = new ProjectGeneration();
@@ -39,7 +38,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
}
catch (Exception ex)
{
UnityEngine.Debug.Log($"Error detecting Visual Studio installations: {ex}");
UnityEngine.Debug.LogError($"Error detecting Visual Studio installations: {ex}");
_installations = Array.Empty<VisualStudioInstallation>();
}
@@ -64,7 +63,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
{
}
internal bool TryGetVisualStudioInstallationForPath(string editorPath, out VisualStudioInstallation installation)
internal virtual bool TryGetVisualStudioInstallationForPath(string editorPath, out IVisualStudioInstallation installation)
{
// lookup for well known installations
foreach (var candidate in _installations)
@@ -79,7 +78,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
return Discovery.TryDiscoverInstallation(editorPath, out installation);
}
public bool TryGetInstallationForPath(string editorPath, out CodeEditor.Installation installation)
public virtual bool TryGetInstallationForPath(string editorPath, out CodeEditor.Installation installation)
{
var result = TryGetVisualStudioInstallationForPath(editorPath, out var vsi);
installation = vsi == null ? default : vsi.ToCodeEditorInstallation();
@@ -117,14 +116,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
}
void RegenerateProjectFiles()
{
var rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(new GUILayoutOption[] {}));
rect.width = 252;
if (GUI.Button(rect, "Regenerate project files"))
{
_generator.Sync();
}
}
{
var rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(new GUILayoutOption[] { }));
rect.width = 252;
if (GUI.Button(rect, "Regenerate project files"))
{
_generator.Sync();
}
}
void SettingsButton(ProjectGenerationFlag preference, string guiMessage, string toolTip)
{
@@ -143,8 +142,12 @@ namespace Microsoft.Unity.VisualStudio.Editor
foreach (var file in importedFiles.Where(a => Path.GetExtension(a) == ".pdb"))
{
var pdbFile = FileUtility.GetAssetFullPath(file);
var asmFile = Path.ChangeExtension(pdbFile, ".dll");
// skip Unity packages like com.unity.ext.nunit
if (pdbFile.IndexOf($"{Path.DirectorySeparatorChar}com.unity.", StringComparison.OrdinalIgnoreCase) > 0)
continue;
var asmFile = Path.ChangeExtension(pdbFile, ".dll");
if (!File.Exists(asmFile) || !Image.IsAssembly(asmFile))
continue;
@@ -176,11 +179,31 @@ namespace Microsoft.Unity.VisualStudio.Editor
return false;
}
private static void CheckCurrentEditorInstallation()
{
var editorPath = CodeEditor.CurrentEditorInstallation;
try
{
if (Discovery.TryDiscoverInstallation(editorPath, out _))
return;
}
catch (IOException)
{
}
UnityEngine.Debug.LogWarning($"Visual Studio executable {editorPath} is not found. Please change your settings in Edit > Preferences > External Tools.");
}
public bool OpenProject(string path, int line, int column)
{
CheckCurrentEditorInstallation();
if (!IsSupportedPath(path))
return false;
if (!IsProjectGeneratedFor(path, out var missingFlag))
UnityEngine.Debug.LogWarning($"You are trying to open {path} outside a generated project. This might cause problems with IntelliSense and debugging. To avoid this, you can change your .csproj preferences in Edit > Preferences > External Tools and enable {GetProjectGenerationFlagDescription(missingFlag)} generation.");
if (IsOSX)
return OpenOSXApp(path, line, column);
@@ -190,6 +213,67 @@ namespace Microsoft.Unity.VisualStudio.Editor
return false;
}
private static string GetProjectGenerationFlagDescription(ProjectGenerationFlag flag)
{
switch (flag)
{
case ProjectGenerationFlag.BuiltIn:
return "Built-in packages";
case ProjectGenerationFlag.Embedded:
return "Embedded packages";
case ProjectGenerationFlag.Git:
return "Git packages";
case ProjectGenerationFlag.Local:
return "Local packages";
case ProjectGenerationFlag.LocalTarBall:
return "Local tarball";
case ProjectGenerationFlag.PlayerAssemblies:
return "Player projects";
case ProjectGenerationFlag.Registry:
return "Registry packages";
case ProjectGenerationFlag.Unknown:
return "Packages from unknown sources";
case ProjectGenerationFlag.None:
default:
return string.Empty;
}
}
private bool IsProjectGeneratedFor(string path, out ProjectGenerationFlag missingFlag)
{
missingFlag = ProjectGenerationFlag.None;
// No need to check when opening the whole solution
if (string.IsNullOrEmpty(path))
return true;
// We only want to check for cs scripts
if (ProjectGeneration.ScriptingLanguageFor(path) != ScriptingLanguage.CSharp)
return true;
// Even on windows, the package manager requires relative path + unix style separators for queries
var basePath = _generator.ProjectDirectory;
var relativePath = FileUtility
.NormalizeWindowsToUnix(path)
.Replace(basePath, string.Empty)
.Trim(FileUtility.UnixSeparator);
var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(relativePath);
if (packageInfo == null)
return true;
var source = packageInfo.source;
if (!Enum.TryParse<ProjectGenerationFlag>(source.ToString(), out var flag))
return true;
if (_generator.AssemblyNameProvider.ProjectGenerationFlag.HasFlag(flag))
return true;
// Return false if we found a source not flagged for generation
missingFlag = flag;
return false;
}
private bool OpenWindowsApp(string path, int line)
{
var progpath = FileUtility

View File

@@ -10,7 +10,16 @@ using IOPath = System.IO.Path;
namespace Microsoft.Unity.VisualStudio.Editor
{
internal class VisualStudioInstallation
internal interface IVisualStudioInstallation
{
string Path { get; }
bool SupportsAnalyzers { get; }
bool SupportsCSharp8 { get; }
string[] GetAnalyzers();
CodeEditor.Installation ToCodeEditorInstallation();
}
internal class VisualStudioInstallation : IVisualStudioInstallation
{
public string Name { get; set; }
public string Path { get; set; }

View File

@@ -33,8 +33,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
// - if another application is using this port with exclusive access
// - or if the firewall is not properly configured
var messagingPort = MessagingPort();
try {
try
{
_messager = Messager.BindTo(messagingPort);
_messager.ReceiveMessage += ReceiveMessage;
}
@@ -155,7 +156,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
// If the user disabled auto-refresh in Unity, do not try to force refresh the Asset database
if (!EditorPrefs.GetBool("kAutoRefresh", true))
return;
RunOnceOnUpdate(AssetDatabase.Refresh);
}