VSTO部署计划
背景:须要应用VSTO开发一个Excel插件,插件具备自动更新的性能
VisualStudio: 2022
针对Excel版本:2016
ClickOnce部署
该计划应用了一个文件服务器用来拜访部署文件。(后以www.example.com/Files作为示例地址)
- 应用VS模板,创立一个Excel AddIn我的项目(在其中填充你想要的性能,此处略过不提)
- 右键我的项目,关上属性界面
- 选中公布页签,进行设置并点击公布
- 公布后的文件复制到文件服务器的目录下即可
- 用户从对应URL下载Setup.exe进行装置即可;后续也会主动从对应URL拉取更新的
问题
如果呈现从不信赖的地位或起源装置的报错,导致无奈进行装置,能够间接采纳信赖证书的形式装置
右键下载下来的Setup.exe
,找到证书进行装置起因:公布的软件都有证书,在属性界面的签名页签里进行设置。默认应用的是测试证书,用户机器不信赖。须要手动装置信赖下才能够失常。
后续不更改证书,就不必从新信赖了
dll部署
ClickOnce
部署很不便,然而没有版本倒退的性能。在理论的我的项目中,插件版本往往和数据版本有关联的,切换到指定的svn或git版本,心愿也能有对应版本的插件性能。
以svn版本控制为例,阐明怎么应用dll部署。
插件本体我的项目
依然采纳ClickOnce
部署的形式,不过能够不填近程Url,因为不存在插件更新的状况;界面及性能采纳Dll的形式书写
Dll我的项目创立
- 创立一个Net Framework类库
- 引入相干援用;将失常的VSTO我的项目中的援用都增加进来
创立绘制的函数(从VSTO设计器产生的函数间接复制过去就行)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Office.Tools.Ribbon; namespace ClassLibrary1 { public static class Class1 { /// <summary> /// 绘制tab,返回提供给VSTO应用 /// </summary> /// <param name="factory"></param> /// <returns></returns> public static RibbonTab DrawTab(RibbonFactory factory) { RibbonTab tab1 = factory.CreateRibbonTab(); RibbonGroup group1 = factory.CreateRibbonGroup(); tab1.SuspendLayout(); tab1.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office; tab1.Groups.Add(group1); tab1.Label = "TabAddIns"; tab1.Name = "tab1"; group1.Label = "group1"; group1.Name = "group1"; tab1.ResumeLayout(false); tab1.PerformLayout(); return tab1; } } }
VSTO我的项目中的功能区代码略作调整
设计器产生代码
批改前private void InitializeComponent() { this.tab1 = this.Factory.CreateRibbonTab(); this.group1 = this.Factory.CreateRibbonGroup(); this.tab1.SuspendLayout(); this.SuspendLayout(); // // tab1 // this.tab1.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office; this.tab1.Groups.Add(this.group1); this.tab1.Label = "TabAddIns"; this.tab1.Name = "tab1"; // // group1 // this.group1.Label = "group1"; this.group1.Name = "group1"; // // Ribbon1 // this.Name = "Ribbon1"; this.RibbonType = "Microsoft.Excel.Workbook"; this.Tabs.Add(this.tab1); this.Load += new Microsoft.Office.Tools.Ribbon.RibbonUIEventHandler(this.Ribbon1_Load); this.tab1.ResumeLayout(false); this.tab1.PerformLayout(); this.ResumeLayout(false); }
批改后
private void InitializeComponent() { this.SuspendLayout(); // 依据dll获取函数,产生tab Assembly assembly = Assembly.LoadFrom("XXX/test.dll"); Type type = assembly.GetType("ClassLibrary1.Class1"); MethodInfo methodInfo = type.GetMethod("DrawTab", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static ); this.tab1 = (RibbonTab)methodInfo.Invoke(null, new[] { this.Factory }); this.Name = "Ribbon1"; this.RibbonType = "Microsoft.Excel.Workbook"; this.Tabs.Add(this.tab1); this.ResumeLayout(false); }
这样在关上插件之后,会依据dll主动获取绘制函数,从而实现依据dll的内容更新插件。
问题
- 不同用户,机子上dll的门路可能不同,怎么获取?
能够要求用户首次应用的时候,执行一个.bat
,让用户输出本人的svn我的项目门路,而后依据svn门路和相对路径,拼出来dll的门路。