com.unity.ide.visualstudio@2.0.15

## [2.0.15] - 2022-03-21

Integration:

- Improved project generation performance.
- Added support for keeping file/folder structure when working with external packages.
- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor.
This commit is contained in:
Unity Technologies
2022-03-21 00:00:00 +00:00
parent fa2de33e64
commit b132c03a8a
7 changed files with 76 additions and 48 deletions

View File

@@ -1,5 +1,15 @@
# Code Editor Package for Visual Studio # Code Editor Package for Visual Studio
## [2.0.15] - 2022-03-21
Integration:
- Improved project generation performance.
- Added support for keeping file/folder structure when working with external packages.
- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor.
## [2.0.14] - 2022-01-14 ## [2.0.14] - 2022-01-14
Integration: Integration:

View File

@@ -39,7 +39,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString()); return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString());
} }
public static string NormalizeWindowsToUnix(string path) public static string NormalizeWindowsToUnix(this string path)
{ {
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
return path; return path;

View File

@@ -55,8 +55,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
static readonly string[] k_ReimportSyncExtensions = { ".dll", ".asmdef" }; static readonly string[] k_ReimportSyncExtensions = { ".dll", ".asmdef" };
string[] m_ProjectSupportedExtensions = Array.Empty<string>(); HashSet<string> m_ProjectSupportedExtensions = new HashSet<string>();
string[] m_BuiltinSupportedExtensions = Array.Empty<string>(); HashSet<string> m_BuiltinSupportedExtensions = new HashSet<string>();
readonly string m_ProjectName; readonly string m_ProjectName;
readonly IAssemblyNameProvider m_AssemblyNameProvider; readonly IAssemblyNameProvider m_AssemblyNameProvider;
@@ -217,8 +217,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
private void SetupProjectSupportedExtensions() private void SetupProjectSupportedExtensions()
{ {
m_ProjectSupportedExtensions = m_AssemblyNameProvider.ProjectSupportedExtensions; m_ProjectSupportedExtensions = new HashSet<string>(m_AssemblyNameProvider.ProjectSupportedExtensions);
m_BuiltinSupportedExtensions = EditorSettings.projectGenerationBuiltinExtensions; m_BuiltinSupportedExtensions = new HashSet<string>(EditorSettings.projectGenerationBuiltinExtensions);
} }
private bool ShouldFileBePartOfSolution(string file) private bool ShouldFileBePartOfSolution(string file)
@@ -246,24 +246,30 @@ namespace Microsoft.Unity.VisualStudio.Editor
public bool IsSupportedFile(string path) public bool IsSupportedFile(string path)
{ {
var extension = GetExtensionWithoutDot(path); return IsSupportedFile(path, out _);
}
private bool IsSupportedFile(string path, out string extensionWithoutDot)
{
extensionWithoutDot = GetExtensionWithoutDot(path);
// Dll's are not scripts but still need to be included // Dll's are not scripts but still need to be included
if (extension == "dll") if (extensionWithoutDot == "dll")
return true; return true;
if (extension == "asmdef") if (extensionWithoutDot == "asmdef")
return true; return true;
if (m_BuiltinSupportedExtensions.Contains(extension)) if (m_BuiltinSupportedExtensions.Contains(extensionWithoutDot))
return true; return true;
if (m_ProjectSupportedExtensions.Contains(extension)) if (m_ProjectSupportedExtensions.Contains(extensionWithoutDot))
return true; return true;
return false; return false;
} }
private static ScriptingLanguage ScriptingLanguageFor(Assembly assembly) private static ScriptingLanguage ScriptingLanguageFor(Assembly assembly)
{ {
var files = assembly.sourceFiles; var files = assembly.sourceFiles;
@@ -271,12 +277,17 @@ namespace Microsoft.Unity.VisualStudio.Editor
if (files.Length == 0) if (files.Length == 0)
return ScriptingLanguage.None; return ScriptingLanguage.None;
return ScriptingLanguageFor(files[0]); return ScriptingLanguageForFile(files[0]);
} }
internal static ScriptingLanguage ScriptingLanguageFor(string path) internal static ScriptingLanguage ScriptingLanguageForExtension(string extensionWithoutDot)
{ {
return GetExtensionWithoutDot(path) == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None; return extensionWithoutDot == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None;
}
internal static ScriptingLanguage ScriptingLanguageForFile(string path)
{
return ScriptingLanguageForExtension(GetExtensionWithoutDot(path));
} }
public void GenerateAndWriteSolutionAndProjects() public void GenerateAndWriteSolutionAndProjects()
@@ -336,7 +347,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
continue; continue;
} }
if (IsSupportedFile(asset) && ScriptingLanguage.None == ScriptingLanguageFor(asset)) if (IsSupportedFile(asset, out var extensionWithoutDot) && ScriptingLanguage.None == ScriptingLanguageForExtension(extensionWithoutDot))
{ {
// Find assembly the asset belongs to by adding script extension and using compilation pipeline. // Find assembly the asset belongs to by adding script extension and using compilation pipeline.
var assemblyName = m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset); var assemblyName = m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset);
@@ -354,7 +365,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
stringBuilders[assemblyName] = projectBuilder; stringBuilders[assemblyName] = projectBuilder;
} }
projectBuilder.Append(" <None Include=\"").Append(EscapedRelativePathFor(asset)).Append("\" />").Append(k_WindowsNewline); IncludeAsset(projectBuilder, "None", asset);
} }
} }
@@ -366,6 +377,26 @@ namespace Microsoft.Unity.VisualStudio.Editor
return result; return result;
} }
private void IncludeAsset(StringBuilder builder, string tag, string asset)
{
var filename = EscapedRelativePathFor(asset, out var packageInfo);
builder.Append($" <{tag} Include=\"").Append(filename);
if (Path.IsPathRooted(filename) && packageInfo != null)
{
// We are outside the Unity project and using a package context
var linkPath = SkipPathPrefix(asset.NormalizePathSeparators(), packageInfo.assetPath.NormalizePathSeparators());
builder.Append("\">").Append(k_WindowsNewline);
builder.Append(" <Link>").Append(linkPath).Append("</Link>").Append(k_WindowsNewline);
builder.Append($" </{tag}>").Append(k_WindowsNewline);
}
else
{
builder.Append("\" />").Append(k_WindowsNewline);
}
}
private void SyncProject( private void SyncProject(
Assembly assembly, Assembly assembly,
Dictionary<string, string> allAssetsProjectParts, Dictionary<string, string> allAssetsProjectParts,
@@ -479,17 +510,16 @@ namespace Microsoft.Unity.VisualStudio.Editor
projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline); projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
foreach (string file in assembly.sourceFiles) foreach (string file in assembly.sourceFiles)
{ {
if (!IsSupportedFile(file)) if (!IsSupportedFile(file, out var extensionWithoutDot))
continue; continue;
var extension = Path.GetExtension(file).ToLower(); if ("dll" != extensionWithoutDot)
var fullFile = EscapedRelativePathFor(file);
if (".dll" != extension)
{ {
projectBuilder.Append(" <Compile Include=\"").Append(fullFile).Append("\" />").Append(k_WindowsNewline); IncludeAsset(projectBuilder, "Compile", file);
} }
else else
{ {
var fullFile = EscapedRelativePathFor(file, out _);
references.Add(fullFile); references.Add(fullFile);
} }
} }
@@ -564,7 +594,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
private void AppendReference(string fullReference, StringBuilder projectBuilder) private void AppendReference(string fullReference, StringBuilder projectBuilder)
{ {
var escapedFullPath = EscapedRelativePathFor(fullReference); var escapedFullPath = EscapedRelativePathFor(fullReference, out _);
projectBuilder.Append(" <Reference Include=\"").Append(Path.GetFileNameWithoutExtension(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(" <HintPath>").Append(escapedFullPath).Append("</HintPath>").Append(k_WindowsNewline);
projectBuilder.Append(" </Reference>").Append(k_WindowsNewline); projectBuilder.Append(" </Reference>").Append(k_WindowsNewline);
@@ -924,13 +954,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
projectGuid); projectGuid);
} }
private string EscapedRelativePathFor(string file) private string EscapedRelativePathFor(string file, out UnityEditor.PackageManager.PackageInfo packageInfo)
{ {
var projectDir = ProjectDirectory.NormalizePathSeparators(); var projectDir = ProjectDirectory.NormalizePathSeparators();
file = file.NormalizePathSeparators(); file = file.NormalizePathSeparators();
var path = SkipPathPrefix(file, projectDir); var path = SkipPathPrefix(file, projectDir);
var packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.Replace('\\', '/')); packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.NormalizeWindowsToUnix());
if (packageInfo != null) if (packageInfo != null)
{ {
// We have to normalize the path, because the PackageManagerRemapper assumes // We have to normalize the path, because the PackageManagerRemapper assumes

View File

@@ -63,6 +63,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
internal static bool IsEnabled => CodeEditor.CurrentEditor is VisualStudioEditor && UnityInstallation.IsMainUnityEditorProcess; internal static bool IsEnabled => CodeEditor.CurrentEditor is VisualStudioEditor && UnityInstallation.IsMainUnityEditorProcess;
// this one seems legacy and not used anymore
// keeping it for now given it is public, so we need a major bump to remove it
public void CreateIfDoesntExist() public void CreateIfDoesntExist()
{ {
if (!_generator.HasSolutionBeenGenerated()) if (!_generator.HasSolutionBeenGenerated())
@@ -260,7 +262,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
return true; return true;
// We only want to check for cs scripts // We only want to check for cs scripts
if (ProjectGeneration.ScriptingLanguageFor(path) != ScriptingLanguage.CSharp) if (ProjectGeneration.ScriptingLanguageForFile(path) != ScriptingLanguage.CSharp)
return true; return true;
// Even on windows, the package manager requires relative path + unix style separators for queries // Even on windows, the package manager requires relative path + unix style separators for queries
@@ -357,31 +359,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
absolutePath = Path.GetFullPath(path); absolutePath = Path.GetFullPath(path);
} }
string solution = GetOrGenerateSolutionFile(path); var solution = GetOrGenerateSolutionFile(path);
return OpenVisualStudio(CodeEditor.CurrentEditorInstallation, solution, absolutePath, line); return OpenVisualStudio(CodeEditor.CurrentEditorInstallation, solution, absolutePath, line);
} }
private string GetOrGenerateSolutionFile(string path) private string GetOrGenerateSolutionFile(string path)
{ {
var solution = GetSolutionFile(path); _generator.Sync();
if (solution == "") return _generator.SolutionFile();
{
_generator.Sync();
solution = GetSolutionFile(path);
}
return solution;
}
string GetSolutionFile(string path)
{
var solutionFile = _generator.SolutionFile();
if (File.Exists(solutionFile))
{
return solutionFile;
}
return "";
} }
} }
} }

