Skip to content

Commit 09d7d03

Browse files
sailroGitHub Enterprise
authored andcommitted
Merge pull request #167 from unity/version-2.0.19
2.0.19
2 parents 4e6a530 + 7d243a9 commit 09d7d03

27 files changed

+1369
-634
lines changed

.vsconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{
1+
{
22
"version": "1.0",
3-
"components": [
3+
"components": [
44
"Microsoft.VisualStudio.Workload.ManagedGame"
55
]
6-
}
6+
}

.yamato/CI.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
codeeditor: visualstudio
22

33
editors:
4-
- version: 2019.4
54
- version: 2020.3
65
- version: 2021.3
7-
- version: 2022.1
8-
- version: 2022.2
6+
- version: 2022.3
7+
- version: 2023.1
98
- version: trunk
109
platforms:
1110
- name: win

Assets/Editor/CSProjAssetTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void Start()
4040
public virtual void SetUp()
4141
{
4242
var projectDirectory = Directory.GetParent(Application.dataPath).FullName;
43-
m_ProjectGeneration = new ProjectGeneration(projectDirectory);
43+
m_ProjectGeneration = new LegacyStyleProjectGeneration(projectDirectory);
4444
}
4545

4646
[UnityTearDown]

Packages/com.unity.ide.visualstudio.tests/Tests/Editor/CSProjectTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void DefaultSyncSettings_WhenSynced_CreatesProjectFileFromDefaultTemplate
124124
{
125125
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
126126
"<Project ToolsVersion=\"4.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">",
127+
" <!-- Generated file, do not modify, your changes will be overwritten (use AssetPostprocessor.OnGeneratedCSProject) -->",
127128
" <PropertyGroup>",
128129
" <LangVersion>latest</LangVersion>",
129130
" </PropertyGroup>",
@@ -233,10 +234,10 @@ public void WontSynchronize_WhenNoFilesChanged()
233234
var synchronizer = m_Builder.Build();
234235

235236
synchronizer.Sync();
236-
Assert.AreEqual(3, m_Builder.WriteTimes, "3 writes for solution + csproj + .vsconfig");
237+
Assert.AreEqual(2, m_Builder.WriteTimes, "2 writes for solution + csproj");
237238

238239
synchronizer.Sync();
239-
Assert.AreEqual(3, m_Builder.WriteTimes, "No more files should be written");
240+
Assert.AreEqual(2, m_Builder.WriteTimes, "No more files should be written");
240241
}
241242

242243
[Test]

Packages/com.unity.ide.visualstudio.tests/Tests/Editor/SolutionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public void ContentWithoutChanges_WhenSynced_DoesNotReSync()
4646
var synchronizer = m_Builder.Build();
4747

4848
synchronizer.Sync();
49-
Assert.AreEqual(3, m_Builder.WriteTimes); // 3 writes for csproj / solution / .vsconfig
49+
Assert.AreEqual(2, m_Builder.WriteTimes); // 2 writes for csproj / solution
5050

5151
synchronizer.Sync();
52-
Assert.AreEqual(3, m_Builder.WriteTimes, "When content doesn't change we shouldn't re-sync");
52+
Assert.AreEqual(2, m_Builder.WriteTimes, "When content doesn't change we shouldn't re-sync");
5353
}
5454

5555
[Test]
@@ -58,12 +58,12 @@ public void AssemblyChanged_AfterSync_PerformsReSync()
5858
var synchronizer = m_Builder.Build();
5959

6060
synchronizer.Sync();
61-
Assert.AreEqual(3, m_Builder.WriteTimes); // 3 writes for csproj / solution / .vsconfig
61+
Assert.AreEqual(2, m_Builder.WriteTimes); // 2 writes for csproj / solution
6262

6363
m_Builder.WithAssemblies(new[] { new Assembly("Another", "path/to/Assembly.dll", new[] { "file.cs" }, new string[0], new Assembly[0], new string[0], AssemblyFlags.None) });
6464

6565
synchronizer.Sync();
66-
Assert.AreEqual(3 + 2, m_Builder.WriteTimes, "Should only re-sync the solution file and the 'Another' csproj");
66+
Assert.AreEqual(2 + 2, m_Builder.WriteTimes, "Should only re-sync the solution file and the 'Another' csproj");
6767
}
6868

6969
[Test]

Packages/com.unity.ide.visualstudio.tests/Tests/Editor/SynchronizerBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public SynchronizerBuilder()
5252

5353
public ProjectGeneration Build()
5454
{
55-
return m_ProjectGeneration = new ProjectGeneration(projectDirectory, m_AssemblyProvider.Object, m_FileIoMock, m_GUIDGenerator.Object);
55+
return m_ProjectGeneration = new LegacyStyleProjectGeneration(projectDirectory, m_AssemblyProvider.Object, m_FileIoMock, m_GUIDGenerator.Object);
5656
}
5757

