900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > revit二次开发——制作插件安装包 自动写addin文件

revit二次开发——制作插件安装包 自动写addin文件

时间:2019-04-15 15:36:01

相关推荐

revit二次开发——制作插件安装包 自动写addin文件

目录

准备工作安装包制作1、新建项目,选中Setup Project2、进入项目,在Application Folder里添加要打包的文件2.1 文件夹说明2.2添加卸载程序2.3依赖框架 3、以上配置完成,编译Setup项目即可在“Setup项目/Release”生成安装包。 自定义安装程序类示例:自动写addin文件

准备工作

1、打开visual studio

2、打开 工具—>扩展

3、搜索 installer,安装Microsoft Visual Studio Installer Projects

安装包制作

1、新建项目,选中Setup Project

2、进入项目,在Application Folder里添加要打包的文件

2.1 文件夹说明

Application Folder : 应用程序包含的文件设置。User’s Desktop : 用户桌面快捷方式设置。User’s Programs Menu : 用户启动菜单的快捷方式设置。

2.2添加卸载程序

卸载功能实现: C:\Windows\System32\msiexec.exe在 Application Folder 文件夹中添加 msiexec.exe ,创建快捷方式,并设置属性 Arguments=/x {1028BF2E-832F-4B79-8D54-01CFB4BB30EC}

(备注:{1028BF2E-832F-4B79-8D54-01CFB4BB30EC} 为 Setup项目属性中的ProductCode,当项目属性中ProductCode改变时,卸载这里的Arguments需要跟着改变)

2.3依赖框架

右键Setup项目–>属性–>Prerequisites

在系统必备的窗体中,勾选Framework 4.6(开发的应用程序所使用的Framework版本,示例中为4.6),选择【从组件供应商的网站上下载系统必备组件】(此选项会提示客户去微软官网下载Framework 4.6 )。

指定系统必备组件的安装位置其他选项:需要提前把Framework 指定版本的安装包下载下来放置相应目录下

启动条件:右键Setup项目–>View–>启动条件,.NET Framework属性Version修改为.NET Framework 4.6(与系统必备Framework版本一致)

3、以上配置完成,编译Setup项目即可在“Setup项目/Release”生成安装包。

自定义安装程序类

• 制作安装程序时,可以添加自定义安装程序类,在此类中编写安装过程中的一些自定义操作。

• 添加自定义安装操作类。

•打包程序增加自定义操作

1.Setup项目右键–>View–>自定义操作,可以看到有四个子项:安装、提交、回滚、卸载,如右图所示

2.在Install上点击右键–>添加自定义操作–>Application Folder -->【主输出】(这样,重新生成后,安装之后就会执行 OnBeforeInstall 、 OnAfterInstall 、 BeforeInstall事件、 AfterInstall事件的代码了。)

示例:自动写addin文件

public class Installer1:Installer{private IContainer components = null;public Installer1(){InitializeComponent();base.BeforeInstall += InstallerTest_BeforeInstall;base.AfterInstall += InstallerTest_AfterInstall;base.AfterUninstall += InstallerTest_AfterUninstall;}private void InstallerTest_AfterUninstall(object sender, InstallEventArgs e){string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);string path = folderPath + "\\Autodesk\\Revit\\Addins\\\\test.addin";try{if (File.Exists(path)){File.Delete(path);}}catch (Exception){}}private void InstallerTest_AfterInstall(object sender, InstallEventArgs e){string text = "test";string directoryName = Path.GetDirectoryName(typeof(Installer1).Assembly.Location);string text2 = directoryName + "\\test Program\\" + text + ".dll";string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);string path = folderPath + "\\Autodesk\\Revit\\Addins\\\\test.addin";string text3 = Guid.NewGuid().ToString();try{if (File.Exists(item)){File.Delete(item);}File.WriteAllLines(item, new List<string>{"<?xml version=\"1.0\" encoding=\"UTF-8\"?>","<RevitAddIns>","<AddIn Type=\"Application\">","<VendorId>ADSK</VendorId>","<Name>test</Name>","<Assembly>" + text2 + "</Assembly>","<AddInId>" + text3 + "</AddInId>","<FullClassName>" + text + ".App</FullClassName>","<VendorDescription>Zobon, </VendorDescription>","</AddIn>","</RevitAddIns>"}.ToArray(), Encoding.UTF8);}catch (Exception){} }private void InstallerTest_BeforeInstall(object sender, InstallEventArgs e){//什么也不做}private void InitializeComponent(){components = new Container();}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。