View File

@@ -2,21 +2,24 @@
"name": "com.unity.ide.visualstudio", "name": "com.unity.ide.visualstudio",
"displayName": "Visual Studio Editor", "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.", "description": "Code editor integration for supporting Visual Studio as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.",
"version": "2.0.14", "version": "2.0.15",
"unity": "2019.4", "unity": "2019.4",
"unityRelease": "25f1", "unityRelease": "25f1",
"dependencies": { "dependencies": {
"com.unity.test-framework": "1.1.9" "com.unity.test-framework": "1.1.9"
}, },
"relatedPackages": { "relatedPackages": {
"com.unity.ide.visualstudio.tests": "2.0.14" "com.unity.ide.visualstudio.tests": "2.0.15"
},
"upm": {
"changelog": "Integration:\n\n- Improved project generation performance.\n- Added support for keeping file/folder structure when working with external packages.\n- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor."
}, },
"upmCi": { "upmCi": {
"footprint": "8aa1049966a0586c636698ec81d764940b1dbe44" "footprint": "d5d60c3083dbc14a4be33dc1f8c4e7fe147ffb74"
}, },
"repository": { "repository": {
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git", "url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
"type": "git", "type": "git",
"revision": "f1e8af5df9e2507088a8622d173c9a7d5a03a882" "revision": "ca1ece42f5a2c5484ba15a15bb975ccc1f6a1a3c"
} }
} }