-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
References are now cached in a targets file. This improves build time and should (but actually doesn't) make the referenced assemblies show up in Visual Studio Solution Explorer.
- Loading branch information
1 parent
c1d83a9
commit 2e1cb13
Showing
4 changed files
with
243 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
UnityModStudio.Build/Tasks/ResolveGameAssemblyReferences.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using UnityModStudio.Common; | ||
|
||
namespace UnityModStudio.Build.Tasks; | ||
|
||
public class ResolveGameAssemblyReferences : Task | ||
{ | ||
[Required] | ||
public string? GamePath { get; set; } | ||
|
||
[Required] | ||
public string? TargetFramework { get; set; } | ||
|
||
public ITaskItem[] ExistingReferences { get; set; } = []; | ||
|
||
[Output] | ||
public string? Architecture { get; private set; } | ||
|
||
[Output] | ||
public ITaskItem[] ReferencesToAdd { get; private set; } = []; | ||
|
||
[Output] | ||
public ITaskItem[] ReferencesToUpdate { get; private set; } = []; | ||
|
||
[Output] | ||
public ITaskItem[] ReferencesToRemove { get; private set; } = []; | ||
|
||
public override bool Execute() | ||
{ | ||
if (!GameInformationResolver.TryGetGameInformation(GamePath, out var gameInformation, out var error)) | ||
{ | ||
Log.LogError(error); | ||
return false; | ||
} | ||
|
||
Architecture = gameInformation.Architecture.ToString(); | ||
|
||
IEnumerable<FileInfo> assemblyFiles = gameInformation.GameAssemblyFiles; | ||
if (!(TargetFramework?.StartsWith("netstandard", StringComparison.OrdinalIgnoreCase) ?? false)) | ||
assemblyFiles = assemblyFiles.Concat(gameInformation.FrameworkAssemblyFiles); | ||
var resolvedReferences = assemblyFiles.ToDictionary(file => Path.GetFileNameWithoutExtension(file.Name), file => file.FullName, | ||
StringComparer.OrdinalIgnoreCase); | ||
|
||
var referencesToUpdate = new List<ITaskItem>(); | ||
var referencesToRemove = new List<ITaskItem>(); | ||
foreach (var reference in ExistingReferences) | ||
{ | ||
if (resolvedReferences.TryGetValue(reference.ItemSpec, out var path)) | ||
{ | ||
reference.SetMetadata("HintPath", path); | ||
reference.SetMetadata("Private", "false"); | ||
referencesToUpdate.Add(reference); | ||
} | ||
else //if (string.Equals(reference.GetMetadata("IsImplicitlyDefined"), "true", StringComparison.OrdinalIgnoreCase)) | ||
referencesToRemove.Add(reference); | ||
} | ||
|
||
var existingReferenceNames = new HashSet<string>(ExistingReferences.Select(item => item.ItemSpec), | ||
StringComparer.OrdinalIgnoreCase); | ||
var referencesToAdd = new List<ITaskItem>(); | ||
foreach (var resolvedReference in resolvedReferences) | ||
{ | ||
if (!existingReferenceNames.Contains(resolvedReference.Key)) | ||
{ | ||
var reference = new TaskItem(resolvedReference.Key); | ||
reference.SetMetadata("HintPath", resolvedReference.Value); | ||
reference.SetMetadata("Private", "false"); | ||
reference.SetMetadata("IsImplicitlyDefined", "true"); | ||
reference.SetMetadata("IsImplicitlyDefinedGameReference", "true"); | ||
referencesToAdd.Add(reference); | ||
} | ||
} | ||
|
||
ReferencesToAdd = referencesToAdd.ToArray(); | ||
ReferencesToUpdate = referencesToUpdate.ToArray(); | ||
ReferencesToRemove = referencesToRemove.ToArray(); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.