设为首页 收藏本站
查看: 1585|回复: 0

[经验分享] (转)刚开始Outlook Addin的布署问题

[复制链接]

尚未签到

发表于 2015-9-12 13:58:45 | 显示全部楼层 |阅读模式
  转自:http://weblogs.asp.net/mnissen/articles/427504.aspx

遇到的问题:
VSTO开发的Outlook Addin生成的默认setup工程不能正确的将插件安装到客户端,安装过程没有报错,注册表的Outlook下面的Addin也有注册。
  
  最后的解决:客户端需要满足下面几个条件:
  1.                       .NET Framework 2.0 (RC1)
  2.                       Microsoft Office 2003 w/Outlook
  3.                       Microsoft Office 2003 SP1 (or later)
  4.                       Microsoft Office 2003 Primary Interop Assemblies (O2003PIA.exe) (how-to)
  5.                       Visual Studio Tools for Office Runtime (vstor.exe) (Same version as .NET Framework!)
  6.                       Language pack for vstor (Optional)
  7.                       Registry keys for Outlook plugin (fixed by default VSTO Setup project)
  8.                       Code Access Security FullTrust grant to your assemblies
  
  相关的软件可以去Microsoft网站下载。
  
  VSTO模版中生成的setup工程中欠缺如下两个方面:
  1.              reference中缺少Microsoft.Office.Tools.Common.dll,这点可以简单的在主工程中添加reference选择相应的dll即可。
  2.              需要msi自动的实现Code Access Security(而不是在客户机安装.NET Framework 2.0 Configuration Tools然后手动配置安全策略),实现方法如下:
  
  新建一个System.Configuration.Install.Installer的继承,通过右键点击你的工程然后Add New Item | Installer Class,命名为Installer,然后在Installer.cs中写入代码如下:

  

