Skip to content

Commit

Permalink
Improve VSIX
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Dec 8, 2024
1 parent c5d88c8 commit 4a9ea64
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
29 changes: 29 additions & 0 deletions VSIX/DevWinUI_Template/DevWinUI_Template/Common/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;

namespace DevWinUI_Template;
public static class Helper
{
public static bool IsPreviewVSIX()
{
var asm = Assembly.GetExecutingAssembly();
var asmDir = Path.GetDirectoryName(asm.Location);
var manifestPath = Path.Combine(asmDir, "extension.vsixmanifest");
bool isPreview = false;
if (File.Exists(manifestPath))
{
var doc = new XmlDocument();
doc.Load(manifestPath);
var metaData = doc.DocumentElement.ChildNodes.Cast<XmlElement>().FirstOrDefault(x => x.Name == "Metadata");
var identity = metaData.ChildNodes.Cast<XmlElement>().FirstOrDefault(x => x.Name == "Preview");
var value = identity?.InnerText;
if (!string.IsNullOrEmpty(value))
{
isPreview = value.ToLower().Equals("true");
}
}
return isPreview;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public async void RunStarted(object automationObject, Dictionary<string, string>

if (templateConfig.IsBlank || templateConfig.IsTest)
{
if (Helper.IsPreviewVSIX())
{
WizardConfig.UsePreReleaseVersion = true;
}

AddReplacementsDictionary(replacementsDictionary);
_shouldAddProjectItem = true;
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Xml;
using DevWinUI_Template.WizardUI;

namespace DevWinUI_Template;
Expand Down Expand Up @@ -39,31 +35,12 @@ private void DashboardPage_Loaded(object sender, RoutedEventArgs e)
}
}

if (IsPreviewVSIX())
if (Helper.IsPreviewVSIX())
{
CmbVersion.SelectedIndex = 1;
}
}
private bool IsPreviewVSIX()
{
var asm = Assembly.GetExecutingAssembly();
var asmDir = Path.GetDirectoryName(asm.Location);
var manifestPath = Path.Combine(asmDir, "extension.vsixmanifest");
bool isPreview = false;
if (File.Exists(manifestPath))
{
var doc = new XmlDocument();
doc.Load(manifestPath);
var metaData = doc.DocumentElement.ChildNodes.Cast<XmlElement>().FirstOrDefault(x => x.Name == "Metadata");
var identity = metaData.ChildNodes.Cast<XmlElement>().FirstOrDefault(x => x.Name == "Preview");
var value = identity?.InnerText;
if (!string.IsNullOrEmpty(value))
{
isPreview = value.ToLower().Equals("true");
}
}
return isPreview;
}

private void cmbVersionMechanism_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var cmbVersionMechanism = sender as ComboBox;
Expand Down

0 comments on commit 4a9ea64

Please sign in to comment.