From 137fd4d70a192ec34e8223bd37c4918122be3c25 Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Thu, 2 Jan 2020 13:34:44 -0800 Subject: [PATCH 1/7] add winmd support --- .../ProjectGenerator/Scripts/CSProjectInfo.cs | 13 + .../Exporters/TemplatedProjectExporter.cs | 12 + .../Scripts/UnityProjectInfo.cs | 62 +++++ .../ProjectGenerator/Scripts/WinMDInfo.cs | 237 ++++++++++++++++++ .../Scripts/WinMDInfo.cs.meta | 11 + 5 files changed, 335 insertions(+) create mode 100644 Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs create mode 100644 Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs.meta diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/CSProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/CSProjectInfo.cs index 39f3400..b7c4689 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/CSProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/CSProjectInfo.cs @@ -45,6 +45,7 @@ public class CSProjectInfo : ReferenceItemInfo { private readonly List> csProjectDependencies = new List>(); private readonly List> pluginAssemblyDependencies = new List>(); + private readonly List> winmdDependencies = new List>(); /// /// The associated Assembly-Definition info if available. @@ -63,6 +64,8 @@ public class CSProjectInfo : ReferenceItemInfo public IReadOnlyCollection> PluginDependencies { get; } + public IReadOnlyCollection> WinMDDependencies { get; } + /// /// Creates a new instance of the CSProject info. /// @@ -87,6 +90,7 @@ internal CSProjectInfo(UnityProjectInfo unityProjectInfo, AssemblyDefinitionInfo ProjectDependencies = new ReadOnlyCollection>(csProjectDependencies); PluginDependencies = new ReadOnlyCollection>(pluginAssemblyDependencies); + WinMDDependencies = new ReadOnlyCollection>(winmdDependencies); } private ProjectType GetProjectType(AssemblyDefinitionInfo assemblyDefinitionInfo) @@ -161,6 +165,15 @@ internal void AddDependency(PluginAssemblyInfo pluginAssemblyInfo) AddDependency(pluginAssemblyDependencies, pluginAssemblyInfo); } + /// + /// Adds a dependency to the project. + /// + /// The winmd dependency. + internal void AddDependency(WinMDInfo winmdInfo) + { + AddDependency(winmdDependencies, winmdInfo); + } + private void AddDependency(List> items, T referenceInfo) where T : ReferenceItemInfo { items.Add(new CSProjectDependency(referenceInfo, diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedProjectExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedProjectExporter.cs index 66d55f8..5831a61 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedProjectExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedProjectExporter.cs @@ -438,6 +438,18 @@ private void CreateProjectReferencesSet(CSProjectInfo projectInfo, ITemplatePart additionalSearchPaths.Add(Path.GetDirectoryName(dependency.Dependency.ReferencePath.LocalPath)); } + foreach (CSProjectDependency dependency in projectInfo.WinMDDependencies) + { + List platformConditions = GetPlatformConditions(inEditor ? projectInfo.InEditorPlatforms : projectInfo.PlayerPlatforms, inEditor ? dependency.InEditorSupportedPlatforms : dependency.PlayerSupportedPlatforms); + + TemplateReplacementSet replacementSet = pluginReferenceTemplatePart.CreateReplacementSet(templateReplacementSet); + pluginReferenceTemplatePart.Tokens["REFERENCE"].AssignValue(replacementSet, dependency.Dependency.Name); + pluginReferenceTemplatePart.Tokens["HINT_PATH"].AssignValue(replacementSet, dependency.Dependency.ReferencePath.LocalPath); + pluginReferenceTemplatePart.Tokens["CONDITION"].AssignValue(replacementSet, platformConditions.Count == 0 ? "false" : string.Join(" OR ", platformConditions)); + + additionalSearchPaths.Add(Path.GetDirectoryName(dependency.Dependency.ReferencePath.LocalPath)); + } + templatePart.Tokens["REFERENCE_CONFIGURATION"].AssignValue(templateReplacementSet, inEditor ? "InEditor" : "Player"); } diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs index 956974d..e55d766 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs @@ -56,6 +56,11 @@ public class UnityProjectInfo : IDisposable /// public IReadOnlyCollection Plugins { get; private set; } + /// + /// Gets all the parsed winmds for this Unity project. + /// + public IReadOnlyCollection WinMDs { get; private set; } + public UnityProjectInfo(HashSet supportedBuildTargets) { AvailablePlatforms = new ReadOnlyCollection(CompilationPipeline.GetAssemblyDefinitionPlatforms() @@ -97,6 +102,8 @@ public void RefreshPlugins() } } + WinMDs = new ReadOnlyCollection(ScanForWinMDs()); + RefreshProjects(); } @@ -272,6 +279,16 @@ private CSProjectInfo GetProjectInfo(Dictionary projectsM toReturn.AddDependency(plugin); } } + + foreach (WinMDInfo winmd in WinMDs) + { + Debug.Log($"winmd: {winmd.Name} {winmd.ReferencePath}"); + if (!dependencies.IsBaseOf(winmd.ReferencePath)) + { + Debug.Log($"WinMD referenced: {winmd.Name}"); + toReturn.AddDependency(winmd); + } + } } foreach (string reference in toReturn.AssemblyDefinitionInfo.References) @@ -343,6 +360,51 @@ private List ScanForPluginDLLs() return toReturn; } + + private List ScanForWinMDs() + { + List toReturn = new List(); + + foreach (string assetWinmdPath in Directory.GetFiles(Utilities.AssetPath, "*.winmd", SearchOption.AllDirectories)) + { + string assetRelativePath = Utilities.GetAssetsRelativePathFrom(assetWinmdPath); + PluginImporter importer = (PluginImporter)AssetImporter.GetAtPath(assetRelativePath); + if (importer == null) + { + Debug.LogWarning($"Didn't get an importer for '{assetRelativePath}', most likely due to it being in a Unity hidden folder (prefixed by a .)"); + continue; + } + + WinMDInfo toAdd = new WinMDInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetWinmdPath); + toReturn.Add(toAdd); + } + + foreach (string packageWinmdPath in Directory.GetFiles(Utilities.PackageLibraryCachePath, "*.winmd", SearchOption.AllDirectories)) + { + string metaPath = packageWinmdPath + ".meta"; + + if (!File.Exists(metaPath)) + { + Debug.LogWarning($"Skipping a packages winmd that didn't have an associated meta: '{packageWinmdPath}'"); + continue; + } + Guid guid; + using (StreamReader reader = new StreamReader(metaPath)) + { + string guidLine = reader.ReadUntil("guid"); + if (!Guid.TryParse(guidLine.Split(':')[1].Trim(), out guid)) + { + Debug.LogWarning($"Skipping a packages winmd that didn't have a valid guid in the .meta file: '{packageWinmdPath}'"); + continue; + } + } + + WinMDInfo toAdd = new WinMDInfo(this, guid, packageWinmdPath); + toReturn.Add(toAdd); + } + + return toReturn; + } } } #endif \ No newline at end of file diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs new file mode 100644 index 0000000..264d4d2 --- /dev/null +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs @@ -0,0 +1,237 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#if UNITY_EDITOR +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEngine; + +namespace Microsoft.Build.Unity.ProjectGeneration +{ + /// + /// This is the information for the winmds in the Unity project. + /// + public class WinMDInfo : ReferenceItemInfo + { + /// + /// Gets the output path to the reference. + /// + public Uri ReferencePath { get; } + + /// + /// If the plugin has define constraints, then it will only be referenced if the platform/project defines at least one of these constraints. + /// ! operator means that the specified plugin must not be included + /// https://docs.unity3d.com/ScriptReference/PluginImporter.DefineConstraints.html + /// + public HashSet DefineConstraints { get; private set; } + + /// + /// Creates a new instance of the . + /// + public WinMDInfo(UnityProjectInfo unityProjectInfo, Guid guid, string fullPath) + : base(unityProjectInfo, guid, Path.GetFileNameWithoutExtension(fullPath)) + { + ReferencePath = new Uri(fullPath); + ParseYAMLFile(); + } + + private void ParseYAMLFile() + { + Dictionary enabledPlatforms = new Dictionary(); + using (StreamReader reader = new StreamReader(ReferencePath.LocalPath + ".meta")) + { + DefineConstraints = new HashSet(); + + // Parse define constraints + string defineConstraints = reader.ReadUntil("defineConstraints:", "platformData:"); + string platformData; + if (defineConstraints.Contains("defineConstraints:")) + { + if (!defineConstraints.Contains("[]")) + { + reader.ReadWhile(line => + { + line = line.Trim(); + if (line.StartsWith("-")) + { + string define = line.Substring(1).Trim(); + + if (define.StartsWith("'") && define.EndsWith("'")) + { + define = define.Substring(1, define.Length - 2); + } + + DefineConstraints.Add(define); + return true; + } + // else + return false; + }); + } + + // Since succeded, read until platformData + platformData = reader.ReadUntil("platformData:"); + } + else + { + // If it's not defineConstraints, then it's one of the other 3 + platformData = defineConstraints; + } + + if (!platformData.Contains("platformData:")) + { + // Read until platform data + reader.ReadUntil("platformData:"); + } + + ParsePlatformData(reader, enabledPlatforms); + } + + Dictionary inEditorPlatforms = new Dictionary(); + if (enabledPlatforms.TryGetValue("Editor", out bool platformEnabled) && platformEnabled) + { + foreach (CompilationPlatformInfo platform in UnityProjectInfo.AvailablePlatforms) + { + inEditorPlatforms.Add(platform.BuildTarget, platform); + } + } + + Dictionary playerPlatforms = new Dictionary(); + + TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "Win", BuildTarget.StandaloneWindows); + TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "Win64", BuildTarget.StandaloneWindows64); + TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "WindowsStoreApps", BuildTarget.WSAPlayer); + TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "iOS", BuildTarget.iOS); + TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "Android", BuildTarget.Android); + + FilterPlatformsBasedOnDefineConstraints(inEditorPlatforms, true); + FilterPlatformsBasedOnDefineConstraints(playerPlatforms, false); + + InEditorPlatforms = new ReadOnlyDictionary(inEditorPlatforms); + PlayerPlatforms = new ReadOnlyDictionary(playerPlatforms); + } + + private void ParsePlatformData(StreamReader reader, Dictionary enabledPlatforms) + { + if (reader.ReadUntil("first:", "userData:").Contains("userData:") || reader.EndOfStream) + { + // We reached the end + return; + } + + if (reader.ReadLine().Contains("'': Any")) // Try use exclude method + { + string settingsLine = reader.ReadUntil("settings:", "userData:"); + if (settingsLine.Contains("userData:")) + { + return; + } + + // We are fine to use exclude method if we have a set of settings + if (!settingsLine.Contains("settings: {}")) + { + reader.ReadWhile(l => + { + if (l.Contains("Exclude")) + { + string[] parts = l.Trim().Replace("Exclude ", string.Empty).Split(':'); + enabledPlatforms.Add(parts[0], parts[1].Trim() == "0"); // These are exclude, so check for 0 if to include + return true; + } + + return false; + }); + + return; + } + } + // else fall through to use -first method + + string line; + while ((line = reader.ReadUntil("first:", "userData:")).Contains("first:") && !reader.EndOfStream) + { + string[] platformLineParts = reader.ReadLine().Split(':'); + string platform = platformLineParts[1].Trim(); + + if (platformLineParts[0].Contains("Facebook")) + { + platform = $"Facebook{platform}"; + } + string enabledLine = reader.ReadUntil("enabled:"); + + enabledPlatforms.Add(platform, enabledLine.Split(':')[1].Trim() == "1"); + } + } + + private bool ContainsDefineHelper(string define, bool inEditor, CompilationPlatformInfo platform) + { + return platform.CommonPlatformDefines.Contains(define) + || (inEditor ? platform.AdditionalInEditorDefines.Contains(define) : platform.AdditionalPlayerDefines.Contains(define)); + } + + private void FilterPlatformsBasedOnDefineConstraints(IDictionary platformDictionary, bool inEditor) + { + if (DefineConstraints.Count == 0) + { + // No exclusions + return; + } + + bool defaultExcludeValue = DefineConstraints.Any(t => !t.StartsWith("!")); + HashSet toExclude = new HashSet(); + foreach (KeyValuePair platformPair in platformDictionary) + { + // We presume exclude, then check + bool exclude = defaultExcludeValue; + foreach (string define in DefineConstraints) + { + // Does this define exclude + if (define.StartsWith("!")) + { + if (ContainsDefineHelper(define.Substring(1), inEditor, platformPair.Value)) + { + exclude = true; + break; + } + } + else if (ContainsDefineHelper(define, inEditor, platformPair.Value)) + { + // This platform is supported, but still search for !defineconstraitns that may force exclusion + exclude = false; + } + } + + if (exclude) + { + toExclude.Add(platformPair.Key); + } + } + + foreach (BuildTarget buildTarget in toExclude) + { + platformDictionary.Remove(buildTarget); + } + } + + private void TryAddEnabledPlatform(Dictionary playerPlatforms, Dictionary enabledPlatforms, string platformName, BuildTarget platformTarget) + { + if (enabledPlatforms.TryGetValue(platformName, out bool platformEnabled) && platformEnabled) + { + CompilationPlatformInfo platform = UnityProjectInfo.AvailablePlatforms.FirstOrDefault(t => t.BuildTarget == platformTarget); + if (platform != null) + { + playerPlatforms.Add(platformTarget, platform); + } + else + { + Debug.LogError($"Platform '{platformName}' was specified as enabled by '{ReferencePath.LocalPath}' plugin, but not available in processed compilation settings."); + } + } + } + } +} +#endif \ No newline at end of file diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs.meta b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs.meta new file mode 100644 index 0000000..4d180eb --- /dev/null +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 769306ff23e177f4abf9ce36414f8f44 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 9a9ef3d5c51bcffe860a834a7c3807a5970b11f1 Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 8 Jan 2020 09:54:57 -0800 Subject: [PATCH 2/7] address review comments' --- .../Scripts/UnityProjectInfo.cs | 97 +++++++------------ 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs index 504c904..094667e 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs @@ -91,7 +91,8 @@ public void Dispose() public void RefreshPlugins() { - Plugins = new ReadOnlyCollection(ScanForPluginDLLs()); + ScanForReferences(out List plugins, out List winmds); + Plugins = new ReadOnlyCollection(plugins); foreach (PluginAssemblyInfo plugin in Plugins) { @@ -102,7 +103,7 @@ public void RefreshPlugins() } } - WinMDs = new ReadOnlyCollection(ScanForWinMDs()); + WinMDs = new ReadOnlyCollection(winmds); RefreshProjects(); } @@ -272,18 +273,18 @@ private CSProjectInfo GetProjectInfo(Dictionary projectsM Uri dependencies = new Uri(Path.Combine(Utilities.AssetPath, "Dependencies\\")); foreach (PluginAssemblyInfo plugin in Plugins.Where(t => t.Type != PluginType.Native)) { + Debug.Log($"Plugin: {plugin.Name} {plugin.Type} {plugin.AutoReferenced} {plugin.ReferencePath}"); if (!dependencies.IsBaseOf(plugin.ReferencePath) && (plugin.AutoReferenced || assemblyDefinitionInfo.PrecompiledAssemblyReferences.Contains(plugin.Name))) { + Debug.Log($"Plugin referenced: {plugin.Name}"); toReturn.AddDependency(plugin); } } foreach (WinMDInfo winmd in WinMDs) { - Debug.Log($"winmd: {winmd.Name} {winmd.ReferencePath}"); if (!dependencies.IsBaseOf(winmd.ReferencePath)) { - Debug.Log($"WinMD referenced: {winmd.Name}"); toReturn.AddDependency(winmd); } } @@ -313,13 +314,16 @@ private CSProjectInfo GetProjectInfo(Dictionary projectsM return toReturn; } - private List ScanForPluginDLLs() + private void ScanForReferences(out List plugins, out List winmds) { - List toReturn = new List(); + plugins = new List(); + winmds = new List(); - foreach (string assetAssemblyPath in Directory.GetFiles(Utilities.AssetPath, "*.dll", SearchOption.AllDirectories)) + IEnumerable assetReferences = Directory.GetFiles(Utilities.AssetPath, "*.*", SearchOption.AllDirectories) + .Where(file => file.ToLower().EndsWith(".dll") || file.ToLower().EndsWith(".winmd")); + foreach (string assetPath in assetReferences) { - string assetRelativePath = Utilities.GetAssetsRelativePathFrom(assetAssemblyPath); + string assetRelativePath = Utilities.GetAssetsRelativePathFrom(assetPath); PluginImporter importer = (PluginImporter)AssetImporter.GetAtPath(assetRelativePath); if (importer == null) { @@ -327,63 +331,27 @@ private List ScanForPluginDLLs() continue; } - PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetAssemblyPath, importer.isNativePlugin ? PluginType.Native : PluginType.Managed); - toReturn.Add(toAdd); - } - - foreach (string packageDllPath in Directory.GetFiles(Utilities.PackageLibraryCachePath, "*.dll", SearchOption.AllDirectories)) - { - string metaPath = packageDllPath + ".meta"; - - if (!File.Exists(metaPath)) + if (assetRelativePath.EndsWith(".dll")) { - Debug.LogWarning($"Skipping a packages DLL that didn't have an associated meta: '{packageDllPath}'"); - continue; + PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetPath, importer.isNativePlugin ? PluginType.Native : PluginType.Managed); + plugins.Add(toAdd); } - Guid guid; - using (StreamReader reader = new StreamReader(metaPath)) + else if (assetRelativePath.EndsWith(".winmd")) { - string guidLine = reader.ReadUntil("guid"); - if (!Guid.TryParse(guidLine.Split(':')[1].Trim(), out guid)) - { - Debug.LogWarning($"Skipping a packages DLL that didn't have a valid guid in the .meta file: '{packageDllPath}'"); - continue; - } + WinMDInfo toAdd = new WinMDInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetPath); + winmds.Add(toAdd); } - - bool isManaged = Utilities.IsManagedAssembly(packageDllPath); - PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, guid, packageDllPath, isManaged ? PluginType.Managed : PluginType.Native); - toReturn.Add(toAdd); } - return toReturn; - } - - private List ScanForWinMDs() - { - List toReturn = new List(); - - foreach (string assetWinmdPath in Directory.GetFiles(Utilities.AssetPath, "*.winmd", SearchOption.AllDirectories)) + IEnumerable packageReferences = Directory.GetFiles(Utilities.PackageLibraryCachePath, "*.*", SearchOption.AllDirectories) + .Where(file => file.ToLower().EndsWith(".dll") || file.ToLower().EndsWith(".winmd")); + foreach (string packagePath in packageReferences) { - string assetRelativePath = Utilities.GetAssetsRelativePathFrom(assetWinmdPath); - PluginImporter importer = (PluginImporter)AssetImporter.GetAtPath(assetRelativePath); - if (importer == null) - { - Debug.LogWarning($"Didn't get an importer for '{assetRelativePath}', most likely due to it being in a Unity hidden folder (prefixed by a .)"); - continue; - } - - WinMDInfo toAdd = new WinMDInfo(this, Guid.Parse(AssetDatabase.AssetPathToGUID(assetRelativePath)), assetWinmdPath); - toReturn.Add(toAdd); - } - - foreach (string packageWinmdPath in Directory.GetFiles(Utilities.PackageLibraryCachePath, "*.winmd", SearchOption.AllDirectories)) - { - string metaPath = packageWinmdPath + ".meta"; + string metaPath = packagePath + ".meta"; if (!File.Exists(metaPath)) { - Debug.LogWarning($"Skipping a packages winmd that didn't have an associated meta: '{packageWinmdPath}'"); + Debug.LogWarning($"Skipping a packages reference that didn't have an associated meta: '{packagePath}'"); continue; } Guid guid; @@ -392,17 +360,24 @@ private List ScanForWinMDs() string guidLine = reader.ReadUntil("guid"); if (!Guid.TryParse(guidLine.Split(':')[1].Trim(), out guid)) { - Debug.LogWarning($"Skipping a packages winmd that didn't have a valid guid in the .meta file: '{packageWinmdPath}'"); + Debug.LogWarning($"Skipping a packages reference that didn't have a valid guid in the .meta file: '{packagePath}'"); continue; } } - WinMDInfo toAdd = new WinMDInfo(this, guid, packageWinmdPath); - toReturn.Add(toAdd); + if (packagePath.EndsWith(".dll")) + { + bool isManaged = Utilities.IsManagedAssembly(packagePath); + PluginAssemblyInfo toAdd = new PluginAssemblyInfo(this, guid, packagePath, isManaged ? PluginType.Managed : PluginType.Native); + plugins.Add(toAdd); + } + else if (packagePath.EndsWith(".winmd")) + { + WinMDInfo toAdd = new WinMDInfo(this, guid, packagePath); + winmds.Add(toAdd); + } } - - return toReturn; } } } -#endif +#endif \ No newline at end of file From 29ac5a5601edb0724a0c5ffc43127b886465d22c Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 8 Jan 2020 09:55:37 -0800 Subject: [PATCH 3/7] remove logs --- .../Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs index 094667e..9302a32 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs @@ -273,10 +273,8 @@ private CSProjectInfo GetProjectInfo(Dictionary projectsM Uri dependencies = new Uri(Path.Combine(Utilities.AssetPath, "Dependencies\\")); foreach (PluginAssemblyInfo plugin in Plugins.Where(t => t.Type != PluginType.Native)) { - Debug.Log($"Plugin: {plugin.Name} {plugin.Type} {plugin.AutoReferenced} {plugin.ReferencePath}"); if (!dependencies.IsBaseOf(plugin.ReferencePath) && (plugin.AutoReferenced || assemblyDefinitionInfo.PrecompiledAssemblyReferences.Contains(plugin.Name))) { - Debug.Log($"Plugin referenced: {plugin.Name}"); toReturn.AddDependency(plugin); } } From 3c21ca7d934ff6ab870505a241e1469d2872c1ce Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 8 Jan 2020 09:59:19 -0800 Subject: [PATCH 4/7] update stale comment --- .../Editor/ProjectGenerator/Scripts/WinMDInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs index 264d4d2..4828e3e 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs @@ -78,7 +78,7 @@ private void ParseYAMLFile() } else { - // If it's not defineConstraints, then it's one of the other 3 + // If it's not defineConstraints, check next for platformData platformData = defineConstraints; } From 9da276e443514eaf0217ed42bab405ffd5cea965 Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 8 Jan 2020 12:29:02 -0800 Subject: [PATCH 5/7] address review comments --- .../Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs index 9302a32..570061d 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs @@ -317,7 +317,7 @@ private void ScanForReferences(out List plugins, out List(); winmds = new List(); - IEnumerable assetReferences = Directory.GetFiles(Utilities.AssetPath, "*.*", SearchOption.AllDirectories) + IEnumerable assetReferences = Directory.EnumerateFiles(Utilities.AssetPath, "*.*", SearchOption.AllDirectories) .Where(file => file.ToLower().EndsWith(".dll") || file.ToLower().EndsWith(".winmd")); foreach (string assetPath in assetReferences) { @@ -341,7 +341,7 @@ private void ScanForReferences(out List plugins, out List packageReferences = Directory.GetFiles(Utilities.PackageLibraryCachePath, "*.*", SearchOption.AllDirectories) + IEnumerable packageReferences = Directory.EnumerateFiles(Utilities.PackageLibraryCachePath, "*.*", SearchOption.AllDirectories) .Where(file => file.ToLower().EndsWith(".dll") || file.ToLower().EndsWith(".winmd")); foreach (string packagePath in packageReferences) { From 3cfe36617dfbe80cbeb447a572e5a7a8c651f692 Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 8 Jan 2020 12:50:23 -0800 Subject: [PATCH 6/7] only add references when winmds are in a good state --- .../Scripts/UnityProjectInfo.cs | 9 +++++- .../ProjectGenerator/Scripts/WinMDInfo.cs | 28 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs index 570061d..c9f54a2 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs @@ -283,7 +283,14 @@ private CSProjectInfo GetProjectInfo(Dictionary projectsM { if (!dependencies.IsBaseOf(winmd.ReferencePath)) { - toReturn.AddDependency(winmd); + if (winmd.IsValid) + { + toReturn.AddDependency(winmd); + } + else + { + Debug.LogWarning($"References to {winmd} were excluded because the winmd is configured incorrectly."); + } } } } diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs index 4828e3e..e524003 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/WinMDInfo.cs @@ -29,6 +29,8 @@ public class WinMDInfo : ReferenceItemInfo /// public HashSet DefineConstraints { get; private set; } + public bool IsValid { get; private set; } + /// /// Creates a new instance of the . /// @@ -102,11 +104,8 @@ private void ParseYAMLFile() Dictionary playerPlatforms = new Dictionary(); - TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "Win", BuildTarget.StandaloneWindows); - TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "Win64", BuildTarget.StandaloneWindows64); + IsValid = VerifyEnabledPlatforms(enabledPlatforms); TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "WindowsStoreApps", BuildTarget.WSAPlayer); - TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "iOS", BuildTarget.iOS); - TryAddEnabledPlatform(playerPlatforms, enabledPlatforms, "Android", BuildTarget.Android); FilterPlatformsBasedOnDefineConstraints(inEditorPlatforms, true); FilterPlatformsBasedOnDefineConstraints(playerPlatforms, false); @@ -232,6 +231,27 @@ private void TryAddEnabledPlatform(Dictionary enabledPlatforms) + { + bool valid = true; + foreach (KeyValuePair platform in enabledPlatforms) + { + if (platform.Value && + (platform.Key == "Win" || + platform.Key == "Win64" || + platform.Key == "iOS" || + platform.Key == "Android" || + platform.Key == "Editor")) + { + Debug.LogError($"WinMDs should only be enabled for the WSA Player; however, {ReferencePath} was configured to support {platform.Key}."); + valid = false; + break; + } + } + + return valid; + } } } #endif \ No newline at end of file From 95026ee87c1e5d17aa75dcc53591f239bd87a297 Mon Sep 17 00:00:00 2001 From: Chris Barth Date: Wed, 8 Jan 2020 14:46:44 -0800 Subject: [PATCH 7/7] fix coment --- .../Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs index c9f54a2..af4ea3b 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/UnityProjectInfo.cs @@ -289,7 +289,7 @@ private CSProjectInfo GetProjectInfo(Dictionary projectsM } else { - Debug.LogWarning($"References to {winmd} were excluded because the winmd is configured incorrectly."); + Debug.LogError($"References to {winmd} were excluded because the winmd is configured incorrectly. Make sure this winmd is setup to only support WSAPlayer in the Unity inspector."); } } }