From 8529b300486e8f637c23464ba71c12001a2d4275 Mon Sep 17 00:00:00 2001 From: mfournier Date: Sun, 25 Oct 2020 20:42:06 -0400 Subject: [PATCH] XboxLivePostProcessing - Remove dependency on Visual Studio Tools for Unity This post-processing step used a functionality of Visual Studio Tools for Unity for which there is an equivalent in Unity (at least in 2019.4.3f1). By removing this dependency, it removes the obligation of having Visual Studio Tools for Unity installed on the machine building the project using Xbox Live plugin. I moved the replaced functionality from XboxLivePostProcessing.cs to XboxLivePostProcessingUnityProject.cs. --- .../Editor/XboxLivePostProcessing.cs | 37 +------------- .../XboxLivePostProcessingUnityProject.cs | 48 +++++++++++++++++++ ...XboxLivePostProcessingUnityProject.cs.meta | 11 +++++ 3 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs create mode 100644 Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs.meta diff --git a/Assets/Xbox Live/Editor/XboxLivePostProcessing.cs b/Assets/Xbox Live/Editor/XboxLivePostProcessing.cs index bfd98398..e1d1a090 100644 --- a/Assets/Xbox Live/Editor/XboxLivePostProcessing.cs +++ b/Assets/Xbox Live/Editor/XboxLivePostProcessing.cs @@ -3,7 +3,6 @@ // namespace Assets.Xbox_Live.Editor { - using System; using System.IO; using System.Xml; using System.Xml.Linq; @@ -11,52 +10,18 @@ namespace Assets.Xbox_Live.Editor using Microsoft.Xbox.Services; - using SyntaxTree.VisualStudio.Unity.Bridge; - using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; /// - /// Handles post processing the generated Visaul Studio projects in order to deal with DevCenter + /// Handles post processing the generated Visual Studio projects in order to deal with DevCenter /// association and including Xbox Live configuration files. /// [InitializeOnLoad] public class XboxLivePostProcessing { - static XboxLivePostProcessing() - { - ProjectFilesGenerator.ProjectFileGeneration += AddXboxServicesConfig; - } - - /// - /// Adds the XboxServices.config file to the generated project file. - /// - /// The name of the file being processed. - /// The content of the file being processed. - /// The project file with an additional content element included. - /// - /// This only modifies the Unity debug projects and will not have any - /// effect on projects built as part of the Unity UWP build process. - /// - private static string AddXboxServicesConfig(string fileName, string fileContent) - { - if (!fileName.EndsWith(".Editor.csproj")) - { - const string configFileElement = - " \r\n" + - " PreserveNewest\r\n" + - " \r\n"; - - // Hacky way to do this for now. Should make it a bit more stable. - int lastItemGroup = fileContent.LastIndexOf(" ", StringComparison.OrdinalIgnoreCase); - fileContent = fileContent.Insert(lastItemGroup, configFileElement); - } - - return fileContent; - } - [PostProcessBuild(1)] public static void OnPostprocessBuild(BuildTarget target, string solutionFolder) { diff --git a/Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs b/Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs new file mode 100644 index 00000000..54d83237 --- /dev/null +++ b/Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// +namespace Assets.Xbox_Live.Editor +{ + using System; + using Microsoft.Xbox.Services; + using UnityEditor; + + /// + /// Handles post processing the generated Visual Studio projects in order to deal with DevCenter + /// association and including Xbox Live configuration files. + /// + public class XboxLivePostProcessingUnityProject : AssetPostprocessor + { + private static string OnGeneratedCSProject(string path, string content) + { + return AddXboxServicesConfig(path, content); + } + + /// + /// Adds the XboxServices.config file to the generated project file. + /// + /// The name of the file being processed. + /// The content of the file being processed. + /// The project file with an additional content element included. + /// + /// This only modifies the Unity debug projects and will not have any + /// effect on projects built as part of the Unity UWP build process. + /// + private static string AddXboxServicesConfig(string fileName, string fileContent) + { + if (!fileName.EndsWith(".Editor.csproj")) + { + const string configFileElement = + " \r\n" + + " PreserveNewest\r\n" + + " \r\n"; + + // Hacky way to do this for now. Should make it a bit more stable. + int lastItemGroup = fileContent.LastIndexOf(" ", StringComparison.OrdinalIgnoreCase); + fileContent = fileContent.Insert(lastItemGroup, configFileElement); + } + + return fileContent; + } + } +} diff --git a/Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs.meta b/Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs.meta new file mode 100644 index 00000000..84c579ea --- /dev/null +++ b/Assets/Xbox Live/Editor/XboxLivePostProcessingUnityProject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4fe701e19650d9541b767bce400e693e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: