![](/img/trans.png)
[英]VSIX extension install but item-template not shown in visual studio
[英]Visual Studio Extension works while debugging but when I Install the VSIX it is not working
我正在嘗試用 C# 制作一個 VSIX 插件。 當我處於開發模式時,該插件工作正常。 但是當我嘗試通過雙擊 VSIX 安裝插件時,它不起作用。 我已經閱讀了一些文檔,有些人說要打包然后進行安裝。 但是,當我將“生成 .pkgdef 文件”選項設置為“True”時,我收到類似“CreatePkgDef : error : ArgumentException: 在此程序集中找不到 Visual Studio 注冊屬性”之類的錯誤。 並且程序集應包含在程序集“Microsoft.VisualStudio.Shell.Framework”版本“16.0.0.0”中定義的屬性“Microsoft.VisualStudio.Shell.RegistrationAttribute”的實例
基本上我想部署我的 VSIX。 我該怎么做?有人可以幫忙嗎? 謝謝你。
我得到了真正的問題。 實際上我正在使用 ITeamExplorerNavigationItem2 在團隊資源管理器中添加一個按鈕。 我使用屬性 public System.Drawing.Image Image 來控制按鈕圖標。
public System.Drawing.Image Image => null // Button comes up without any button icon
public System.Drawing.Image Image => System.Drawing.Image.FromFile("MyImage.png"); // button does not show up in the team explorer
我懷疑的是,在調試過程中,它找到了“MyImage.png”的路徑,但在運行時圖像沒有打包到 VSIX,所以它沒有找到 .png 路徑,隨后它沒有顯示圖標和按鈕。
為了解決這個問題,我實際上在項目中添加了一個Resource.resx文件,並在其中添加了圖像。 由於在編譯時將 resource.resx 文件添加到 VSIX 文件中,因此在安裝后可以正確顯示。 修改后的代碼
public System.Drawing.Image Image => Resource.MyImage;
VSIX 安裝的資產在 .vsixmanifest 文件中聲明。 就您而言,您已經擁有:
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
但是,第二項應該是不必要的。 僅在注冊新包時才需要 Pkgdef 文件 - 即從 Microsoft.VisualStudio.Shell.Package 或 Microsoft.VisualStudio.Shell.AsyncPackage 繼承的類(這些用於與您使用的擴展點不同的擴展點)。 由於您的 MEF 組件已經注冊(這似乎是您唯一需要的東西),您的 VSIX 應該已經能夠正常安裝。
為了更詳細地說明這些,當安裝 VSIX 時,它會查看這些資產,然后根據它們重新配置 VS。
[Export(typeof(ITeamExplorerNavigationItem))]
到您的班級中(但我不熟悉該功能,所以我不肯定)。編輯(回復評論):如果問題是您的圖像未加載,則可能是因為您的 VSIX 不包含您的圖像,或者因為您沒有使用正確的文件路徑。 默認情況下,所有文件路徑都將相對於 devenv.exe 所在的文件夾進行解析。 假設您的圖像位於 DLL 旁邊,您可能需要執行以下操作:
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string iconPath = Path.Combine(assemblyFolder, "MyImage.png");
您可以使用 Process Monitor (procmon ) 之類的工具來准確查看進程加載失敗的路徑。 (我不知道為什么它在調試時有效,但在安裝時無效。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.