Visual studio VS2017,VSIX:未实例化刚刚创建的AsyncPackage
这是默认的VSPackage。我只添加了ProvideAutoLoad属性Visual studio VS2017,VSIX:未实例化刚刚创建的AsyncPackage,visual-studio,visual-studio-extensions,vsix,vssdk,Visual Studio,Visual Studio Extensions,Vsix,Vssdk,这是默认的VSPackage。我只添加了ProvideAutoLoad属性 using System; using System.ComponentModel.Design; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; using System.Threading; using S
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.Win32;
using Task = System.Threading.Tasks.Task;
namespace VSIXProject1
{
/// <summary>
/// This is the class that implements the package exposed by this assembly.
/// </summary>
/// <remarks>
/// <para>
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell. These attributes tell the pkgdef creation
/// utility what data to put into .pkgdef file.
/// </para>
/// <para>
/// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file.
/// </para>
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[Guid(VSPackage1.PackageGuidString)]
[ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
public sealed class VSPackage1 : AsyncPackage
{
/// <summary>
/// VSPackage1 GUID string.
/// </summary>
public const string PackageGuidString = "cca56365-4b14-4a96-9280-c30dce400195";
/// <summary>
/// Initializes a new instance of the <see cref="VSPackage1"/> class.
/// </summary>
public VSPackage1()
{
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}
#region Package Members
/// <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>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}
#endregion
}
}
使用系统;
使用System.ComponentModel.Design;
使用系统诊断;
使用System.Diagnostics.CodeAnalysis;
利用制度全球化;
使用System.Runtime.InteropServices;
使用系统线程;
使用System.Threading.Tasks;
使用Microsoft.VisualStudio;
使用Microsoft.VisualStudio.OLE.Interop;
使用Microsoft.VisualStudio.Shell;
使用Microsoft.VisualStudio.Shell.Interop;
使用Microsoft.Win32;
使用Task=System.Threading.Tasks.Task;
命名空间VSIXProject1
{
///
///这是实现此程序集公开的包的类。
///
///
///
///类被视为Visual Studio的有效包的最低要求
///是实现IVsPackage接口并向shell注册自身。
///此包使用托管包框架(MPF)中定义的帮助器类
///要做到这一点:它派生自提供
///IVsPackage接口,并使用框架中定义的注册属性
///在shell中注册自身及其组件。这些属性告诉pkgdef的创建
///实用工具将哪些数据放入.pkgdef文件。
///
///
///要加载到VS中,包必须由.vsixmanifest文件中的Asset Type=“Microsoft.VisualStudio.VsPackage”…引用。
///
///
[PackageRegistration(UseManagedResourcesOnly=true,AllowsBackgroundLoading=true)]
[InstalledProductRegistration(“#110”、“#112”、“1.0”,IconResourceID=400)]//有关此软件包的帮助信息/关于
[Guid(VSPackage1.PackageGuidString)]
[提供自动加载(UIContextGuids.NoSolution,PackageAutoLoadFlags.BackgroundLoad)]
[提供自动加载(UIContextGuids.SolutionExists,PackageAutoLoadFlags.BackgroundLoad)]
[SuppressMessage(“StyleCop.CSharp.DocumentationRules”,“SA1650:ElementDocumentationmustbespelled正确”,justionment=“pkgdef,VS和vsixmanifest是有效的VS术语”)]
公共密封类VSPackage1:AsyncPackage
{
///
///VSPackage1 GUID字符串。
///
public const string PackageGuidString=“cca56365-4b14-4a96-9280-c30dce400195”;
///
///初始化类的新实例。
///
公共VSPackage1()
{
//在这个方法中,您可以放置任何不需要的初始化代码
//任何Visual Studio服务,因为此时已创建包对象,但
//尚未位于Visual Studio环境中。执行所有其他操作的位置
//初始化是初始化方法。
}
#地区方案成员
///
///初始化包;此方法在包定位后立即调用,因此这就是位置
///您可以在其中放置依赖VisualStudio提供的服务的所有初始化代码。
///
///用于监视初始化取消的取消令牌,当VS关闭时可能会发生初始化取消。
///进度更新的提供程序。
///表示包初始化的异步工作的任务,如果没有,则表示已完成的任务。不要从此方法返回null。
受保护的覆盖异步任务初始化同步(CancellationToken CancellationToken,IProgress progress)
{
//异步初始化时,当前线程此时可能是后台线程。
//切换到UI线程后,执行任何需要UI线程的初始化。
等待此消息。JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}
#端区
}
}
看起来它没有被实例化。如果我正在添加断点或Debug.WriteLine(…),那么什么都不会发生。当我添加命令时,也什么都没有。我只能在扩展和更新窗口中看到我的扩展
我用逐步复制的方法录制了这个小视频,我的问题是:
我应该如何处理我的包得到实例化?我从默认的包模板开始,对我来说,添加属性
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
到package类使事情正常工作。尝试返回默认模板并添加该行,然后调试
对我来说,这是模板中的一个bug。模板应该可以正常工作,而不需要在stackoverflow上搜寻很久就可以找到丢失的魔法咒语。显然,您只想点击调试键,看到断点被点击,然后从那里开始构建。我在从Visual Studio 2017接管一个扩展时遇到了这个问题,该扩展在接管所有中间Visual Studio版本之前,我想可能是在VS2010上创建的。我改变了两件或更多的事情,但我不知道是哪一件让它起作用了
- %appdata%\Microsoft\VisualStudio\16.0\U d1c373