Skip to content

Commit da374e4

Browse files
Add support for Unity 6.5+ DotNetSdk directory
1 parent b70622a commit da374e4

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

sources/UnityRoslynUpdater/UpdateOperations/UpdateSdkOperation.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@ public Task ExecuteAsync(UpdateContext context)
1818
Directory.CreateDirectory(Path.Combine(context.EditorDataPath, "BuiltInDotNetSdk"));
1919
ProcessBuiltInSdkDirectory(Path.Combine(context.EditorDataPath, "DotNetSdkRoslyn"));
2020
ProcessBuiltInSdkDirectory(Path.Combine(context.EditorDataPath, "NetCoreRuntime"));
21+
bool dotNetSdk = ProcessBuiltInSdkDirectory(Path.Combine(context.EditorDataPath, "DotNetSdk"));
2122

22-
void ProcessBuiltInSdkDirectory(string path)
23+
bool ProcessBuiltInSdkDirectory(string path)
2324
{
24-
if (Directory.ResolveLinkTarget(path, returnFinalTarget: true) is null)
25+
try
2526
{
26-
// The directory is not a symbolic link, so we probably haven't
27-
// patched this Unity installation yet. We'll move the directory
28-
// into the BuiltInDotNetSdk directory so the symbolic link can
29-
// be created.
30-
var destination = Path.Combine(context.EditorDataPath, "BuiltInDotNetSdk", Path.GetFileName(path));
31-
Directory.Move(path, destination);
32-
return;
33-
}
27+
if (Directory.ResolveLinkTarget(path, returnFinalTarget: true) is null)
28+
{
29+
// The directory is not a symbolic link, so we probably haven't
30+
// patched this Unity installation yet. We'll move the directory
31+
// into the BuiltInDotNetSdk directory so the symbolic link can
32+
// be created.
33+
var destination = Path.Combine(context.EditorDataPath, "BuiltInDotNetSdk", Path.GetFileName(path));
34+
Directory.Move(path, destination);
35+
return true;
36+
}
3437

35-
// The directory IS a symbolic link, meaning we have most likely
36-
// patched this installation previously. We'll delete the link so
37-
// it can be updated.
38-
Directory.Delete(path, recursive: false);
38+
// The directory IS a symbolic link, meaning we have most likely
39+
// patched this installation previously. We'll delete the link so
40+
// it can be updated.
41+
Directory.Delete(path, recursive: false);
42+
return true;
43+
}
44+
catch (DirectoryNotFoundException)
45+
{
46+
// Intentionally ignored.
47+
return false;
48+
}
3949
}
4050

4151
Directory.CreateSymbolicLink(Path.Combine(context.EditorDataPath, "NetCoreRuntime"), DotNetRoot.GetLocation());
4252
Directory.CreateSymbolicLink(Path.Combine(context.EditorDataPath, "DotNetSdkRoslyn"), Path.Combine(sdk.Location, "Roslyn", "bincore"));
4353

54+
if (dotNetSdk)
55+
Directory.CreateSymbolicLink(Path.Combine(context.EditorDataPath, "DotNetSdk"), DotNetRoot.GetLocation());
56+
4457
// Leave behind a file denoting which SDK we are currently linked to.
4558
File.WriteAllText(Path.Combine(context.EditorDataPath, ".dotnet-link"), sdk.Location);
4659

0 commit comments

Comments
 (0)