DSC0000.gif DSC0001.gif
  1 DSC0002.gif using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Security.Policy;
  5using System.Security;
  6
  7namespace EOfficeSync
  8 DSC0003.gif {
  9 DSC0004.gif     // Code Access Security configuring installer by Mads Nissen 2005
10    // http://weblogs.asp.net/mnissen
11
12    [RunInstaller(true)]
13    public partial class Installer : System.Configuration.Install.Installer
14 DSC0005.gif DSC0006.gif     {
15
16        private readonly string installPolicyLevel = "Machine";
17        private readonly string namedPermissionSet = "FullTrust";
18        private readonly string codeGroupDescription = "VSTO Permissions for Objectware Plugins";
19        private readonly string productName = "Objectware SharepointConnector";
20        private readonly bool debugBreakOnInstall = false;
21
22        private string codeGroupName = "";
23
24        /**//// <summary>
25        /// Gets a CodeGroup name based on the productname and URL evidence
26 DSC0007.gif         /// </summary>
27        private string CodeGroupName
28        {
29            get
30            {
31                if (codeGroupName.Length == 0)
32                {
33                    codeGroupName = "[" + productName + "] " + InstallDirectory;
34                }
35                return codeGroupName;
36            }
37        }
38
39        /**//// <summary>
40        /// Gets the installdirectory with a wildcard suffix for use with URL evidence
41        /// </summary>
42        private string InstallDirectory
43        {
44            get
45            {
46                // Get the install directory of the current installer
47                string assemblyPath = this.Context.Parameters["assemblypath"];
48                string installDirectory =
49                    assemblyPath.Substring(0, assemblyPath.LastIndexOf("\\"));
50
51                if (!installDirectory.EndsWith(@"\"))
52                    installDirectory += @"\";
53                installDirectory += "*";
54
55                return installDirectory;
56            }
57        }
58
59        public Installer()
60        {
61        }
62
63        public override void Install(System.Collections.IDictionary stateSaver)
64        {
65            base.Install(stateSaver);
66
67            try
68            {
69                ConfigureCodeAccessSecurity();
70                // Method not able to persist configuration to config file:
71                // SetPortalUrlFromInstallerParameter();
72            }
73            catch (Exception ex)
74            {
75                System.Windows.Forms.MessageBox.Show(ex.ToString());
76                this.Rollback(stateSaver);
77            }
78        }
79
80        /**//// <summary>
81        /// Configures FullTrust for the entire installdirectory
82        /// </summary>
83        private void ConfigureCodeAccessSecurity()
84        {
85
86            PolicyLevel machinePolicyLevel = GetPolicyLevel();
87
88            if (null == GetCodeGroup(machinePolicyLevel))
89            {
90                // Create a new FullTrust permission set
91                PermissionSet permissionSet = new NamedPermissionSet(this.namedPermissionSet);
92
93                IMembershipCondition membershipCondition =
94                    new UrlMembershipCondition(InstallDirectory);
95
96                // Create the code group
97                PolicyStatement policyStatement = new PolicyStatement(permissionSet);
98                CodeGroup codeGroup = new UnionCodeGroup(membershipCondition, policyStatement);
99                codeGroup.Description = this.codeGroupDescription;
100                codeGroup.Name = this.codeGroupName;
101
102                // Add the code group
103                machinePolicyLevel.RootCodeGroup.AddChild(codeGroup);
104
105                // Save changes
106                SecurityManager.SavePolicy();
107            }
108        }
109
110        /**//// <summary>
111        /// Gets the currently defined policylevel
112        /// </summary>
113        /// <returns></returns>
114        private PolicyLevel GetPolicyLevel()
115        {
116            // Find the machine policy level
117            PolicyLevel machinePolicyLevel = null;
118            System.Collections.IEnumerator policyHierarchy = SecurityManager.PolicyHierarchy();
119
120            while (policyHierarchy.MoveNext())
121            {
122                PolicyLevel level = (PolicyLevel)policyHierarchy.Current;
123                if (level.Label.CompareTo(installPolicyLevel) == 0)
124                {
125                    machinePolicyLevel = level;
126                    break;
127                }
128            }
129
130            if (machinePolicyLevel == null)
131            {
132                throw new ApplicationException(
133                    "Could not find Machine Policy level. Code Access Security " +
134                    "is not configured for this application."
135                    );
136            }
137            return machinePolicyLevel;
138        }
139
140        /**//// <summary>
141        /// Gets current codegroup based on CodeGroupName at the given policylevel
142        /// </summary>
143        /// <param name="policyLevel"></param>
144        /// <returns>null if not found</returns>
145        private CodeGroup GetCodeGroup(PolicyLevel policyLevel)
146        {
147            foreach (CodeGroup codeGroup in policyLevel.RootCodeGroup.Children)
148            {
149                if (codeGroup.Name.CompareTo(CodeGroupName) == 0)
150                {
151                    return codeGroup;
152                }
153            }
154            return null;
155        }
156
157        public override void Uninstall(System.Collections.IDictionary savedState)
158        {
159            if (debugBreakOnInstall)
160                System.Diagnostics.Debugger.Break();
161
162            base.Uninstall(savedState);
163            try
164            {
165                this.UninstallCodeAccessSecurity();
166            }
167            catch (Exception ex)
168            {
169                System.Windows.Forms.MessageBox.Show("Unable to uninstall code access security:\n\n" + ex.ToString());
170            }
171        }
172
173        private void UninstallCodeAccessSecurity()
174        {
175            PolicyLevel machinePolicyLevel = GetPolicyLevel();
176
177            CodeGroup codeGroup = GetCodeGroup(machinePolicyLevel);
178            if (codeGroup != null)
179            {
180                machinePolicyLevel.RootCodeGroup.RemoveChild(codeGroup);
181
182                // Save changes
183                SecurityManager.SavePolicy();
184            }
185        }
186    }
187 DSC0008.gif }  
  VB.Net版本的请查看:http://weblogs.asp.net/mnissen/articles/429117.aspx
setup工程View | Custom Actioninstalluninstall中添加新的Custom Action,选择生成好的Primary Output。完工。

详细内容可以参考http://weblogs.asp.net/mnissen

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-112728-1-1.html 上篇帖子: OutLook 安全防问限制 下篇帖子: 把Outlook与Google Calendar同步了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表