Skip to content

Commit debcc81

Browse files
committed
Delegate extra file creation to the specific installation
1 parent 43fcd51 commit debcc81

File tree

5 files changed

+52
-32
lines changed

5 files changed

+52
-32
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Diagnostics;
88
using System.Text;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

1112
namespace Microsoft.Unity.VisualStudio.Editor
@@ -21,19 +22,34 @@ internal static class ProcessRunner
2122
{
2223
public const int DefaultTimeoutInMilliseconds = 300000;
2324

24-
public static ProcessStartInfo ProcessStartInfoFor(string filename, string arguments)
25+
public static ProcessStartInfo ProcessStartInfoFor(string filename, string arguments, bool redirect = true, bool shell = false)
2526
{
2627
return new ProcessStartInfo
2728
{
28-
UseShellExecute = false,
29+
UseShellExecute = shell,
2930
CreateNoWindow = true,
30-
RedirectStandardOutput = true,
31-
RedirectStandardError = true,
31+
RedirectStandardOutput = redirect,
32+
RedirectStandardError = redirect,
3233
FileName = filename,
3334
Arguments = arguments
3435
};
3536
}
3637

38+
public static void Start(string filename, string arguments)
39+
{
40+
Start(ProcessStartInfoFor(filename, arguments, false));
41+
}
42+
43+
public static void Start(ProcessStartInfo processStartInfo)
44+
{
45+
var process = new Process { StartInfo = processStartInfo };
46+
47+
using (process)
48+
{
49+
process.Start();
50+
}
51+
}
52+
3753
public static ProcessRunnerResult StartAndWaitForExit(string filename, string arguments, int timeoutms = DefaultTimeoutInMilliseconds, Action<string> onOutputReceived = null)
3854
{
3955
return StartAndWaitForExit(ProcessStartInfoFor(filename, arguments), timeoutms, onOutputReceived);

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

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public bool SyncIfNeeded(IEnumerable<string> affectedFiles, IEnumerable<string>
108108

109109
// See https://devblogs.microsoft.com/setup/configure-visual-studio-across-your-organization-with-vsconfig/
110110
// We create a .vsconfig file to make sure our ManagedGame workload is installed
111-
CreateVsConfigIfNotFound();
111+
CreateExtraFiles(m_CurrentInstallation);
112112

113113
// Don't sync if we haven't synced before
114114
var affected = affectedFiles as ICollection<string> ?? affectedFiles.ToArray();
@@ -148,28 +148,9 @@ public bool SyncIfNeeded(IEnumerable<string> affectedFiles, IEnumerable<string>
148148
}
149149
}
150150

151-
private void CreateVsConfigIfNotFound()
151+
private void CreateExtraFiles(IVisualStudioInstallation installation)
152152
{
153-
const string ManagedWorkload = "Microsoft.VisualStudio.Workload.ManagedGame";
154-
155-
try
156-
{
157-
var vsConfigFile = VsConfigFile();
158-
if (m_FileIOProvider.Exists(vsConfigFile))
159-
return;
160-
161-
var content = $@"{{
162-
""version"": ""1.0"",
163-
""components"": [
164-
""{ManagedWorkload}""
165-
]
166-
}}
167-
";
168-
m_FileIOProvider.WriteAllText(vsConfigFile, content);
169-
}
170-
catch (IOException)
171-
{
172-
}
153+
installation.CreateExtraFiles(ProjectDirectory);
173154
}
174155

175156
private bool HasFilesBeenModified(IEnumerable<string> affectedFiles, IEnumerable<string> reimportedFiles)
@@ -201,7 +182,7 @@ public void Sync()
201182

202183
// See https://devblogs.microsoft.com/setup/configure-visual-studio-across-your-organization-with-vsconfig/
203184
// We create a .vsconfig file to make sure our ManagedGame workload is installed
204-
CreateVsConfigIfNotFound();
185+
CreateExtraFiles(m_CurrentInstallation);
205186

206187
var externalCodeAlreadyGeneratedProjects = OnPreGeneratingCSProjectFiles();
207188

@@ -618,11 +599,6 @@ public string SolutionFile()
618599
return Path.Combine(ProjectDirectory.NormalizePathSeparators(), $"{InvalidCharactersRegexPattern.Replace(m_ProjectName, "_")}.sln");
619600
}
620601

621-
internal string VsConfigFile()
622-
{
623-
return Path.Combine(ProjectDirectory.NormalizePathSeparators(), ".vsconfig");
624-
}
625-
626602
internal string GetLangVersion(Assembly assembly)
627603
{
628604
var targetLanguageVersion = "latest"; // danger: latest is not the same absolute value depending on the VS version.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
158158
[DllImport("AppleEventIntegration")]
159159
private static extern bool OpenVisualStudio(string appPath, string solutionPath, string filePath, int line);
160160

161+
public override void CreateExtraFiles(string projectDirectory)
162+
{
163+
}
164+
161165
public override bool Open(string path, int line, int column, string solution)
162166
{
163167
string absolutePath = "";

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,28 @@ private enum COMIntegrationState
241241
Exited
242242
}
243243

244+
public override void CreateExtraFiles(string projectDirectory)
245+
{
246+
try
247+
{
248+
var vsConfigFile = IOPath.Combine(projectDirectory.NormalizePathSeparators(), ".vsconfig");
249+
if (File.Exists(vsConfigFile))
250+
return;
251+
252+
const string content = @"{
253+
""version"": ""1.0"",
254+
""components"": [
255+
""Microsoft.VisualStudio.Workload.ManagedGame""
256+
]
257+
}
258+
";
259+
File.WriteAllText(vsConfigFile, content);
260+
}
261+
catch (IOException)
262+
{
263+
}
264+
}
265+
244266
public override bool Open(string path, int line, int column, string solution)
245267
{
246268
var progpath = FileUtility.GetPackageAssetFullPath("Editor", "COMIntegration", "Release", "COMIntegration.exe");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal interface IVisualStudioInstallation
1818
CodeEditor.Installation ToCodeEditorInstallation();
1919
bool Open(string path, int line, int column, string solutionPath);
2020
IGenerator ProjectGenerator { get; }
21+
void CreateExtraFiles(string projectDirectory);
2122
}
2223

2324
internal abstract class VisualStudioInstallation : IVisualStudioInstallation
@@ -31,6 +32,7 @@ internal abstract class VisualStudioInstallation : IVisualStudioInstallation
3132
public abstract Version LatestLanguageVersionSupported { get; }
3233
public abstract string[] GetAnalyzers();
3334
public abstract IGenerator ProjectGenerator { get; }
35+
public abstract void CreateExtraFiles(string projectDirectory);
3436
public abstract bool Open(string path, int line, int column, string solutionPath);
3537

3638
protected Version GetLatestLanguageVersionSupported(VersionPair[] versions)

0 commit comments

Comments
 (0)