惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
C
Check Point Blog
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
SecWiki News
SecWiki News
有赞技术团队
有赞技术团队
Latest news
Latest news
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
Project Zero
Project Zero
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
腾讯CDC
P
Proofpoint News Feed
L
LINUX DO - 热门话题
C
Cisco Blogs
P
Palo Alto Networks Blog
Vercel News
Vercel News
P
Privacy International News Feed
爱范儿
爱范儿
Scott Helme
Scott Helme
L
Lohrmann on Cybersecurity
MyScale Blog
MyScale Blog
K
Kaspersky official blog
B
Blog RSS Feed
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
O
OpenAI News
博客园 - 叶小钗
量子位
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
J
Java Code Geeks
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 最新话题
F
Fortinet All Blogs
N
News | PayPal Newsroom
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
N
News and Events Feed by Topic
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI

博客园 - 蒜头

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for (email address). 再谈Images到xps,pdf的转换 SQL Server 2005中xml类型和函数的简单应用 部分Office 2007文件格式转换为xps和pdf代码整理 Image.FromFile gives "Out of Memory" Exception for icon - 蒜头 简单介绍PDF,XPS,Images,Office 2007之间的转换方法 - 蒜头 - 博客园 SQL 2005 全文检索(续) 简单实现C#生成Excel 2007文件并下载 简单应用ReportViewer控件 配置SQL Server Session方法 采用负载均衡,部署了两个ASP.NET 2.0的站点服务器碰到的问题 初试VSTS 2008(TFS安装) Windows Server 2003分区修改方法[转载] 一个简单的document library event handler VS 2005 SP1 安装错误 [续] 一个简单的Checkbox Custom Field Type ASP.NET 2.0 SQL Cache 配置方法 解读Document Library关于权限的对象模型 SharePoint应用AJAX.NET和AJAX Control Toolkit
制作VSTO 2005 SE开发的Office 2007 AddIn的安装包
蒜头 · 2007-09-23 · via 博客园 - 蒜头

首先,明确要使AddIn能运行得前提条件:
1、.Net Framework 2.0
2、VSTO 2005 SE runtime
3、Visual Studio Tools for Office Language Pack 非英文版本需要安装
4、Primary interop assemblies redistributable package for the 2007 release of Office(一般安装Office 2007时已经安装了)

使用VSTO 2005 SE开发完Office 2007的AddIn后制作Windonws Installer安装包过程如下:

1、下载安装Visual Studio 2005 Tools for Office Second Edition Sample: Deploying Office Solutions Using Windows Installer;

2、下载VSTO 2005 SE runtime,将vstor.exe拷贝到C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample\Packages\VSTOSERuntime下;

3、安装Windows SDK,VistaWin 2003的都可以。主要为了编译一个cpp文件,不需要全部安装;

4、运行VS2005的命令行工具,到Visual Studio 2005 Tools for Office Second Edition Sample安装目录下,默认是C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample\projects\Checks,运行

cl.exe -"D:\Program Files\Microsoft Platform SDK\Include" /Oxs /MT /GS ComponentCheck.cpp


编译ComponentCheck.cpp生成一个exe文件,拷贝到Packages\Office2007PIA下。

Vista 的是Include路径是"D:\Program Files\Microsoft SDKs\Windows\v6.0\Include"

5、下载Primary interop assemblies redistributable package for the 2007 release of Office,下载安装后,将o2007pia.msi拷贝到Packages\Office2007PIA下;

6、需要的话就下载Visual Studio Tools for Office Language Pack,拷贝到Packages\VSTOLP;

7、将Packages下的所有内容拷贝到.Net Framwork 目录下Pagckages目录,默认位置C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages;

8、添加projects目录下的SetSecurity到自己的AddIn项目中,它的作用是在安装时为我们的程序集添加安全策略。如果不添加安全策略,我们的插件是不会被Office调用的;

9、添加所有的项目输出到安装项目中;

10、在安装项目的属性中添加运行的先决条件。如果不执行第7步,这里是不能选择这些先决条件的。添加以后,安装时会检查这些组件,如果未安装,安装程序会提示用户连接微软网站下载和安装;

11、为安装项目添加Custom Actions,注册表项已经由VSTO模板创建了,可以根据自己的需要再修改,比如添加到HLM下;

选择SetSecurity的主输出
在Install的CustomActionData中添加:

/assemblyName="OutlookAddin.dll" /targetDir="[TARGETDIR]\"
   
/solutionCodeGroupName="MyCompanyName.OutlookAddin"
   