5858
public SynchronizerBuilder WithSolutionText(string solutionText)
@@ -248,7 +248,7 @@ public override bool TryGetInstallationForPath(string editorPath, out CodeEditor
248248
return true;
249249
}
250250

251-
internal override bool TryGetVisualStudioInstallationForPath(string editorPath, bool searchInstallations, out IVisualStudioInstallation installation)
251+
internal override bool TryGetVisualStudioInstallationForPath(string editorPath, bool lookupDiscoveredInstallations, out IVisualStudioInstallation installation)
252252
{
253253
var mock = new Mock<IVisualStudioInstallation>();
254254
mock.Setup(x => x.SupportsAnalyzers).Returns(true);

Packages/com.unity.ide.visualstudio.tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "com.unity.ide.visualstudio.tests",
44
"displayName": "Visual Studio Editor",
55
"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.",
6-
"version": "2.0.17",
6+
"version": "2.0.18",
77
"unity": "2019.4",
88
"unityRelease": "25f1",
99
"dependencies": {

Packages/com.unity.ide.visualstudio/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Code Editor Package for Visual Studio
22

3+
## [2.0.18] - 2023-03-17
4+
5+
Integration:
6+
7+
- Performance improvements with `EditorApplication.update` callbacks.
8+
9+
Project generation:
10+
11+
- Add extra compiler options for analyzers and source generators.
12+
313
## [2.0.17] - 2022-12-06
414

515
Integration:
@@ -13,7 +23,6 @@ Project generation:
1323
- Update supported C# versions.
1424
- Performance improvements.
1525

16-
1726
## [2.0.16] - 2022-06-08
1827

1928
Integration:

Packages/com.unity.ide.visualstudio/Editor/Cli.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal static string GetInstallationDetails(IVisualStudioInstallation installa
2323

2424
internal static void GenerateSolutionWith(VisualStudioEditor vse, string installationPath)
2525
{
26-
if (vse != null && vse.TryGetVisualStudioInstallationForPath(installationPath, searchInstallations: true, out var vsi))
26+
if (vse != null && vse.TryGetVisualStudioInstallationForPath(installationPath, lookupDiscoveredInstallations: true, out var vsi))
2727
{
2828
Log($"Using {GetInstallationDetails(vsi)}");
2929
vse.SyncAll();

Packages/com.unity.ide.visualstudio/Editor/Discovery.cs

Lines changed: 22 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -3,162 +3,52 @@
33
* Copyright (c) Microsoft Corporation. All rights reserved.
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
6-
using System;
7-
using System.IO;
6+
87
using System.Collections.Generic;
9-
using System.Diagnostics;
10-
using System.Text.RegularExpressions;
11-
using System.Linq;
12-
using UnityEngine;
8+
using System.IO;
139

1410
namespace Microsoft.Unity.VisualStudio.Editor
1511
{
1612
internal static class Discovery
1713
{
18-
internal const string ManagedWorkload = "Microsoft.VisualStudio.Workload.ManagedGame";
19-
20-
internal static string _vsWherePath;
21-
22-
public static void FindVSWhere()
23-
{
24-
_vsWherePath = FileUtility.GetPackageAssetFullPath("Editor", "VSWhere", "vswhere.exe");
25-
}
26-
2714
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
2815
{
29-
if (VisualStudioEditor.IsWindows)
30-
{
31-
foreach (var installation in QueryVsWhere())
32-
yield return installation;
33-
}
16+
foreach (var installation in VisualStudioForWindowsInstallation.GetVisualStudioInstallations())
17+
yield return installation;
3418

35-
if (VisualStudioEditor.IsOSX)
36-
{
37-
var candidates = Directory.EnumerateDirectories("/Applications", "*.app");
38-
foreach (var candidate in candidates)
39-
{
40-
if (TryDiscoverInstallation(candidate, out var installation))
41-
yield return installation;
42-
}
43-
}
44-
}
45-
46-
private static bool IsCandidateForDiscovery(string path)
47-
{
48-
if (File.Exists(path) && VisualStudioEditor.IsWindows && Regex.IsMatch(path, "devenv.exe$", RegexOptions.IgnoreCase))
49-
return true;
50-
51-
if (Directory.Exists(path) && VisualStudioEditor.IsOSX && Regex.IsMatch(path, "Visual\\s?Studio(?!.*Code.*).*.app$", RegexOptions.IgnoreCase))
52-
return true;
19+
foreach (var installation in VisualStudioForMacInstallation.GetVisualStudioInstallations())
20+
yield return installation;
5321

54-
return false;
22+
foreach (var installation in VisualStudioCodeInstallation.GetVisualStudioInstallations())
23+
yield return installation;
5524
}
5625

5726
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation)
5827
{
59-
installation = null;
60-
61-
if (string.IsNullOrEmpty(editorPath))
62-
return false;
63-
64-
if (!IsCandidateForDiscovery(editorPath))
65-
return false;
66-
67-
// On windows we use the executable directly, so we can query extra information
68-
var fvi = editorPath;
69-
70-
// On Mac we use the .app folder, so we need to access to main assembly
71-
if (VisualStudioEditor.IsOSX)
28+
try
7229
{
73-
fvi = Path.Combine(editorPath, "Contents/Resources/lib/monodevelop/bin/VisualStudio.exe");
30+
if (VisualStudioForWindowsInstallation.TryDiscoverInstallation(editorPath, out installation))
31+
return true;
7432

75-
if (!File.Exists(fvi))
76-
fvi = Path.Combine(editorPath, "Contents/MonoBundle/VisualStudio.exe");
33+
if (VisualStudioForMacInstallation.TryDiscoverInstallation(editorPath, out installation))
34+
return true;
7735

78-
if (!File.Exists(fvi))
79-
fvi = Path.Combine(editorPath, "Contents/MonoBundle/VisualStudio.dll");
36+
if (VisualStudioCodeInstallation.TryDiscoverInstallation(editorPath, out installation))
37+
return true;
8038
}
81-
82-
if (!File.Exists(fvi))
83-
return false;
84-
85-
// VS preview are not using the isPrerelease flag so far
86-
// On Windows FileDescription contains "Preview", but not on Mac
87-
var vi = FileVersionInfo.GetVersionInfo(fvi);
88-
var version = new Version(vi.ProductVersion);
89-
var isPrerelease = vi.IsPreRelease || string.Concat(editorPath, "/" + vi.FileDescription).ToLower().Contains("preview");
90-
91-
installation = new VisualStudioInstallation()
39+
catch (IOException)
9240
{
93-
IsPrerelease = isPrerelease,
94-
Name = $"{vi.FileDescription}{(isPrerelease && VisualStudioEditor.IsOSX ? " Preview" : string.Empty)} [{version.ToString(3)}]",
95-
Path = editorPath,
96-
Version = version
97-
};
98-
return true;
99-
}
100-
101-
#region VsWhere Json Schema
102-
#pragma warning disable CS0649
103-
[Serializable]
104-
internal class VsWhereResult
105-
{
106-
public VsWhereEntry[] entries;
107-
108-
public static VsWhereResult FromJson(string json)
109-
{
110-
return JsonUtility.FromJson<VsWhereResult>("{ \"" + nameof(VsWhereResult.entries) + "\": " + json + " }");
41+
installation = null;
11142
}
11243

113-
public IEnumerable<VisualStudioInstallation> ToVisualStudioInstallations()
114-
{
115-
foreach (var entry in entries)
116-
{
117-
yield return new VisualStudioInstallation()
118-
{
119-
Name = $"{entry.displayName} [{entry.catalog.productDisplayVersion}]",
120-
Path = entry.productPath,
121-
IsPrerelease = entry.isPrerelease,
122-
Version = Version.Parse(entry.catalog.buildVersion)
123-
};
124-
}
125-
}
126-
}
127-
128-
[Serializable]
129-
internal class VsWhereEntry
130-
{
131-
public string displayName;
132-
public bool isPrerelease;
133-
public string productPath;
134-
public VsWhereCatalog catalog;
135-
}
136-
137-
[Serializable]
138-
internal class VsWhereCatalog
139-
{
140-
public string productDisplayVersion; // non parseable like "16.3.0 Preview 3.0"
141-
public string buildVersion;
44+
return false;
14245
}
143-
#pragma warning restore CS3021
144-
#endregion
14546

146-
private static IEnumerable<VisualStudioInstallation> QueryVsWhere()
47+
public static void Initialize()
14748
{
148-
var progpath = _vsWherePath;
149-
150-
if (string.IsNullOrWhiteSpace(progpath))
151-
return Enumerable.Empty<VisualStudioInstallation>();
152-
153-
var result = ProcessRunner.StartAndWaitForExit(progpath, "-prerelease -format json -utf8");
154-
155-
if (!result.Success)
156-
throw new Exception($"Failure while running vswhere: {result.Error}");
157-
158-
// Do not catch any JsonException here, this will be handled by the caller
159-
return VsWhereResult
160-
.FromJson(result.Output)
161-
.ToVisualStudioInstallations();
49+
VisualStudioForWindowsInstallation.Initialize();
50+
VisualStudioForMacInstallation.Initialize();
51+
VisualStudioCodeInstallation.Initialize();
16252
}
16353
}
16454
}

0 commit comments

Comments
 (0)