gpt4 book ai didi

visual-studio - Visual Studio VSIX OnSolutionOpened 不工作

转载 作者:行者123 更新时间:2023-12-02 07:21:58 25 4
gpt4 key购买 nike

我正在尝试为 Visual Studio 实现某种起始页扩展。主要目的是通过在每次打开解决方案时启动本地 HTML 文件,为我工作的公司内的特定项目提供说明和最佳实践。我开始使用 Visual Commander ( https://vlasovstudio.com/visual-commander/extensions.html ),效果很好。但我想让它成为一个 VSIX 文件。经过一些研究,我生成了代码,但如果我调试或直接从调试文件夹安装 vsix,则什么也不会发生(即使我在第一行抛出异常也不会)。代码非常简单:

 #region Package Members

DTE DTE;

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
base.Initialize();
try
{
IServiceContainer serviceContainer = this as IServiceContainer;
DTE = serviceContainer.GetService(typeof(SDTE)) as DTE;
EnvDTE.Events events = DTE.Events;
EnvDTE.SolutionEvents solutionEvents = events.SolutionEvents;
solutionEvents.Opened += OnSolutionOpened;
}
catch (Exception ex)
{
throw ex;
}
}

private void OnSolutionOpened()
{
try
{
string startupFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(DTE.Solution.FullName), GetSolutionStartPage());
if (System.IO.File.Exists(startupFile))
{
DTE.ItemOperations.Navigate(startupFile);
}
}
catch (Exception ex)
{
throw ex;
}
}

string GetSolutionStartPage()
{
return ((DTE.Solution != null) ? System.IO.Path.GetFileNameWithoutExtension(DTE.Solution.FullName) : "") + ".html";
}

#endregion

最佳答案

不要忘记在类级别而不是方法级别移动 solutionEvents 声明,否则您的下一个问题将是它只能工作一段时间(因为垃圾回收)。参见 https://msdn.microsoft.com/en-us/library/envdte.solutionevents.aspx

关于visual-studio - Visual Studio VSIX OnSolutionOpened 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43379298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com