/solutionCodeGroupDescription="Code group for OutlookAddin"
   
/assemblyCodeGroupName="OutlookAddin"
   
/assemblyCodeGroupDescription="Code group for OutlookAddin"
   
/allUsers=[ALLUSERS]


RollBack的CustomActionData中添加:

/solutionCodeGroupName="MyCompanyName.OutlookAddin"

Uninstall的CustomActionData中添加:

/solutionCodeGroupName="MyCompanyName.OutlookAddin"

Install时,如果只有一个dll,SetSecurity除外,这样设置就可以了,也不用修改代码,如果你有多个dll要为每个添加安全策略,这就要对这个参数和SetSecurity做一点修改:

/assemblyName="OutlookAddin.dll,2.dll,3.dll" /targetDir="[TARGETDIR]\"
   
/solutionCodeGroupName="MyCompanyName.OutlookAddin"
   
/solutionCodeGroupDescription="Code group for OutlookAddin"
   
/assemblyCodeGroupName="OutlookAddin"
   
/assemblyCodeGroupDescription="Code group for OutlookAddin"
   
/allUsers=[ALLUSERS]

在SetSecurity.cs中以下这短代码:

                bool allUsers = String.Equals(allUsersString, "1");
                
string assemblyPath = Path.Combine(targetDir, assemblyName);

                
// Note that Install method may be invoked during Repair mode and the code group 
                
// may already exist.
                
// To prevent adding of another code group, remove the code group if it exists.
                try
                
{
                    
// The solutionCodeGroupName must be a unique name; otherwise, the method might delete wrong code group.
                    CaspolSecurityPolicyCreator.RemoveSecurityPolicy(allUsers, solutionCodeGroupName);
                }

                
catch {}

                CaspolSecurityPolicyCreator.AddSecurityPolicy(
                    allUsers,
                    solutionCodeGroupName,
                    solutionCodeGroupDescription,
                    assemblyPath,
                    assemblyCodeGroupName,
                    assemblyCodeGroupDescription);
                stateSaver.Add(
"allUsers", allUsers);

修改为:

                bool allUsers = String.Equals(allUsersString, "1");

                
// Note that Install method may be invoked during Repair mode and the code group 
                
// may already exist.
                
// To prevent adding of another code group, remove the code group if it exists.
                try
                
{
                    
// The solutionCodeGroupName must be a unique name; otherwise, the method might delete wrong code group.
                    CaspolSecurityPolicyCreator.RemoveSecurityPolicy(allUsers, solutionCodeGroupName);
                }

                
catch {}

                
string[] assemblys = assemblyName.Split(',');
                
foreach (string assembly in assemblys)
                
{
                    
string assemblyPath = Path.Combine(targetDir, assembly);
                    CaspolSecurityPolicyCreator.AddSecurityPolicy(
                        allUsers,
                        solutionCodeGroupName,
                        solutionCodeGroupDescription,
                        assemblyPath,
                        assemblyCodeGroupName,
                        assemblyCodeGroupDescription);
                }


                stateSaver.Add(
"allUsers", allUsers);

很笨的方法。:-)(前两天正是这个符号诞生25周年)

12、编译我们的安装项目,这样我的AddIn就可以安装到装有Office 2007的系统上了。

我们会得到一个警告:
WARNING: No 'HomeSite' attribute has been provided for '2007 Microsoft Office Primary Interop Assemblies', so the package will be published to the same location as the bootstrapper.
看安装项目的Debug目录

这个是因为安装程序不能通过微软网站下载2007 Microsoft Office Primary Interop Assemblies(微软未提供),所以将安装包一起发布,我们的安装程序会直接从本地运行这个msi。
这些运行的先决条件,也可以同我们的安装包一起发布。特别是在目标主机无外网连接的情况下。

编译后如下:

当然,我们可以自己去实现这些检测和安装,添加一个Register search和lunch condition,
Register Search属性如下:


Lunch Condition属性如下:


这样我们的安装包一样可以从本地安装VSTO运行时。

这样安装包比较大,我们可以发布两个版本,视具体情况而定。

现在AddIn的安装包基本完成了,其他的一些东西:安装界面,版本...我在这里就不介绍了,现在想说的是这个安装包还不够完美,没有检测是否安装Office 2007,我们也可以通过注册表来实现。

其实,要做出比较好的安装包还是要用Installshiled,但是俺好久没用它了,也不知道如何用它去做Office AddIn的安装包,并且它需要付费,因此,还是用了Windows Installer。