You've already forked com.unity.ide.cursor
mirror of
https://github.com/boxqkrtm/com.unity.ide.cursor.git
synced 2026-05-14 14:20:09 +00:00
com.unity.ide.visualstudio@2.0.1
## [2.0.1] - 2020-03-19 When Visual Studio installation is compatible with C# 8.0, setup the language version to not prompt the user with unsupported constructs. (So far Unity only supports C# 7.3). Use Unity's TypeCache to improve project generation speed. Properly check for a managed assembly before displaying a warning regarding legacy PDB usage. Add support for selective project generation (embedded, local, registry, git, builtin, player).
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# Code Editor Package for Visual Studio
|
||||
|
||||
## [2.0.1] - 2020-03-19
|
||||
|
||||
When Visual Studio installation is compatible with C# 8.0, setup the language version to not prompt the user with unsupported constructs. (So far Unity only supports C# 7.3).
|
||||
Use Unity's TypeCache to improve project generation speed.
|
||||
Properly check for a managed assembly before displaying a warning regarding legacy PDB usage.
|
||||
Add support for selective project generation (embedded, local, registry, git, builtin, player).
|
||||
|
||||
|
||||
## [2.0.0] - 2019-11-06
|
||||
|
||||
- Improved Visual Studio and Visual Studio for Mac automatic discovery
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
if (Path.DirectorySeparatorChar == WinSeparator)
|
||||
path = path.Replace(UnixSeparator, WinSeparator);
|
||||
if (Path.DirectorySeparatorChar == UnixSeparator)
|
||||
path = path.Replace(WinSeparator, UnixSeparator);
|
||||
|
||||
return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString());
|
||||
}
|
||||
@@ -57,36 +59,5 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
return string.Equals(Path.GetDirectoryName(fileName), basePath, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static string FileNameWithoutExtension(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
var indexOfDot = -1;
|
||||
var indexOfSlash = 0;
|
||||
for (var i = path.Length - 1; i >= 0; i--)
|
||||
{
|
||||
if (indexOfDot == -1 && path[i] == '.')
|
||||
{
|
||||
indexOfDot = i;
|
||||
}
|
||||
|
||||
if (indexOfSlash == 0 && path[i] == '/' || path[i] == '\\')
|
||||
{
|
||||
indexOfSlash = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (indexOfDot == -1)
|
||||
{
|
||||
indexOfDot = path.Length - 1;
|
||||
}
|
||||
|
||||
return path.Substring(indexOfSlash, indexOfDot - indexOfSlash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
101
Editor/Image.cs
Normal file
101
Editor/Image.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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.IO;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
public sealed class Image : IDisposable {
|
||||
|
||||
long position;
|
||||
Stream stream;
|
||||
|
||||
Image (Stream stream)
|
||||
{
|
||||
this.stream = stream;
|
||||
this.position = stream.Position;
|
||||
this.stream.Position = 0;
|
||||
}
|
||||
|
||||
bool Advance (int length)
|
||||
{
|
||||
if (stream.Position + length >= stream.Length)
|
||||
return false;
|
||||
|
||||
stream.Seek (length, SeekOrigin.Current);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoveTo (uint position)
|
||||
{
|
||||
if (position >= stream.Length)
|
||||
return false;
|
||||
|
||||
stream.Position = position;
|
||||
return true;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose ()
|
||||
{
|
||||
stream.Position = position;
|
||||
}
|
||||
|
||||
ushort ReadUInt16 ()
|
||||
{
|
||||
return (ushort) (stream.ReadByte ()
|
||||
| (stream.ReadByte () << 8));
|
||||
}
|
||||
|
||||
uint ReadUInt32 ()
|
||||
{
|
||||
return (uint) (stream.ReadByte ()
|
||||
| (stream.ReadByte () << 8)
|
||||
| (stream.ReadByte () << 16)
|
||||
| (stream.ReadByte () << 24));
|
||||
}
|
||||
|
||||
bool IsManagedAssembly ()
|
||||
{
|
||||
if (stream.Length < 318)
|
||||
return false;
|
||||
if (ReadUInt16 () != 0x5a4d)
|
||||
return false;
|
||||
if (!Advance (58))
|
||||
return false;
|
||||
if (!MoveTo (ReadUInt32 ()))
|
||||
return false;
|
||||
if (ReadUInt32 () != 0x00004550)
|
||||
return false;
|
||||
if (!Advance (20))
|
||||
return false;
|
||||
if (!Advance (ReadUInt16 () == 0x20b ? 222 : 206))
|
||||
return false;
|
||||
|
||||
return ReadUInt32 () != 0;
|
||||
}
|
||||
|
||||
public static bool IsAssembly (string file)
|
||||
{
|
||||
if (file == null)
|
||||
throw new ArgumentNullException ("file");
|
||||
|
||||
using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
return IsAssembly (stream);
|
||||
}
|
||||
|
||||
public static bool IsAssembly (Stream stream)
|
||||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException (nameof(stream));
|
||||
if (!stream.CanRead)
|
||||
throw new ArgumentException (nameof(stream));
|
||||
if (!stream.CanSeek)
|
||||
throw new ArgumentException (nameof(stream));
|
||||
|
||||
using (var image = new Image (stream))
|
||||
return image.IsManagedAssembly ();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Image.cs.meta
Normal file
11
Editor/Image.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e6c7ea7c059fb547b6723aaf225900b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Editor/ProjectGeneration.meta
Normal file
8
Editor/ProjectGeneration.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8beeeeebc0857854d8b4e2c2895dd7a9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
170
Editor/ProjectGeneration/AssemblyNameProvider.cs
Normal file
170
Editor/ProjectGeneration/AssemblyNameProvider.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEditor.PackageManager;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
public interface IAssemblyNameProvider
|
||||
{
|
||||
string[] ProjectSupportedExtensions { get; }
|
||||
string ProjectGenerationRootNamespace { get; }
|
||||
ProjectGenerationFlag ProjectGenerationFlag { get; }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public class AssemblyNameProvider : IAssemblyNameProvider
|
||||
{
|
||||
ProjectGenerationFlag m_ProjectGenerationFlag = (ProjectGenerationFlag)EditorPrefs.GetInt("unity_project_generation_flag", 0);
|
||||
|
||||
public string[] ProjectSupportedExtensions => EditorSettings.projectGenerationUserExtensions;
|
||||
|
||||
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 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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
compilerOptions =
|
||||
{
|
||||
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)))
|
||||
{
|
||||
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)
|
||||
{
|
||||
compilerOptions =
|
||||
{
|
||||
ResponseFiles = assembly.compilerOptions.ResponseFiles,
|
||||
AllowUnsafeCode = assembly.compilerOptions.AllowUnsafeCode,
|
||||
ApiCompatibilityLevel = assembly.compilerOptions.ApiCompatibilityLevel
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetCompileOutputPath(string assemblyName)
|
||||
{
|
||||
if (assemblyName.EndsWith(".Player", StringComparison.Ordinal))
|
||||
{
|
||||
return @"Temp\Bin\Debug\Player\";
|
||||
}
|
||||
else
|
||||
{
|
||||
return @"Temp\Bin\Debug\";
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllAssetPaths()
|
||||
{
|
||||
return AssetDatabase.GetAllAssetPaths();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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 ResetProjectGenerationFlag()
|
||||
{
|
||||
ProjectGenerationFlag = ProjectGenerationFlag.None;
|
||||
}
|
||||
|
||||
public string GetAssemblyName(string assemblyOutputPath, string assemblyName)
|
||||
{
|
||||
return assemblyOutputPath.EndsWith(@"\Player\", StringComparison.Ordinal) ? assemblyName + ".Player" : assemblyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/ProjectGeneration/AssemblyNameProvider.cs.meta
Normal file
11
Editor/ProjectGeneration/AssemblyNameProvider.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57537f08f8e923f488e4aadabb831c9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Editor/ProjectGeneration/FileIOProvider.cs
Normal file
31
Editor/ProjectGeneration/FileIOProvider.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
public interface IFileIO
|
||||
{
|
||||
bool Exists(string fileName);
|
||||
|
||||
string ReadAllText(string fileName);
|
||||
void WriteAllText(string fileName, string content);
|
||||
}
|
||||
|
||||
class FileIOProvider : IFileIO
|
||||
{
|
||||
public bool Exists(string fileName)
|
||||
{
|
||||
return File.Exists(fileName);
|
||||
}
|
||||
|
||||
public string ReadAllText(string fileName)
|
||||
{
|
||||
return File.ReadAllText(fileName);
|
||||
}
|
||||
|
||||
public void WriteAllText(string fileName, string content)
|
||||
{
|
||||
File.WriteAllText(fileName, content, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/ProjectGeneration/FileIOProvider.cs.meta
Normal file
11
Editor/ProjectGeneration/FileIOProvider.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec80b1fb8938b3b4ab442d10390c5315
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Editor/ProjectGeneration/GUIDProvider.cs
Normal file
21
Editor/ProjectGeneration/GUIDProvider.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public string SolutionGuid(string projectName, ScriptingLanguage scriptingLanguage)
|
||||
{
|
||||
return SolutionGuidGenerator.GuidForSolution(projectName, scriptingLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/ProjectGeneration/GUIDProvider.cs.meta
Normal file
11
Editor/ProjectGeneration/GUIDProvider.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7652904b1008e324fb7cfb952ea87656
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SR = System.Reflection;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@@ -26,50 +27,15 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
CSharp
|
||||
}
|
||||
|
||||
public interface IGenerator {
|
||||
public interface IGenerator
|
||||
{
|
||||
bool SyncIfNeeded(IEnumerable<string> affectedFiles, IEnumerable<string> reimportedFiles);
|
||||
void Sync();
|
||||
bool HasSolutionBeenGenerated();
|
||||
bool IsSupportedFile(string path);
|
||||
string SolutionFile();
|
||||
string ProjectDirectory { get; }
|
||||
void GenerateAll(bool generateAll);
|
||||
bool IsSupportedFile(string path);
|
||||
}
|
||||
|
||||
public interface IAssemblyNameProvider
|
||||
{
|
||||
string GetAssemblyNameFromScriptPath(string path);
|
||||
IEnumerable<Assembly> GetAllAssemblies(Func<string, bool> shouldFileBePartOfSolution);
|
||||
IEnumerable<string> GetAllAssetPaths();
|
||||
UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath);
|
||||
}
|
||||
|
||||
public struct TestSettings {
|
||||
public bool ShouldSync;
|
||||
public Dictionary<string, string> SyncPath;
|
||||
}
|
||||
|
||||
class AssemblyNameProvider : IAssemblyNameProvider
|
||||
{
|
||||
public string GetAssemblyNameFromScriptPath(string path)
|
||||
{
|
||||
return CompilationPipeline.GetAssemblyNameFromScriptPath(path);
|
||||
}
|
||||
|
||||
public IEnumerable<Assembly> GetAllAssemblies(Func<string, bool> shouldFileBePartOfSolution)
|
||||
{
|
||||
return CompilationPipeline.GetAssemblies().Where(i => 0 < i.sourceFiles.Length && i.sourceFiles.Any(shouldFileBePartOfSolution));
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllAssetPaths()
|
||||
{
|
||||
return AssetDatabase.GetAllAssetPaths();
|
||||
}
|
||||
|
||||
public UnityEditor.PackageManager.PackageInfo FindForAssetPath(string assetPath)
|
||||
{
|
||||
return UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath);
|
||||
}
|
||||
IAssemblyNameProvider AssemblyNameProvider { get; }
|
||||
}
|
||||
|
||||
public class ProjectGeneration : IGenerator
|
||||
@@ -99,31 +65,28 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
public string ProjectDirectory { get; }
|
||||
|
||||
public TestSettings Settings { get; set; }
|
||||
|
||||
readonly string m_ProjectName;
|
||||
readonly IAssemblyNameProvider m_AssemblyNameProvider;
|
||||
bool m_ShouldGenerateAll;
|
||||
readonly IFileIO m_FileIOProvider;
|
||||
readonly IGUIDGenerator m_GUIDGenerator;
|
||||
VisualStudioInstallation m_CurrentInstallation;
|
||||
public IAssemblyNameProvider AssemblyNameProvider => m_AssemblyNameProvider;
|
||||
|
||||
public ProjectGeneration() : this(Directory.GetParent(Application.dataPath).FullName, new AssemblyNameProvider())
|
||||
public ProjectGeneration() : this(Directory.GetParent(Application.dataPath).FullName)
|
||||
{
|
||||
}
|
||||
|
||||
public ProjectGeneration(string tempDirectory) : this(tempDirectory, new AssemblyNameProvider()) {
|
||||
public ProjectGeneration(string tempDirectory) : this(tempDirectory, new AssemblyNameProvider(), new FileIOProvider(), new GUIDProvider())
|
||||
{
|
||||
}
|
||||
|
||||
public ProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNameProvider) {
|
||||
Settings = new TestSettings { ShouldSync = true };
|
||||
public ProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNameProvider, IFileIO fileIoProvider, IGUIDGenerator guidGenerator)
|
||||
{
|
||||
ProjectDirectory = tempDirectory.Replace('\\', '/');
|
||||
m_ProjectName = Path.GetFileName(ProjectDirectory);
|
||||
m_AssemblyNameProvider = assemblyNameProvider;
|
||||
|
||||
SetupProjectSupportedExtensions();
|
||||
}
|
||||
|
||||
public void GenerateAll(bool generateAll)
|
||||
{
|
||||
m_ShouldGenerateAll = generateAll;
|
||||
m_FileIOProvider = fileIoProvider;
|
||||
m_GUIDGenerator = guidGenerator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,10 +124,19 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return k_ReimportSyncExtensions.Contains(new FileInfo(asset).Extension);
|
||||
}
|
||||
|
||||
private void RefreshCurrentInstallation()
|
||||
{
|
||||
var editor = CodeEditor.CurrentEditor as VisualStudioEditor;
|
||||
editor?.TryGetVisualStudioInstallationForPath(CodeEditor.CurrentEditorInstallation, out m_CurrentInstallation);
|
||||
}
|
||||
|
||||
public void Sync()
|
||||
{
|
||||
// We need the exact VS version/capabilities to tweak project generation (analyzers/langversion)
|
||||
RefreshCurrentInstallation();
|
||||
|
||||
SetupProjectSupportedExtensions();
|
||||
bool externalCodeAlreadyGeneratedProjects = OnPreGeneratingCSProjectFiles();
|
||||
var externalCodeAlreadyGeneratedProjects = OnPreGeneratingCSProjectFiles();
|
||||
|
||||
if (!externalCodeAlreadyGeneratedProjects)
|
||||
{
|
||||
@@ -175,19 +147,19 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
public bool HasSolutionBeenGenerated()
|
||||
{
|
||||
return File.Exists(SolutionFile());
|
||||
return m_FileIOProvider.Exists(SolutionFile());
|
||||
}
|
||||
|
||||
void SetupProjectSupportedExtensions()
|
||||
{
|
||||
m_ProjectSupportedExtensions = EditorSettings.projectGenerationUserExtensions;
|
||||
m_ProjectSupportedExtensions = m_AssemblyNameProvider.ProjectSupportedExtensions;
|
||||
m_BuiltinSupportedExtensions = EditorSettings.projectGenerationBuiltinExtensions;
|
||||
}
|
||||
|
||||
bool ShouldFileBePartOfSolution(string file)
|
||||
{
|
||||
// Exclude files coming from packages except if they are internalized.
|
||||
if (!m_ShouldGenerateAll && IsInternalizedPackagePath(file))
|
||||
if (m_AssemblyNameProvider.IsInternalizedPackagePath(file))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -227,9 +199,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return false;
|
||||
}
|
||||
|
||||
static ScriptingLanguage ScriptingLanguageFor(Assembly island)
|
||||
static ScriptingLanguage ScriptingLanguageFor(Assembly assembly)
|
||||
{
|
||||
var files = island.sourceFiles;
|
||||
var files = assembly.sourceFiles;
|
||||
|
||||
if (files.Length == 0)
|
||||
return ScriptingLanguage.None;
|
||||
@@ -242,42 +214,22 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return GetExtensionWithoutDot(path) == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None;
|
||||
}
|
||||
|
||||
static List<Type> SafeGetTypes(System.Reflection.Assembly a)
|
||||
{
|
||||
var ret = new List<Type>();
|
||||
|
||||
try
|
||||
{
|
||||
ret = a.GetTypes().ToList();
|
||||
}
|
||||
catch (System.Reflection.ReflectionTypeLoadException rtl)
|
||||
{
|
||||
ret = rtl.Types.ToList();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new List<Type>();
|
||||
}
|
||||
|
||||
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.
|
||||
// Only synchronize assemblies that have associated source files and ones that we actually want in the project.
|
||||
// This also filters out DLLs coming from .asmdef files in packages.
|
||||
var assemblies = m_AssemblyNameProvider.GetAllAssemblies(ShouldFileBePartOfSolution);
|
||||
var assemblies = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
|
||||
|
||||
var allAssetProjectParts = GenerateAllAssetProjectParts();
|
||||
|
||||
var monoIslands = assemblies.ToList();
|
||||
var assemblyList = assemblies.ToList();
|
||||
|
||||
SyncSolution(monoIslands);
|
||||
var allProjectIslands = RelevantIslandsForMode(monoIslands).ToList();
|
||||
foreach (Assembly assembly in allProjectIslands)
|
||||
SyncSolution(assemblyList);
|
||||
var allProjectAssemblies = RelevantAssembliesForMode(assemblyList).ToList();
|
||||
foreach (Assembly assembly in allProjectAssemblies)
|
||||
{
|
||||
var responseFileData = ParseResponseFileData(assembly);
|
||||
SyncProject(assembly, allAssetProjectParts, responseFileData, allProjectIslands);
|
||||
SyncProject(assembly, allAssetProjectParts, responseFileData, allProjectAssemblies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,8 +237,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
var systemReferenceDirectories = CompilationPipeline.GetSystemAssemblyDirectories(assembly.compilerOptions.ApiCompatibilityLevel);
|
||||
|
||||
Dictionary<string, ResponseFileData> responseFilesData = assembly.compilerOptions.ResponseFiles.ToDictionary(x => x, x => CompilationPipeline.ParseResponseFile(
|
||||
Path.Combine(ProjectDirectory, x),
|
||||
Dictionary<string, ResponseFileData> responseFilesData = assembly.compilerOptions.ResponseFiles.ToDictionary(x => x, x => m_AssemblyNameProvider.ParseResponseFile(
|
||||
x,
|
||||
ProjectDirectory,
|
||||
systemReferenceDirectories
|
||||
));
|
||||
@@ -313,7 +265,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
foreach (string asset in m_AssemblyNameProvider.GetAllAssetPaths())
|
||||
{
|
||||
// Exclude files coming from packages except if they are internalized.
|
||||
if (!m_ShouldGenerateAll && IsInternalizedPackagePath(asset))
|
||||
if (m_AssemblyNameProvider.IsInternalizedPackagePath(asset))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -328,7 +280,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
continue;
|
||||
}
|
||||
|
||||
assemblyName = FileUtility.FileNameWithoutExtension(assemblyName);
|
||||
assemblyName = Path.GetFileNameWithoutExtension(assemblyName);
|
||||
|
||||
if (!stringBuilders.TryGetValue(assemblyName, out var projectBuilder))
|
||||
{
|
||||
@@ -348,28 +300,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsInternalizedPackagePath(string file)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var packageInfo = m_AssemblyNameProvider.FindForAssetPath(file);
|
||||
if (packageInfo == null) {
|
||||
return false;
|
||||
}
|
||||
var packageSource = packageInfo.source;
|
||||
return packageSource != PackageSource.Embedded && packageSource != PackageSource.Local;
|
||||
}
|
||||
|
||||
void SyncProject(
|
||||
Assembly island,
|
||||
Assembly assembly,
|
||||
Dictionary<string, string> allAssetsProjectParts,
|
||||
IEnumerable<ResponseFileData> responseFilesData,
|
||||
List<Assembly> allProjectIslands)
|
||||
List<Assembly> allProjectAssemblies)
|
||||
{
|
||||
SyncProjectFileIfNotChanged(ProjectFile(island), ProjectText(island, allAssetsProjectParts, responseFilesData, allProjectIslands));
|
||||
SyncProjectFileIfNotChanged(ProjectFile(assembly), ProjectText(assembly, allAssetsProjectParts, responseFilesData, allProjectAssemblies));
|
||||
}
|
||||
|
||||
void SyncProjectFileIfNotChanged(string path, string newContents)
|
||||
@@ -389,114 +326,88 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
SyncFileIfNotChanged(path, newContents);
|
||||
}
|
||||
|
||||
static IEnumerable<SR.MethodInfo> GetPostProcessorCallbacks(string name)
|
||||
{
|
||||
return TypeCache
|
||||
.GetTypesDerivedFrom<AssetPostprocessor>()
|
||||
.Select(t => t.GetMethod(name, SR.BindingFlags.Public | SR.BindingFlags.NonPublic | SR.BindingFlags.Static))
|
||||
.Where(m => m!= null);
|
||||
}
|
||||
|
||||
static void OnGeneratedCSProjectFiles()
|
||||
{
|
||||
IEnumerable<Type> 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)
|
||||
foreach(var method in GetPostProcessorCallbacks(nameof(OnGeneratedCSProjectFiles)))
|
||||
{
|
||||
var method = type.GetMethod("OnGeneratedCSProjectFiles", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
if (method == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
method.Invoke(null, args);
|
||||
method.Invoke(null, Array.Empty<object>());
|
||||
}
|
||||
}
|
||||
|
||||
static bool OnPreGeneratingCSProjectFiles()
|
||||
{
|
||||
IEnumerable<Type> 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)
|
||||
|
||||
foreach(var method in GetPostProcessorCallbacks(nameof(OnPreGeneratingCSProjectFiles)))
|
||||
{
|
||||
var args = new object[0];
|
||||
var method = type.GetMethod("OnPreGeneratingCSProjectFiles", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
if (method == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var returnValue = method.Invoke(null, args);
|
||||
var retValue = method.Invoke(null, Array.Empty<object>());
|
||||
if (method.ReturnType == typeof(bool))
|
||||
{
|
||||
result |= (bool)returnValue;
|
||||
result |= (bool)retValue;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static string InvokeAssetPostProcessorGenerationCallbacks(string name, string path, string content)
|
||||
{
|
||||
foreach(var method in GetPostProcessorCallbacks(name))
|
||||
{
|
||||
var args = new [] { path, content };
|
||||
var returnValue = method.Invoke(null, args);
|
||||
if (method.ReturnType == typeof(string))
|
||||
{
|
||||
// We want to chain content update between invocations
|
||||
content = (string)returnValue;
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
static string OnGeneratedCSProject(string path, string content)
|
||||
{
|
||||
IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => SafeGetTypes(x))
|
||||
.Where(x => typeof(AssetPostprocessor).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
|
||||
foreach (var type in types)
|
||||
{
|
||||
var args = new [] { path, content };
|
||||
var method = type.GetMethod("OnGeneratedCSProject", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
if (method == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var returnValue = method.Invoke(null, args);
|
||||
if (method.ReturnType == typeof(string))
|
||||
{
|
||||
content = (string)returnValue;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
return InvokeAssetPostProcessorGenerationCallbacks(nameof(OnGeneratedCSProject), path, content);
|
||||
}
|
||||
|
||||
static string OnGeneratedSlnSolution(string path, string content)
|
||||
{
|
||||
IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => SafeGetTypes(x))
|
||||
.Where(x => typeof(AssetPostprocessor).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
|
||||
foreach (var type in types)
|
||||
{
|
||||
var args = new [] { path, content };
|
||||
var method = type.GetMethod("OnGeneratedSlnSolution", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
if (method == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var returnValue = method.Invoke(null, args);
|
||||
if (method.ReturnType == typeof(string))
|
||||
{
|
||||
content = (string)returnValue;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
return InvokeAssetPostProcessorGenerationCallbacks(nameof(OnGeneratedSlnSolution), path, content);
|
||||
}
|
||||
|
||||
void SyncFileIfNotChanged(string filename, string newContents)
|
||||
{
|
||||
if (File.Exists(filename) &&
|
||||
newContents == File.ReadAllText(filename))
|
||||
try
|
||||
{
|
||||
if (m_FileIOProvider.Exists(filename) && newContents == m_FileIOProvider.ReadAllText(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogException(exception);
|
||||
}
|
||||
|
||||
if (Settings.ShouldSync)
|
||||
{
|
||||
File.WriteAllText(filename, newContents, Encoding.UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
var utf8 = Encoding.UTF8;
|
||||
byte[] utfBytes = utf8.GetBytes(newContents);
|
||||
Settings.SyncPath[filename] = utf8.GetString(utfBytes, 0, utfBytes.Length);
|
||||
}
|
||||
m_FileIOProvider.WriteAllText(filename, newContents);
|
||||
}
|
||||
|
||||
string ProjectText(Assembly assembly,
|
||||
Dictionary<string, string> allAssetsProjectParts,
|
||||
IEnumerable<ResponseFileData> responseFilesData,
|
||||
List<Assembly> allProjectIslands)
|
||||
List<Assembly> allProjectAsemblies)
|
||||
{
|
||||
var projectBuilder = new StringBuilder(ProjectHeader(assembly, responseFilesData));
|
||||
var references = new List<string>();
|
||||
var projectReferences = new List<Match>();
|
||||
|
||||
projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
|
||||
foreach (string file in assembly.sourceFiles)
|
||||
@@ -517,62 +428,39 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
}
|
||||
projectBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
|
||||
|
||||
var assemblyName = FileUtility.FileNameWithoutExtension(assembly.outputPath);
|
||||
|
||||
projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
|
||||
|
||||
// Append additional non-script files that should be included in project generation.
|
||||
if (allAssetsProjectParts.TryGetValue(assemblyName, out var additionalAssetsForProject))
|
||||
if (allAssetsProjectParts.TryGetValue(assembly.name, out var additionalAssetsForProject))
|
||||
projectBuilder.Append(additionalAssetsForProject);
|
||||
|
||||
var islandRefs = references.Union(assembly.allReferences);
|
||||
|
||||
foreach (string reference in islandRefs)
|
||||
var responseRefs = responseFilesData.SelectMany(x => x.FullPathReferences.Select(r => r));
|
||||
var internalAssemblyReferences = assembly.assemblyReferences
|
||||
.Where(i => !i.sourceFiles.Any(ShouldFileBePartOfSolution)).Select(i => i.outputPath);
|
||||
var allReferences =
|
||||
assembly.compiledAssemblyReferences
|
||||
.Union(responseRefs)
|
||||
.Union(references)
|
||||
.Union(internalAssemblyReferences);
|
||||
foreach (var reference in allReferences)
|
||||
{
|
||||
if (reference.EndsWith("/UnityEditor.dll", StringComparison.Ordinal)
|
||||
|| reference.EndsWith("/UnityEngine.dll", StringComparison.Ordinal)
|
||||
|| reference.EndsWith("\\UnityEditor.dll", StringComparison.Ordinal)
|
||||
|| reference.EndsWith("\\UnityEngine.dll", StringComparison.Ordinal))
|
||||
continue;
|
||||
|
||||
var match = k_ScriptReferenceExpression.Match(reference);
|
||||
if (match.Success)
|
||||
{
|
||||
// assume csharp language
|
||||
// Add a reference to a project except if it's a reference to a script assembly
|
||||
// that we are not generating a project for. This will be the case for assemblies
|
||||
// coming from .assembly.json files in non-internalized packages.
|
||||
var dllName = match.Groups["dllname"].Value;
|
||||
if (allProjectIslands.Any(i => Path.GetFileName(i.outputPath) == dllName))
|
||||
{
|
||||
projectReferences.Add(match);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
string fullReference = Path.IsPathRooted(reference) ? reference : Path.Combine(ProjectDirectory, reference);
|
||||
|
||||
AppendReference(fullReference, projectBuilder);
|
||||
}
|
||||
|
||||
var responseRefs = responseFilesData.SelectMany(x => x.FullPathReferences.Select(r => r));
|
||||
foreach (var reference in responseRefs)
|
||||
{
|
||||
AppendReference(reference, projectBuilder);
|
||||
}
|
||||
projectBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
|
||||
|
||||
if (0 < projectReferences.Count)
|
||||
if (0 < assembly.assemblyReferences.Length)
|
||||
{
|
||||
projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
|
||||
foreach (Match reference in projectReferences)
|
||||
projectBuilder.Append(" <ItemGroup>").Append(k_WindowsNewline);
|
||||
foreach (Assembly reference in assembly.assemblyReferences.Where(i => i.sourceFiles.Any(ShouldFileBePartOfSolution)))
|
||||
{
|
||||
var referencedProject = reference.Groups["project"].Value;
|
||||
|
||||
projectBuilder.Append(" <ProjectReference Include=\"").Append(referencedProject).Append(GetProjectExtension()).Append("\">").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <Project>{").Append(ProjectGuid(Path.Combine("Temp", reference.Groups["project"].Value + ".dll"))).Append("}</Project>").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <Name>").Append(referencedProject).Append("</Name>").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <ProjectReference Include=\"").Append(reference.name).Append(GetProjectExtension()).Append("\">").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <Project>{").Append(ProjectGuid(reference)).Append("}</Project>").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <Name>").Append(reference.name).Append("</Name>").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" </ProjectReference>").Append(k_WindowsNewline);
|
||||
}
|
||||
|
||||
projectBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
|
||||
}
|
||||
|
||||
@@ -599,14 +487,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
void AppendReference(string fullReference, StringBuilder projectBuilder)
|
||||
{
|
||||
var escapedFullPath = EscapedRelativePathFor(fullReference);
|
||||
projectBuilder.Append(" <Reference Include=\"").Append(FileUtility.FileNameWithoutExtension(escapedFullPath)).Append("\">").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <Reference Include=\"").Append(Path.GetFileNameWithoutExtension(escapedFullPath)).Append("\">").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" <HintPath>").Append(escapedFullPath).Append("</HintPath>").Append(k_WindowsNewline);
|
||||
projectBuilder.Append(" </Reference>").Append(k_WindowsNewline);
|
||||
}
|
||||
|
||||
public string ProjectFile(Assembly assembly)
|
||||
{
|
||||
return Path.Combine(ProjectDirectory, $"{FileUtility.FileNameWithoutExtension(assembly.outputPath)}.csproj");
|
||||
return Path.Combine(ProjectDirectory, $"{m_AssemblyNameProvider.GetAssemblyName(assembly.outputPath, assembly.name)}.csproj");
|
||||
}
|
||||
|
||||
private static readonly Regex InvalidCharactersRegexPattern = new Regex(@"\?|&|\*|""|<|>|\||#|%|\^|;" + (VisualStudioEditor.IsWindows ? "" : "|:"));
|
||||
@@ -616,7 +504,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
}
|
||||
|
||||
string ProjectHeader(
|
||||
Assembly island,
|
||||
Assembly assembly,
|
||||
IEnumerable<ResponseFileData> responseFilesData
|
||||
)
|
||||
{
|
||||
@@ -625,23 +513,33 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
const string baseDirectory = ".";
|
||||
|
||||
var targetFrameworkVersion = "v4.7.1";
|
||||
var targetLanguageVersion = "latest";
|
||||
var targetLanguageVersion = "latest"; // danger: latest is not the same absolute value depending on the VS version.
|
||||
|
||||
var projectType = ProjectTypeOf(island.outputPath);
|
||||
if (m_CurrentInstallation != null && m_CurrentInstallation.SupportsCSharp8)
|
||||
{
|
||||
// Current installation is compatible with C# 8.
|
||||
// But Unity has no support for C# 8 constructs so far, so tell the compiler to accept only C# 7.3 or lower.
|
||||
targetLanguageVersion = "7.3";
|
||||
}
|
||||
|
||||
var projectType = ProjectTypeOf(assembly.name);
|
||||
|
||||
var arguments = new object[]
|
||||
{
|
||||
toolsVersion, productVersion, ProjectGuid(island.outputPath),
|
||||
toolsVersion,
|
||||
productVersion,
|
||||
ProjectGuid(assembly),
|
||||
XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEngineAssemblyPath())),
|
||||
XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEditorAssemblyPath())),
|
||||
string.Join(";", new[] { "DEBUG", "TRACE" }.Concat(EditorUserBuildSettings.activeScriptCompilationDefines).Concat(island.defines).Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
|
||||
string.Join(";", assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
|
||||
MSBuildNamespaceUri,
|
||||
FileUtility.FileNameWithoutExtension(island.outputPath),
|
||||
EditorSettings.projectGenerationRootNamespace,
|
||||
assembly.name,
|
||||
assembly.outputPath,
|
||||
m_AssemblyNameProvider.ProjectGenerationRootNamespace,
|
||||
targetFrameworkVersion,
|
||||
targetLanguageVersion,
|
||||
baseDirectory,
|
||||
island.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
|
||||
assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
|
||||
// flavoring
|
||||
projectType + ":" + (int)projectType,
|
||||
EditorUserBuildSettings.activeBuildTarget + ":" + (int)EditorUserBuildSettings.activeBuildTarget,
|
||||
@@ -706,7 +604,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return string.Join("\r\n",
|
||||
@" <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />",
|
||||
@" <Target Name=""GenerateTargetFrameworkMonikerAttribute"" />",
|
||||
@" <!-- To modify your build process, add your task inside one of the targets below and uncomment it. ",
|
||||
@" <!-- To modify your build process, add your task inside one of the targets below and uncomment it.",
|
||||
@" Other similar extension points exist, see Microsoft.Common.targets.",
|
||||
@" <Target Name=""BeforeBuild"">",
|
||||
@" </Target>",
|
||||
@@ -724,32 +622,32 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>",
|
||||
@"<Project ToolsVersion=""{0}"" DefaultTargets=""Build"" xmlns=""{6}"">",
|
||||
@" <PropertyGroup>",
|
||||
@" <LangVersion>{10}</LangVersion>",
|
||||
@" <LangVersion>{11}</LangVersion>",
|
||||
@" </PropertyGroup>",
|
||||
@" <PropertyGroup>",
|
||||
@" <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>",
|
||||
@" <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>",
|
||||
@" <ProductVersion>{1}</ProductVersion>",
|
||||
@" <SchemaVersion>2.0</SchemaVersion>",
|
||||
@" <RootNamespace>{8}</RootNamespace>",
|
||||
@" <RootNamespace>{9}</RootNamespace>",
|
||||
@" <ProjectGuid>{{{2}}}</ProjectGuid>",
|
||||
@" <OutputType>Library</OutputType>",
|
||||
@" <AppDesignerFolder>Properties</AppDesignerFolder>",
|
||||
@" <AssemblyName>{7}</AssemblyName>",
|
||||
@" <TargetFrameworkVersion>{9}</TargetFrameworkVersion>",
|
||||
@" <TargetFrameworkVersion>{10}</TargetFrameworkVersion>",
|
||||
@" <FileAlignment>512</FileAlignment>",
|
||||
@" <BaseDirectory>{11}</BaseDirectory>",
|
||||
@" <BaseDirectory>{12}</BaseDirectory>",
|
||||
@" </PropertyGroup>",
|
||||
@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">",
|
||||
@" <DebugSymbols>true</DebugSymbols>",
|
||||
@" <DebugType>full</DebugType>",
|
||||
@" <Optimize>false</Optimize>",
|
||||
@" <OutputPath>Temp\bin\Debug\</OutputPath>",
|
||||
@" <OutputPath>{8}</OutputPath>",
|
||||
@" <DefineConstants>{5}</DefineConstants>",
|
||||
@" <ErrorReport>prompt</ErrorReport>",
|
||||
@" <WarningLevel>4</WarningLevel>",
|
||||
@" <NoWarn>0169</NoWarn>",
|
||||
@" <AllowUnsafeBlocks>{12}</AllowUnsafeBlocks>",
|
||||
@" <AllowUnsafeBlocks>{13}</AllowUnsafeBlocks>",
|
||||
@" </PropertyGroup>",
|
||||
@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">",
|
||||
@" <DebugType>pdbonly</DebugType>",
|
||||
@@ -758,7 +656,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
@" <ErrorReport>prompt</ErrorReport>",
|
||||
@" <WarningLevel>4</WarningLevel>",
|
||||
@" <NoWarn>0169</NoWarn>",
|
||||
@" <AllowUnsafeBlocks>{12}</AllowUnsafeBlocks>",
|
||||
@" <AllowUnsafeBlocks>{13}</AllowUnsafeBlocks>",
|
||||
@" </PropertyGroup>"
|
||||
};
|
||||
|
||||
@@ -778,22 +676,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
@" <PropertyGroup>",
|
||||
@" <ProjectTypeGuids>{{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1}};{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}</ProjectTypeGuids>",
|
||||
@" <UnityProjectGenerator>Package</UnityProjectGenerator>",
|
||||
@" <UnityProjectType>{13}</UnityProjectType>",
|
||||
@" <UnityBuildTarget>{14}</UnityBuildTarget>",
|
||||
@" <UnityVersion>{15}</UnityVersion>",
|
||||
@" <UnityProjectType>{14}</UnityProjectType>",
|
||||
@" <UnityBuildTarget>{15}</UnityBuildTarget>",
|
||||
@" <UnityVersion>{16}</UnityVersion>",
|
||||
@" </PropertyGroup>"
|
||||
};
|
||||
|
||||
var footer = new[]
|
||||
{
|
||||
@" <ItemGroup>",
|
||||
@" <Reference Include=""UnityEngine"">",
|
||||
@" <HintPath>{3}</HintPath>",
|
||||
@" </Reference>",
|
||||
@" <Reference Include=""UnityEditor"">",
|
||||
@" <HintPath>{4}</HintPath>",
|
||||
@" </Reference>",
|
||||
@" </ItemGroup>",
|
||||
@""
|
||||
};
|
||||
|
||||
@@ -803,11 +693,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
.ToList();
|
||||
|
||||
// Only add analyzer block for compatible Visual Studio
|
||||
if (CodeEditor.CurrentEditor is VisualStudioEditor editor && editor.TryGetVisualStudioInstallationForPath(CodeEditor.CurrentEditorInstallation, out var installation))
|
||||
if (m_CurrentInstallation != null && m_CurrentInstallation.SupportsAnalyzers)
|
||||
{
|
||||
if (installation.SupportsAnalyzers)
|
||||
{
|
||||
var analyzers = installation.GetAnalyzers();
|
||||
var analyzers = m_CurrentInstallation.GetAnalyzers();
|
||||
if (analyzers != null && analyzers.Length > 0)
|
||||
{
|
||||
lines.Add(@" <ItemGroup>");
|
||||
@@ -816,29 +704,28 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
lines.Add(@" </ItemGroup>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join("\r\n", lines
|
||||
.Concat(footer));
|
||||
}
|
||||
|
||||
void SyncSolution(IEnumerable<Assembly> islands)
|
||||
void SyncSolution(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
if (InvalidCharactersRegexPattern.IsMatch(ProjectDirectory))
|
||||
Debug.LogWarning("Project path contains special characters, which can be an issue when opening Visual Studio");
|
||||
|
||||
var solutionFile = SolutionFile();
|
||||
var previousSolution = File.Exists(solutionFile) ? SolutionParser.ParseSolutionFile(solutionFile) : null;
|
||||
SyncSolutionFileIfNotChanged(solutionFile, SolutionText(islands, previousSolution));
|
||||
var previousSolution = m_FileIOProvider.Exists(solutionFile) ? SolutionParser.ParseSolutionFile(solutionFile, m_FileIOProvider) : null;
|
||||
SyncSolutionFileIfNotChanged(solutionFile, SolutionText(assemblies, previousSolution));
|
||||
}
|
||||
|
||||
string SolutionText(IEnumerable<Assembly> islands, Solution previousSolution = null)
|
||||
string SolutionText(IEnumerable<Assembly> assemblies, Solution previousSolution = null)
|
||||
{
|
||||
const string fileversion = "12.00";
|
||||
const string vsversion = "15";
|
||||
|
||||
var relevantIslands = RelevantIslandsForMode(islands);
|
||||
var generatedProjects = ToProjectEntries(relevantIslands);
|
||||
var relevantAssemblies = RelevantAssembliesForMode(assemblies);
|
||||
var generatedProjects = ToProjectEntries(relevantAssemblies);
|
||||
|
||||
SolutionProperties[] properties = null;
|
||||
|
||||
@@ -863,10 +750,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return string.Format(GetSolutionText(), fileversion, vsversion, projectEntriesText, projectConfigurationsText, propertiesText);
|
||||
}
|
||||
|
||||
static IEnumerable<Assembly> RelevantIslandsForMode(IEnumerable<Assembly> islands)
|
||||
static IEnumerable<Assembly> RelevantAssembliesForMode(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
IEnumerable<Assembly> relevantIslands = islands.Where(i => ScriptingLanguage.CSharp == ScriptingLanguageFor(i));
|
||||
return relevantIslands;
|
||||
return assemblies.Where(i => ScriptingLanguage.CSharp == ScriptingLanguageFor(i));
|
||||
}
|
||||
|
||||
private string GetPropertiesText(SolutionProperties[] array)
|
||||
@@ -920,15 +806,15 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return string.Join(k_WindowsNewline, projectEntries.ToArray());
|
||||
}
|
||||
|
||||
IEnumerable<SolutionProjectEntry> ToProjectEntries(IEnumerable<Assembly> islands)
|
||||
IEnumerable<SolutionProjectEntry> ToProjectEntries(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
foreach (var island in islands)
|
||||
foreach (var assembly in assemblies)
|
||||
yield return new SolutionProjectEntry()
|
||||
{
|
||||
ProjectFactoryGuid = SolutionGuid(island),
|
||||
Name = FileUtility.FileNameWithoutExtension(island.outputPath),
|
||||
FileName = Path.GetFileName(ProjectFile(island)),
|
||||
ProjectGuid = ProjectGuid(island.outputPath)
|
||||
ProjectFactoryGuid = SolutionGuid(assembly),
|
||||
Name = assembly.name,
|
||||
FileName = Path.GetFileName(ProjectFile(assembly)),
|
||||
ProjectGuid = ProjectGuid(assembly)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -966,16 +852,6 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return path;
|
||||
}
|
||||
|
||||
string ProjectGuid(string assembly)
|
||||
{
|
||||
return SolutionGuidGenerator.GuidForProject(m_ProjectName + FileUtility.FileNameWithoutExtension(assembly));
|
||||
}
|
||||
|
||||
string SolutionGuid(Assembly island)
|
||||
{
|
||||
return SolutionGuidGenerator.GuidForSolution(m_ProjectName, ScriptingLanguageFor(island));
|
||||
}
|
||||
|
||||
static string ProjectFooter()
|
||||
{
|
||||
return GetProjectFooterTemplate();
|
||||
@@ -985,6 +861,18 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
return ".csproj";
|
||||
}
|
||||
|
||||
string ProjectGuid(Assembly assembly)
|
||||
{
|
||||
return m_GUIDGenerator.ProjectGuid(
|
||||
m_ProjectName,
|
||||
m_AssemblyNameProvider.GetAssemblyName(assembly.outputPath, assembly.name));
|
||||
}
|
||||
|
||||
string SolutionGuid(Assembly assembly)
|
||||
{
|
||||
return m_GUIDGenerator.SolutionGuid(m_ProjectName, ScriptingLanguageFor(assembly));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SolutionGuidGenerator
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c55bbb5ab4b342946980281be9e63c1a
|
||||
guid: 9f3705b95d031e84c82f140d8e980867
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
22
Editor/ProjectGeneration/ProjectGenerationFlag.cs
Normal file
22
Editor/ProjectGeneration/ProjectGenerationFlag.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
[Flags]
|
||||
public enum ProjectGenerationFlag
|
||||
{
|
||||
None = 0,
|
||||
Embedded = 1,
|
||||
Local = 2,
|
||||
Registry = 4,
|
||||
Git = 8,
|
||||
BuiltIn = 16,
|
||||
Unknown = 32,
|
||||
PlayerAssemblies = 64,
|
||||
LocalTarBall = 128,
|
||||
}
|
||||
}
|
||||
11
Editor/ProjectGeneration/ProjectGenerationFlag.cs.meta
Normal file
11
Editor/ProjectGeneration/ProjectGenerationFlag.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 555fcccd6b79a864f83e7a319daa1c3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,9 +15,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
private static readonly Regex PropertiesDeclaration = new Regex(@"GlobalSection\((?<name>[\w]+Properties)\)\s+=\s+(?<type>(?:post|pre)Solution)(?<entries>.*?)EndGlobalSection", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
|
||||
private static readonly Regex PropertiesEntryDeclaration = new Regex(@"^\s*(?<key>.*?)=(?<value>.*?)$", RegexOptions.Multiline | RegexOptions.ExplicitCapture);
|
||||
|
||||
public static Solution ParseSolutionFile(string filename)
|
||||
public static Solution ParseSolutionFile(string filename, IFileIO fileIO)
|
||||
{
|
||||
return ParseSolutionContent(File.ReadAllText(filename));
|
||||
return ParseSolutionContent(fileIO.ReadAllText(filename));
|
||||
}
|
||||
|
||||
public static Solution ParseSolutionContent(string content)
|
||||
|
||||
@@ -80,8 +80,6 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
const string unity_generate_all = "unity_generate_all_csproj";
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
@@ -96,14 +94,38 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
GUILayout.Label($"<size=10><color=grey>{package.displayName} v{package.version} enabled</color></size>", style);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var prevGenerate = EditorPrefs.GetBool(unity_generate_all, false);
|
||||
var generateAll = EditorGUILayout.Toggle("Generate all .csproj files.", prevGenerate);
|
||||
if (generateAll != prevGenerate)
|
||||
{
|
||||
EditorPrefs.SetBool(unity_generate_all, generateAll);
|
||||
EditorGUILayout.LabelField("Generate .csproj files for:");
|
||||
EditorGUI.indentLevel++;
|
||||
SettingsButton(ProjectGenerationFlag.Embedded, "Embedded packages", "");
|
||||
SettingsButton(ProjectGenerationFlag.Local, "Local packages", "");
|
||||
SettingsButton(ProjectGenerationFlag.Registry, "Registry packages", "");
|
||||
SettingsButton(ProjectGenerationFlag.Git, "Git packages", "");
|
||||
SettingsButton(ProjectGenerationFlag.BuiltIn, "Built-in packages", "");
|
||||
SettingsButton(ProjectGenerationFlag.LocalTarBall, "Local tarball", "");
|
||||
SettingsButton(ProjectGenerationFlag.Unknown, "Packages from unknown sources", "");
|
||||
SettingsButton(ProjectGenerationFlag.PlayerAssemblies, "Player projects", "For each player project generate an additional csproj with the name 'project-player.csproj'");
|
||||
RegenerateProjectFiles();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
_generator.GenerateAll(generateAll);
|
||||
void RegenerateProjectFiles()
|
||||
{
|
||||
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)
|
||||
{
|
||||
var prevValue = _generator.AssemblyNameProvider.ProjectGenerationFlag.HasFlag(preference);
|
||||
var newValue = EditorGUILayout.Toggle(new GUIContent(guiMessage, toolTip), prevValue);
|
||||
if (newValue != prevValue)
|
||||
{
|
||||
_generator.AssemblyNameProvider.ToggleProjectGeneration(preference);
|
||||
}
|
||||
}
|
||||
|
||||
public void SyncIfNeeded(string[] addedFiles, string[] deletedFiles, string[] movedFiles, string[] movedFromFiles, string[] importedFiles)
|
||||
@@ -113,6 +135,11 @@ 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");
|
||||
|
||||
if (!File.Exists(asmFile) || !Image.IsAssembly(asmFile))
|
||||
continue;
|
||||
|
||||
if (Symbols.IsPortableSymbolFile(pdbFile))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -31,6 +31,20 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsCSharp8
|
||||
{
|
||||
get
|
||||
{
|
||||
if (VisualStudioEditor.IsWindows)
|
||||
return Version >= new Version(16, 0);
|
||||
|
||||
if (VisualStudioEditor.IsOSX)
|
||||
return Version >= new Version(8, 2);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ReadRegistry(RegistryKey hive, string keyName, string valueName)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
"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.0",
|
||||
"version": "2.0.1",
|
||||
"unity": "2020.1",
|
||||
"unityRelease": "0a12",
|
||||
"dependencies": {},
|
||||
"relatedPackages": {
|
||||
"com.unity.ide.visualstudio.tests": "2.0.0"
|
||||
"com.unity.ide.visualstudio.tests": "2.0.1"
|
||||
},
|
||||
"repository": {
|
||||
"footprint": "29b3412db92c0d78a94e0fdcaf3aa46387f7b415",
|
||||
"type": "git",
|
||||
"url": "git@github.cds.internal.unity3d.com:unity/com.unity.ide.visualstudio.git",
|
||||
"revision": "a3fbcc6d9504b41b441ecf6caeb3bbc753d6d010"
|
||||
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
|
||||
"revision": "f8cace3617b9248d18f3a982b22fa3fb527e7b9b"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user