Skip to content

Commit

Permalink
feat: Add welcome page for vsix, set UWP as startup project
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Oct 5, 2020
1 parent 7563e4a commit 8995335
Showing 1 changed file with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
Expand All @@ -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<Project>().FirstOrDefault(s => s.Name.EndsWith(".UWP", StringComparison.OrdinalIgnoreCase));

if (uwpProject is { })
{
val.StartupProjects = uwpProject.UniqueName;
}

var x86Config = val.SolutionConfigurations
.Cast<SolutionConfiguration2>()
.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<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
_targetPath = replacementsDictionary["$destinationdirectory$"];

if (runKind == WizardRunKind.AsMultiProject)
{
_dte = (DTE2)automationObject;
}
}

public bool ShouldAddProjectItem(string filePath)
Expand Down

0 comments on commit 8995335

Please sign in to comment.