diff --git a/src/SolutionTemplate/UnoSolutionTemplate.Wizard/UnoSolutionWizard.cs b/src/SolutionTemplate/UnoSolutionTemplate.Wizard/UnoSolutionWizard.cs index 54610eae3c38..22f9c8c8b8ea 100644 --- a/src/SolutionTemplate/UnoSolutionTemplate.Wizard/UnoSolutionWizard.cs +++ b/src/SolutionTemplate/UnoSolutionTemplate.Wizard/UnoSolutionWizard.cs @@ -1,7 +1,10 @@ -using System; +#nullable enable + +using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography.Xml; using System.Text; using System.Threading.Tasks; using EnvDTE; @@ -12,21 +15,19 @@ namespace UnoSolutionTemplate.Wizard { public class UnoSolutionWizard : IWizard { - private string _targetPath; + private string? _targetPath; + private DTE2? _dte; public void BeforeOpeningFile(global::EnvDTE.ProjectItem projectItem) { - } public void ProjectFinishedGenerating(global::EnvDTE.Project project) { - } public void ProjectItemFinishedGenerating(global::EnvDTE.ProjectItem projectItem) { - } public void RunFinished() @@ -35,16 +36,54 @@ public void RunFinished() if (!File.Exists(nugetConfigPath)) { - using (var reader = new StreamReader(GetType().Assembly.GetManifestResourceStream($"{GetType().Assembly.GetName().Name}..vsconfig"))) + using var reader = new StreamReader(GetType().Assembly.GetManifestResourceStream($"{GetType().Assembly.GetName().Name}..vsconfig")); + File.WriteAllText(nugetConfigPath, reader.ReadToEnd()); + } + + OpenWelcomePage(); + SetAsStartupProject(); + } + + private void OpenWelcomePage() + => _dte?.ItemOperations.Navigate("https://platform.uno/docs/articles/getting-started-tutorial-1.html", vsNavigateOptions.vsNavigateOptionsNewWindow); + + private void SetAsStartupProject() + { + if (_dte != null && _dte.Solution.SolutionBuild is SolutionBuild2 val) + { + try + { + var uwpProject = _dte.Solution.Projects.Cast().FirstOrDefault(s => s.Name.EndsWith(".UWP", StringComparison.OrdinalIgnoreCase)); + + if (uwpProject is { }) + { + val.StartupProjects = uwpProject.UniqueName; + } + + var x86Config = val.SolutionConfigurations + .Cast() + .FirstOrDefault(c => c.Name == "Debug" && c.PlatformName == "x86"); + + x86Config?.Activate(); + } + catch (Exception) { - File.WriteAllText(nugetConfigPath, reader.ReadToEnd()); } } + else + { + throw new InvalidOperationException(); + } } public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { _targetPath = replacementsDictionary["$destinationdirectory$"]; + + if (runKind == WizardRunKind.AsMultiProject) + { + _dte = (DTE2)automationObject; + } } public bool ShouldAddProjectItem(string filePath)