From 150818b1709473bc25a5d8c04fc97e0b963657c9 Mon Sep 17 00:00:00 2001 From: Andrei Borodin Date: Thu, 30 Jan 2020 13:24:30 -0800 Subject: [PATCH 1/3] Updates the token file mechanism for re-gen to take into account the current version of MSB4U. --- ...pendenciesProjectTemplate.g.props.template | 2 +- .../MSBuildForUnity.Common.props.template | 2 +- .../Scripts/Exporters/ICommonPropsExporter.cs | 6 +++ .../ITopLevelDependenciesProjectExporter.cs | 5 ++ .../TemplatedCommonPropsExporter.cs | 5 ++ ...atedTopLevelDependenciesProjectExporter.cs | 15 +++--- .../ProjectGenerator/Scripts/MSBuildTools.cs | 50 +++++++++++++++---- .../Scripts/MSBuildUnityProjectExporter.cs | 6 ++- 8 files changed, 72 insertions(+), 19 deletions(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/DependenciesProjectTemplate.g.props.template b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/DependenciesProjectTemplate.g.props.template index 4b18e40..f295722 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/DependenciesProjectTemplate.g.props.template +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/DependenciesProjectTemplate.g.props.template @@ -23,7 +23,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/MSBuildForUnity.Common.props.template b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/MSBuildForUnity.Common.props.template index 4b3e3ec..b4fed3f 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/MSBuildForUnity.Common.props.template +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/MSBuildTemplates/MSBuildForUnity.Common.props.template @@ -10,7 +10,7 @@ - 0.8.3 + $(_MSBuildForUnityGeneratedOutputDirectory)\Projects $(_MSBuildForUnityGeneratedOutputDirectory)\Output diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ICommonPropsExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ICommonPropsExporter.cs index 3f53892..8a968f5 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ICommonPropsExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ICommonPropsExporter.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. #if UNITY_EDITOR +using System; using System.IO; namespace Microsoft.Build.Unity.ProjectGeneration.Exporters @@ -11,6 +12,11 @@ namespace Microsoft.Build.Unity.ProjectGeneration.Exporters /// public interface ICommonPropsExporter { + /// + /// Gets or sets the current MSBuildForUnity version. + /// + Version MSBuildForUnityVersion { get; set; } + /// /// Gets or sets the Unity major version. /// diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ITopLevelDependenciesProjectExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ITopLevelDependenciesProjectExporter.cs index 7d4fb1e..17e23bd 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ITopLevelDependenciesProjectExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/ITopLevelDependenciesProjectExporter.cs @@ -17,6 +17,11 @@ public interface ITopLevelDependenciesProjectExporter /// Guid Guid { get; set; } + /// + /// Gets or sets the MSBuildForUnity version. + /// + Version MSBuildForUnityVersion { get; set; } + /// /// Gets the set of references for this project. /// diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs index c58fe04..ba32da0 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs @@ -3,12 +3,14 @@ #if UNITY_EDITOR using Microsoft.Build.Unity.ProjectGeneration.Templates; +using System; using System.IO; namespace Microsoft.Build.Unity.ProjectGeneration.Exporters.TemplatedExporter { internal class TemplatedCommonPropsExporter : ICommonPropsExporter { + private const string MSBuildForUnityVersionToken = "MSB4U_VERSION"; private const string UnityMajorVersionToken = "UNITY_MAJOR_VERSION"; private const string UnityMinorVersionToken = "UNITY_MINOR_VERSION"; private const string UnityEditorInstallPathToken = "UNITY_EDITOR_INSTALL_FOLDER"; @@ -20,6 +22,8 @@ internal class TemplatedCommonPropsExporter : ICommonPropsExporter private readonly FileTemplate fileTemplate; private readonly FileInfo exportPath; + public Version MSBuildForUnityVersion { get; set; } + public string UnityMajorVersion { get; set; } public string UnityMinorVersion { get; set; } @@ -44,6 +48,7 @@ public void Write() { TemplatedWriter writer = new TemplatedWriter(fileTemplate); + writer.Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString(3)); writer.Write(UnityMajorVersionToken, UnityMajorVersion); writer.Write(UnityMinorVersionToken, UnityMinorVersion); writer.Write(UnityEditorInstallPathToken, UnityEditorInstallPath.FullName); diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs index b7b80b9..bcd78f9 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs @@ -15,6 +15,7 @@ namespace Microsoft.Build.Unity.ProjectGeneration.Exporters.TemplatedExporter internal class TemplatedTopLevelDependenciesProjectExporter : ITopLevelDependenciesProjectExporter { private const string ProjectGuidToken = "PROJECT_GUID"; + private const string MSBuildForUnityVersionToken = "MSB4U_VERSION"; private const string ProjectReferenceTemplate = "PROJECT_REFERENCE"; private const string ProjectReferenceTemplate_ReferenceToken = "REFERENCE"; @@ -32,6 +33,8 @@ internal class TemplatedTopLevelDependenciesProjectExporter : ITopLevelDependenc public Guid Guid { get; set; } + public Version MSBuildForUnityVersion { get; set; } + public HashSet References { get; } = new HashSet(); public TemplatedTopLevelDependenciesProjectExporter(FileTemplate primaryTemplateFile, FileTemplate propsTemplateFile, FileTemplate targetsTemplateFile, @@ -48,15 +51,15 @@ public TemplatedTopLevelDependenciesProjectExporter(FileTemplate primaryTemplate public void Write() { - TemplatedWriter propsWriter = new TemplatedWriter(propsTemplateFile); - - propsWriter.Write(ProjectGuidToken, Guid); + TemplatedWriter propsWriter = new TemplatedWriter(propsTemplateFile) + .Write(ProjectGuidToken, Guid) + .Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString(3)); foreach (ProjectReference projectReference in References) { - TemplatedWriter referenceWriter = propsWriter.CreateWriterFor(ProjectReferenceTemplate); - referenceWriter.Write(ProjectReferenceTemplate_ReferenceToken, projectReference.ReferencePath.LocalPath); - referenceWriter.Write(ProjectReferenceTemplate_ConditionToken, projectReference.Condition ?? string.Empty); + TemplatedWriter referenceWriter = propsWriter.CreateWriterFor(ProjectReferenceTemplate) + .Write(ProjectReferenceTemplate_ReferenceToken, projectReference.ReferencePath.LocalPath) + .Write(ProjectReferenceTemplate_ConditionToken, projectReference.Condition ?? string.Empty); if (projectReference.IsGenerated) { diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs index 2cab5c2..ec2177f 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs @@ -179,7 +179,7 @@ public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget n public const string CSharpVersion = "7.3"; public const string AutoGenerate = "MSBuild/Auto Generation Enabled"; - private static readonly string TokenFilePath = Path.Combine(Utilities.ProjectPath, "Temp", "PropsGeneratedThisEditorInstance.token"); + public static readonly Version MSBuildForUnityVersion = new Version(0, 8, 3); public static readonly Version DefaultMinUWPSDK = new Version("10.0.14393.0"); private static UnityProjectInfo unityProjectInfo; @@ -285,12 +285,16 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.CleanProfileName); } - bool doesTokenFileExist = File.Exists(TokenFilePath); + // Get the token file in the Unity Temp directory, if it exists. + Version tokenVerison = GetCurrentTokenVersion(); + + // We regenerate, if the token file exists, and it's current version. + bool doesCurrentVersionTokenFileExist = tokenVerison != null && tokenVerison == MSBuildForUnityVersion; // We regenerate everything if: // - We are forced to // - AutoGenerateEnabled and token file doesn't exist or shouldClean is true - bool regenerateEverything = forceGenerateEverything || (Config.AutoGenerateEnabled && (!doesTokenFileExist || shouldClean)); + bool regenerateEverything = forceGenerateEverything || (Config.AutoGenerateEnabled && (!doesCurrentVersionTokenFileExist || shouldClean)); if (regenerateEverything || unityProjectInfo == null) { @@ -301,9 +305,9 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo // We regenerate the common "directory" props file under the following conditions: // - Token file doesn't exist which means editor was just started // - EditorPrefs currentBuildTarget or targetFramework is different from current ones (same as for executing a clean) - if (shouldClean || !doesTokenFileExist) + if (shouldClean || !doesCurrentVersionTokenFileExist) { - MSBuildUnityProjectExporter.ExportCommonPropsFile(Exporter, unityProjectInfo.CurrentPlayerPlatform); + MSBuildUnityProjectExporter.ExportCommonPropsFile(Exporter, MSBuildForUnityVersion, unityProjectInfo.CurrentPlayerPlatform); } if (regenerateEverything) @@ -311,9 +315,15 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo RegenerateEverything(unityProjectInfo, Config.AutoGenerateEnabled || forceCompleteGeneration); } - if (!doesTokenFileExist) + if (!doesCurrentVersionTokenFileExist) { - File.Create(TokenFilePath).Dispose(); + foreach (string tokenFile in Directory.GetFiles(Path.Combine(Utilities.ProjectPath, "Temp"), "*_token.msb4u", SearchOption.TopDirectoryOnly)) + { + File.Delete(tokenFile); + } + + File.Create(Path.Combine(Utilities.ProjectPath, "Temp", $"{MSBuildForUnityVersion.ToString(3)}_token.msb4u")) + .Dispose(); } // Write the current targetframework and build target @@ -327,6 +337,28 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo } } + private static Version GetCurrentTokenVersion() + { + string[] file = Directory.GetFiles(Path.Combine(Utilities.ProjectPath, "Temp"), "*_token.msb4u", SearchOption.TopDirectoryOnly); + + if (file.Length > 0) + { + string versionNumber = Path.GetFileNameWithoutExtension(file[0]).Split('_')[0]; + + string[] versionParts = versionNumber.Split('.'); + + if (versionParts.Length == 3 + && int.TryParse(versionParts[0], out int major) + && int.TryParse(versionParts[1], out int minor) + && int.TryParse(versionParts[2], out int patch)) + { + return new Version(major, minor, patch); + } + } + + return null; + } + private static void ExportCoreUnityPropFiles(UnityProjectInfo unityProjectInfo) { foreach (CompilationPlatformInfo platform in unityProjectInfo.AvailablePlatforms) @@ -364,7 +396,7 @@ private static void RegenerateEverything(UnityProjectInfo unityProjectInfo, bool postCleanupAndCopyStamp = stopwatch.ElapsedMilliseconds; propsFileGenerationStart = stopwatch.ElapsedMilliseconds; - MSBuildUnityProjectExporter.ExportCommonPropsFile(Exporter, unityProjectInfo.CurrentPlayerPlatform); + MSBuildUnityProjectExporter.ExportCommonPropsFile(Exporter, MSBuildForUnityVersion, unityProjectInfo.CurrentPlayerPlatform); if (completeGeneration) { ExportCoreUnityPropFiles(unityProjectInfo); @@ -378,7 +410,7 @@ private static void RegenerateEverything(UnityProjectInfo unityProjectInfo, bool unityProjectInfo.ExportSolution(Exporter, new FileInfo(Exporter.GetSolutionFilePath(unityProjectInfo)), directoryInfo); unityProjectInfo.ExportProjects(Exporter, directoryInfo); } - MSBuildUnityProjectExporter.ExportTopLevelDependenciesProject(Exporter, Config, new DirectoryInfo(Utilities.MSBuildProjectFolder), unityProjectInfo); + MSBuildUnityProjectExporter.ExportTopLevelDependenciesProject(Exporter, MSBuildForUnityVersion, Config, new DirectoryInfo(Utilities.MSBuildProjectFolder), unityProjectInfo); solutionExportEnd = stopwatch.ElapsedMilliseconds; foreach (string otherFile in TemplateFiles.Instance.OtherFiles) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildUnityProjectExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildUnityProjectExporter.cs index 6c9875c..bbd6c5c 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildUnityProjectExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildUnityProjectExporter.cs @@ -61,9 +61,10 @@ public static void ExportCoreUnityPropFile(IUnityProjectExporter exporter, Compi /// /// The overal exporter to use for creating exporters. /// Current unity platform. - public static void ExportCommonPropsFile(IUnityProjectExporter exporter, CompilationPlatformInfo currentPlayerPlatform) + public static void ExportCommonPropsFile(IUnityProjectExporter exporter, Version msb4uVersion, CompilationPlatformInfo currentPlayerPlatform) { ICommonPropsExporter propsExporter = exporter.CreateCommonPropsExporter(new FileInfo(Path.Combine(Utilities.ProjectPath, "MSBuildForUnity.Common.props"))); + propsExporter.MSBuildForUnityVersion = msb4uVersion; string[] versionParts = Application.unityVersion.Split('.'); propsExporter.UnityMajorVersion = versionParts[0]; @@ -79,11 +80,12 @@ public static void ExportCommonPropsFile(IUnityProjectExporter exporter, Compila propsExporter.Write(); } - public static void ExportTopLevelDependenciesProject(IUnityProjectExporter exporter, MSBuildToolsConfig config, DirectoryInfo generatedProjectFolder, UnityProjectInfo unityProjectInfo) + public static void ExportTopLevelDependenciesProject(IUnityProjectExporter exporter, Version msb4uVerison, MSBuildToolsConfig config, DirectoryInfo generatedProjectFolder, UnityProjectInfo unityProjectInfo) { string projectPath = GetProjectFilePath(Utilities.AssetPath, $"{unityProjectInfo.UnityProjectName}.Dependencies"); ITopLevelDependenciesProjectExporter projectExporter = exporter.CreateTopLevelDependenciesProjectExporter(new FileInfo(projectPath), generatedProjectFolder); + projectExporter.MSBuildForUnityVersion = msb4uVerison; projectExporter.Guid = config.DependenciesProjectGuid; if (unityProjectInfo.AvailablePlatforms != null) From 917d8b4823718fe2b1241637c3e5f19cb926b3db Mon Sep 17 00:00:00 2001 From: Andrei Borodin Date: Thu, 30 Jan 2020 13:52:30 -0800 Subject: [PATCH 2/3] Responded to comments, and updated regen logic. --- .../MSBuild/settings.json | 2 +- .../MSBuild/settings.json | 2 +- .../MSBuild/settings.json | 2 +- .../TemplatedCommonPropsExporter.cs | 2 +- ...atedTopLevelDependenciesProjectExporter.cs | 2 +- .../ProjectGenerator/Scripts/MSBuildTools.cs | 54 +++++++++---------- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Samples/CrossUnityDependencies.Unity/MSBuild/settings.json b/Samples/CrossUnityDependencies.Unity/MSBuild/settings.json index aac74b9..caaf48a 100644 --- a/Samples/CrossUnityDependencies.Unity/MSBuild/settings.json +++ b/Samples/CrossUnityDependencies.Unity/MSBuild/settings.json @@ -1 +1 @@ -{"version":3,"autoGenerateEnabled":true,"dependenciesProjectGuid":"f462fc4f-630c-4212-83ae-9208d85ad084","assemblyCSharpGuid":"35f18cf2-8f12-4108-b9f8-d34479756cd6","assemblyCSharpEditorGuid":"df8f1f7e-2119-4936-8901-2097aaf93cf4","assemblyCSharpFirstPassGuid":"cf1ec4f7-e2bb-4d55-949d-a039c5f1b4c2","assemblyCSharpFirstPassEditorGuid":"ac8eb4c9-8a89-4293-be50-54959b7aa5b7","builtInPackagesFolderGuid":"f7ce48f1-7bbc-4628-a728-6afec7c66b71","importedPackagesFolderGuid":"e6b8ba08-82d8-4266-93d4-0a9770d70a66","externalPackagesFolderGuid":"53c6b76f-fa9e-4bc0-9475-9a0944c6d7f5","solutionGuid":"79c75d6a-84d9-443a-98f8-4de7ac4365dc"} \ No newline at end of file +{"version":3,"fullGenerationEnabled":true,"dependenciesProjectGuid":"f462fc4f-630c-4212-83ae-9208d85ad084","assemblyCSharpGuid":"35f18cf2-8f12-4108-b9f8-d34479756cd6","assemblyCSharpEditorGuid":"df8f1f7e-2119-4936-8901-2097aaf93cf4","assemblyCSharpFirstPassGuid":"cf1ec4f7-e2bb-4d55-949d-a039c5f1b4c2","assemblyCSharpFirstPassEditorGuid":"ac8eb4c9-8a89-4293-be50-54959b7aa5b7","builtInPackagesFolderGuid":"f7ce48f1-7bbc-4628-a728-6afec7c66b71","importedPackagesFolderGuid":"e6b8ba08-82d8-4266-93d4-0a9770d70a66","externalPackagesFolderGuid":"53c6b76f-fa9e-4bc0-9475-9a0944c6d7f5","solutionGuid":"79c75d6a-84d9-443a-98f8-4de7ac4365dc"} \ No newline at end of file diff --git a/Samples/IntegratedDependencies.Unity/MSBuild/settings.json b/Samples/IntegratedDependencies.Unity/MSBuild/settings.json index 80e8845..14a3da9 100644 --- a/Samples/IntegratedDependencies.Unity/MSBuild/settings.json +++ b/Samples/IntegratedDependencies.Unity/MSBuild/settings.json @@ -1 +1 @@ -{"version":3,"autoGenerateEnabled":true,"dependenciesProjectGuid":"0d77ab82-d4eb-4034-ac54-4ca04d06906c","assemblyCSharpGuid":"4989d6c6-d8b3-4556-b4a9-06093ded68ad","assemblyCSharpEditorGuid":"0cd3f705-4fb4-4a60-8d09-89dc9f0b38a2","assemblyCSharpFirstPassGuid":"5c2fd87a-9877-4af1-ace8-1eed615617c0","assemblyCSharpFirstPassEditorGuid":"eea5290c-d0ca-4efa-b53c-69b3606c8bf2","builtInPackagesFolderGuid":"f78b56e6-cdfd-4bf5-9c51-6a8989cb7c6d","importedPackagesFolderGuid":"f0962e2e-3201-42a4-90a4-4bd07b8d0413","externalPackagesFolderGuid":"02cfe9b1-8003-483f-802b-f2acc2e2c82b","solutionGuid":"6e6cc69e-a194-4f01-9182-ce7b0f63f375"} \ No newline at end of file +{"version":3,"fullGenerationEnabled":true,"dependenciesProjectGuid":"0d77ab82-d4eb-4034-ac54-4ca04d06906c","assemblyCSharpGuid":"4989d6c6-d8b3-4556-b4a9-06093ded68ad","assemblyCSharpEditorGuid":"0cd3f705-4fb4-4a60-8d09-89dc9f0b38a2","assemblyCSharpFirstPassGuid":"5c2fd87a-9877-4af1-ace8-1eed615617c0","assemblyCSharpFirstPassEditorGuid":"eea5290c-d0ca-4efa-b53c-69b3606c8bf2","builtInPackagesFolderGuid":"f78b56e6-cdfd-4bf5-9c51-6a8989cb7c6d","importedPackagesFolderGuid":"f0962e2e-3201-42a4-90a4-4bd07b8d0413","externalPackagesFolderGuid":"02cfe9b1-8003-483f-802b-f2acc2e2c82b","solutionGuid":"6e6cc69e-a194-4f01-9182-ce7b0f63f375"} \ No newline at end of file diff --git a/Samples/SimpleNuGetDependency.Unity/MSBuild/settings.json b/Samples/SimpleNuGetDependency.Unity/MSBuild/settings.json index 3a11673..f14ca47 100644 --- a/Samples/SimpleNuGetDependency.Unity/MSBuild/settings.json +++ b/Samples/SimpleNuGetDependency.Unity/MSBuild/settings.json @@ -1 +1 @@ -{"version":3,"autoGenerateEnabled":false,"dependenciesProjectGuid":"e8876134-cce4-41b3-ab88-c3fbe5054847","assemblyCSharpGuid":"7bf3dda0-c67f-4423-8b23-f8ff7cbe5675","assemblyCSharpEditorGuid":"207db2b0-7820-489e-b53b-305058b18b5a","assemblyCSharpFirstPassGuid":"f64e1178-7b6f-4327-9507-ddadf821c230","assemblyCSharpFirstPassEditorGuid":"e5126e49-4984-43f0-90c5-978a9fd9ca84","builtInPackagesFolderGuid":"3c0655a2-0a72-4e5b-946f-00c3d7fad32a","importedPackagesFolderGuid":"7db99f50-7e71-432c-aae2-358a5bef69db","externalPackagesFolderGuid":"c1cc1a54-92d9-4d95-ac8f-1074bd46c449","solutionGuid":"3b4041bd-c118-4506-8256-1cb8ca716e78"} \ No newline at end of file +{"version":3,"fullGenerationEnabled":false,"dependenciesProjectGuid":"e8876134-cce4-41b3-ab88-c3fbe5054847","assemblyCSharpGuid":"7bf3dda0-c67f-4423-8b23-f8ff7cbe5675","assemblyCSharpEditorGuid":"207db2b0-7820-489e-b53b-305058b18b5a","assemblyCSharpFirstPassGuid":"f64e1178-7b6f-4327-9507-ddadf821c230","assemblyCSharpFirstPassEditorGuid":"e5126e49-4984-43f0-90c5-978a9fd9ca84","builtInPackagesFolderGuid":"3c0655a2-0a72-4e5b-946f-00c3d7fad32a","importedPackagesFolderGuid":"7db99f50-7e71-432c-aae2-358a5bef69db","externalPackagesFolderGuid":"c1cc1a54-92d9-4d95-ac8f-1074bd46c449","solutionGuid":"3b4041bd-c118-4506-8256-1cb8ca716e78"} \ No newline at end of file diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs index ba32da0..9b40630 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedCommonPropsExporter.cs @@ -48,7 +48,7 @@ public void Write() { TemplatedWriter writer = new TemplatedWriter(fileTemplate); - writer.Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString(3)); + writer.Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString()); writer.Write(UnityMajorVersionToken, UnityMajorVersion); writer.Write(UnityMinorVersionToken, UnityMinorVersion); writer.Write(UnityEditorInstallPathToken, UnityEditorInstallPath.FullName); diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs index bcd78f9..d02ba5d 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/Exporters/TemplatedExporter/TemplatedTopLevelDependenciesProjectExporter.cs @@ -53,7 +53,7 @@ public void Write() { TemplatedWriter propsWriter = new TemplatedWriter(propsTemplateFile) .Write(ProjectGuidToken, Guid) - .Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString(3)); + .Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString()); foreach (ProjectReference projectReference in References) { diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs index ec2177f..6baa11c 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs @@ -26,7 +26,7 @@ public class MSBuildToolsConfig private int version = 0; [SerializeField] - private bool autoGenerateEnabled = false; + private bool fullGenerationEnabled = false; [SerializeField] private string dependenciesProjectGuid = Guid.NewGuid().ToString(); @@ -55,12 +55,12 @@ public class MSBuildToolsConfig [SerializeField] private string solutionGuid = Guid.NewGuid().ToString(); - public bool AutoGenerateEnabled + public bool FullGenerationEnabled { - get => autoGenerateEnabled; + get => fullGenerationEnabled; set { - autoGenerateEnabled = value; + fullGenerationEnabled = value; Save(); } } @@ -177,7 +177,7 @@ public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget n }; public const string CSharpVersion = "7.3"; - public const string AutoGenerate = "MSBuild/Auto Generation Enabled"; + public const string FullGeneration = "MSBuild/Full Generation Enabled"; public static readonly Version MSBuildForUnityVersion = new Version(0, 8, 3); public static readonly Version DefaultMinUWPSDK = new Version("10.0.14393.0"); @@ -199,19 +199,19 @@ public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget n public static MSBuildToolsConfig Config { get; } = MSBuildToolsConfig.Load(); - [MenuItem(AutoGenerate, priority = 101)] + [MenuItem(FullGeneration, priority = 101)] public static void ToggleAutoGenerate() { - Config.AutoGenerateEnabled = !Config.AutoGenerateEnabled; - Menu.SetChecked(AutoGenerate, Config.AutoGenerateEnabled); + Config.FullGenerationEnabled = !Config.FullGenerationEnabled; + Menu.SetChecked(FullGeneration, Config.FullGenerationEnabled); // If we just toggled on, regenerate everything RefreshGeneratedOutput(forceGenerateEverything: true, forceCompleteGeneration: false); } - [MenuItem(AutoGenerate, true, priority = 101)] + [MenuItem(FullGeneration, true, priority = 101)] public static bool ToggleAutoGenerate_Validate() { - Menu.SetChecked(AutoGenerate, Config.AutoGenerateEnabled); + Menu.SetChecked(FullGeneration, Config.FullGenerationEnabled); return true; } @@ -275,11 +275,11 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo BuildTarget currentBuildTarget = EditorUserBuildSettings.activeBuildTarget; ApiCompatibilityLevel targetFramework = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup); - bool shouldClean = EditorPrefs.GetInt($"{nameof(MSBuildTools)}.{nameof(currentBuildTarget)}") != (int)currentBuildTarget + bool buildTargetOrFrameworkChanged = EditorPrefs.GetInt($"{nameof(MSBuildTools)}.{nameof(currentBuildTarget)}") != (int)currentBuildTarget || EditorPrefs.GetInt($"{nameof(MSBuildTools)}.{nameof(targetFramework)}") != (int)targetFramework || forceGenerateEverything; - if (shouldClean) + if (buildTargetOrFrameworkChanged) { // We clean up previous build if the EditorPrefs currentBuildTarget or targetFramework is different from current ones. MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.CleanProfileName); @@ -291,30 +291,26 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo // We regenerate, if the token file exists, and it's current version. bool doesCurrentVersionTokenFileExist = tokenVerison != null && tokenVerison == MSBuildForUnityVersion; - // We regenerate everything if: - // - We are forced to + // We perform the regeneration of complete or partial pass in the following cases: + // - forceGenerateEverything is true (we are told to) + // - buildTargetOrFrameworkChanged is true (target framework changed) + // - doesCurrentVersionTokenFileExist is false (version changed, or editor just opened) + // - AutoGenerateEnabled and token file doesn't exist or shouldClean is true - bool regenerateEverything = forceGenerateEverything || (Config.AutoGenerateEnabled && (!doesCurrentVersionTokenFileExist || shouldClean)); + bool performRegeneration = forceGenerateEverything || buildTargetOrFrameworkChanged || !doesCurrentVersionTokenFileExist; - if (regenerateEverything || unityProjectInfo == null) + if (performRegeneration || unityProjectInfo == null) { // Create the project info only if it's null or we need to regenerate - unityProjectInfo = new UnityProjectInfo(Debug.unityLogger, SupportedBuildTargets, Config, Config.AutoGenerateEnabled || forceCompleteGeneration); - } - - // We regenerate the common "directory" props file under the following conditions: - // - Token file doesn't exist which means editor was just started - // - EditorPrefs currentBuildTarget or targetFramework is different from current ones (same as for executing a clean) - if (shouldClean || !doesCurrentVersionTokenFileExist) - { - MSBuildUnityProjectExporter.ExportCommonPropsFile(Exporter, MSBuildForUnityVersion, unityProjectInfo.CurrentPlayerPlatform); + unityProjectInfo = new UnityProjectInfo(Debug.unityLogger, SupportedBuildTargets, Config, Config.FullGenerationEnabled || forceCompleteGeneration); } - if (regenerateEverything) + if (performRegeneration) { - RegenerateEverything(unityProjectInfo, Config.AutoGenerateEnabled || forceCompleteGeneration); + // If we are forced complete, then we regenerate, otherwise perform the one that is selected + RegenerateEverything(unityProjectInfo, Config.FullGenerationEnabled || forceCompleteGeneration); } - + if (!doesCurrentVersionTokenFileExist) { foreach (string tokenFile in Directory.GetFiles(Path.Combine(Utilities.ProjectPath, "Temp"), "*_token.msb4u", SearchOption.TopDirectoryOnly)) @@ -331,7 +327,7 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo EditorPrefs.SetInt($"{nameof(MSBuildTools)}.{nameof(targetFramework)}", (int)targetFramework); // If we cleaned, now build - if (shouldClean) + if (buildTargetOrFrameworkChanged) { MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.BuildProfileName); } From 1389a6895a89385d9b8aed14464f222dccf62a73 Mon Sep 17 00:00:00 2001 From: Andrei Borodin Date: Thu, 30 Jan 2020 13:57:20 -0800 Subject: [PATCH 3/3] Added formerly serialized as --- .../Editor/ProjectGenerator/Scripts/MSBuildTools.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs index 6baa11c..3f26fbc 100644 --- a/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs +++ b/Source/MSBuildTools.Unity/Packages/com.microsoft.msbuildforunity/Editor/ProjectGenerator/Scripts/MSBuildTools.cs @@ -12,6 +12,7 @@ using UnityEditor; using UnityEditor.Build; using UnityEngine; +using UnityEngine.Serialization; using Debug = UnityEngine.Debug; namespace Microsoft.Build.Unity.ProjectGeneration @@ -25,6 +26,7 @@ public class MSBuildToolsConfig [SerializeField] private int version = 0; + [FormerlySerializedAs("autoGenerateEnabled")] [SerializeField] private bool fullGenerationEnabled = false; @@ -310,7 +312,7 @@ private static void RefreshGeneratedOutput(bool forceGenerateEverything, bool fo // If we are forced complete, then we regenerate, otherwise perform the one that is selected RegenerateEverything(unityProjectInfo, Config.FullGenerationEnabled || forceCompleteGeneration); } - + if (!doesCurrentVersionTokenFileExist) { foreach (string tokenFile in Directory.GetFiles(Path.Combine(Utilities.ProjectPath, "Temp"), "*_token.msb4u", SearchOption.TopDirectoryOnly))