From 1caa9aba81f99a2030d6fd5c5c676ba8eb6b7529 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Fri, 3 Apr 2020 15:03:35 +0200 Subject: [PATCH] Update build script to add new projects to solutions (#2145) * Update build script to add new projects to solutions * Add check for getting visual studio type and error message * CR feedback for powershell script --- tools/GenerateNewControlProject.ps1 | 70 ++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/tools/GenerateNewControlProject.ps1 b/tools/GenerateNewControlProject.ps1 index 1dc5ed0760..41b07ff9a6 100644 --- a/tools/GenerateNewControlProject.ps1 +++ b/tools/GenerateNewControlProject.ps1 @@ -107,4 +107,72 @@ $xml.Save($testAppProject) FindAndReplaceInFile ($muxControlsDir + "\dev\Telemetry\RuntimeProfiler.h") "(\s*ProfId_Size.*\s*})" @" ProfId_$controlName,`$1 -"@ \ No newline at end of file +"@ +# Randomize class name for multiple use of class in one powershell +$id = get-random + +# We need double backslash for C# strings below +$cleanMuxControlsDir = $muxControlsDir.Replace("\","\\") + "\\" + +echo "$cleanMuxControlsDir" + +$assemblies=( + "System","EnvDTE","EnvDTE80" +) + +$source=@" +using System; +using EnvDTE; +using EnvDTE80; +using System.Collections.Generic; +namespace SolutionHelper +{ + public static class SolutionRegister$id{ + public static void Main(){ + Console.WriteLine("Started script"); + var dteType = Type.GetTypeFromProgID("VisualStudio.DTE.16.0", true); + if(dteType == null) + { + Console.WriteLine("You need to install Visual Studio to add projects to the solution"); + return; + } + var dte = (EnvDTE.DTE)System.Activator.CreateInstance(dteType); + var sln = (SolutionClass)dte.Solution; + Solution2 solution = (Solution2)dte.Solution; + Console.WriteLine("Got solution class"); + + var solutionNames = new List(){"MUXControls.sln","MUXControlsInnerLoop.sln"}; + foreach(var solutionName in solutionNames) + { + Console.WriteLine("Opening solution: $($cleanMuxControlsDir)" + solutionName); + solution.Open("$cleanMuxControlsDir" + solutionName); + Console.WriteLine("Opened solution"); + var devFolder = solution.Projects.Item(1); + + // Get correct reference here: + Console.WriteLine("Get dev folder"); + var devSolutionFolder = (SolutionFolder)devFolder.Object; + Console.WriteLine("Add folder"); + SolutionFolder newControlFolder = (SolutionFolder)devSolutionFolder.AddSolutionFolder("$controlName").Object; + + Console.WriteLine("Adding projects:"); + Console.WriteLine("Adding source"); + newControlFolder.AddFromFile("$($cleanMuxControlsDir)dev\\$($controlName)\\$($controlName).vcxitems"); + Console.WriteLine("Adding test UI"); + newControlFolder.AddFromFile("$($cleanMuxControlsDir)dev\\$($controlName)/TestUI/$($controlName)_TestUI.shproj"); + Console.WriteLine("Adding interactions test"); + newControlFolder.AddFromFile("$($cleanMuxControlsDir)dev\\$($controlName)\\InteractionTests\\$($controlName)_InteractionTests.shproj"); + Console.WriteLine("Finished adding projects, saving solution"); + + solution.Close(true); + Console.WriteLine("Saved solution" + solutionName); + } + } + } +} +"@ + + +Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source -Language CSharp + +iex "[SolutionHelper.SolutionRegister$id]::Main()" \ No newline at end of file