通过C#API将解决方案部署解决方案的正确方法是什么?
-
09-12-2019 - |
题
我在一个团队中为SharePoint Foundation 2010开发一个“门户”。我负责制作安装程序,该安装程序设置SharePoint的新实例。它只处理的只是安装解决方案文件和SharePoint的配置。安装程序将部署文件部署到GAC并创建我们的联合安全客户端(用于我们的SharePoint索赔的Auth)。
在安装一个实例期间,我完成了一些与SharePoint有关的任务,并使用.NET 3.5中的SharePoint API:
- 创建/配置trust
- 创建一个Web应用程序。
- 将解决方案部署到农场和Web应用程序
- 创建默认站点集合
- 在网站集中激活默认功能
- 更新Web应用程序“属性”
更新我已经能够在单个SharePoint服务器上正确安装工作,即一个服务器托管服务器场数据库,另一个是SharePoint Services的完整堆栈。我已经开始使用设置进行测试,这些设置将模仿我们托管环境中的SharePoint的真实世界设置。我们有一个数据库服务器和至少三个SharePoint服务器,其中一个只有一个有中央管理局。
我遇到的问题是在这种情况下,我可以正确且没有任何错误,除了功能的激活之外,还没有任何错误。我删除了这一步的代码并验证了Web应用程序,站点集合,信任等(“属性”除了通过启动网站,身份验证和查看默认“团队”主题来正确创建) 。但是,一旦我通过API或通过网站收集设置激活默认功能,我无法再访问该站点并收到错误。
这可能是我问题的症结,我在这里解释时的问题。我们的解决方案非常复杂,因为它涉及从安全性和依赖SharePoint之外的其他服务方面的许多配置。我不知道我们的某些设置是否在服务器上不会传播,导致我们解决方案中的内部错误导致错误页面。如果我在农场情况中坚持下来,我也不知道当我设置“属性”时。当我第一次开始这项任务时,我没有将这些问题的问题发出问题,它造成了类似于我现在所看到的问题。
我也不确定是否正确部署了解决方案,因此损坏了这些功能。我在每个SharePoint服务器上设置了ULS查看器,但我找不到与错误页面上收到的错误相关ID有关的任何内容。我实际上在“Master”SharePoint Server上的ULS查看器中实际上没有事件。我可以看到其他两个服务器上查看器中的解决方案部署和缩回。
我必须遗漏有多个服务器的农场发生的东西。我希望有人可以看一下我用于部署解决方案的代码和设置属性来帮助我。我也非常想弄清楚为什么我看不到我在任何ULS观众中获得的错误。有人可以为我解释这个吗?
我还在寻找更多的明确例子,这些例子是通过C#API配置和设置SharePoint的更新示例。到目前为止,我一直在分解Commandlet的代码,并在代码中复制我可以的内容。我仍然没有“正确的”方法来通过C#激活功能,只需创建运行stsadm.exe的进程即可激活该功能。
这是我添加和部署解决方案的代码:
.SPSolution newSolution = SPFarm.Local.Solutions.Add(Path.Combine(this.SharePointPointRootFolder, solutionDefinition.filename)); if (!solutionDefinition.webApplicationSpecific) { Console.WriteLine("Adding a farm specific solution."); newSolution.Deploy(DateTime.Now, true, true); this.WaitForSolutionJobsToComplete(newSolution.Id); newSolution.Synchronize(); } else //specific to a web application. Load the new solution. { Console.WriteLine("Adding web application specific solution."); Collection<SPWebApplication> webAppCol = new Collection<SPWebApplication>(); webAppCol.Add(this.WebApplication); newSolution.Deploy(DateTime.Now, true, webAppCol, true); this.WaitForSolutionJobsToComplete(newSolution.Id); newSolution = SPFarm.Local.GetObject(newSolution.Id) as SPSolution; newSolution.Synchronize(); this.WaitForSolutionJobsToComplete(newSolution.Id); newSolution.Update(); }
这是我的激活功能的代码。它只需使用一个使用stsadm.exe:
.void UpdateFeatures(SPSite site) { Console.WriteLine("Updating features."); SPSolutionDefinitionCollection collection = SolutionConfigurer.LoadSolutionDefinitions(); foreach (SPSolutionDefinition solutionDefinition in collection.spSolutionDefinition) { Guid id = new Guid(solutionDefinition.ID); if (solutionDefinition.spFeatureDefinition != null && solutionDefinition.spFeatureDefinition.Length > 0) { foreach (Models.SPFeatureDefinition fDef in solutionDefinition.spFeatureDefinition) { Guid fDefId = new Guid(fDef.ID); //this.Activate(fDefId, site); Process stsadmP = WebApplicationConfigurer.GetSTSADMProcess(this.STSADMPath, "-o activatefeature -id " + fDef.ID + " -url " + this.SiteCollectionUrl + " -force"); Console.WriteLine(string.Format("Invoking STSADM.EXE for feature deployment: {0} with arguments:{1}", stsadmP.StartInfo.FileName, stsadmP.StartInfo.Arguments)); stsadmP.Start(); stsadmP.WaitForExit(); if (stsadmP.ExitCode == 0) { Console.WriteLine(string.Format("STSADM.EXE successfully ran for feature id {0} and produced this output: {1}", fDefId, stsadmP.StandardOutput.ReadToEnd())); } else { Console.WriteLine(string.Format("STSADM.EXE did not produce a successful exit code for feature id {0} and produced this output: {1} + {2}", fDefId, stsadmP.StandardOutput.ReadToEnd(), stsadmP.StandardError.ReadToEnd())); } } } } }
这是我如何更新属性。我最后做到了,因为我在部署解决方案后正在这样做,但似乎激活功能正在重置值。
.public void UpdatePropertiesWebApplication() { string dnsName = this.SigningCertificate.GetNameInfo(X509NameType.DnsName, false); SPWebApplication webApplication = SPFarm.Local.GetObject(this.WebApplicationId) as SPWebApplication; if (webApplication != null) { Console.WriteLine("Updating property information for the web application."); if (!webApplication.Properties.ContainsKey(Constants.PropertyBagKeys.ESB_ROOT)) { webApplication.Properties.Add(Constants.PropertyBagKeys.ESB_ROOT, this.ESBUrl); } else { Console.WriteLine("Updating ESB Root URL. " + this.ESBUrl); webApplication.Properties[Constants.PropertyBagKeys.ESB_ROOT] = this.ESBUrl; } Console.WriteLine("ESB Root Url: " + webApplication.Properties[Constants.PropertyBagKeys.ESB_ROOT]); if (!webApplication.Properties.ContainsKey(Constants.PropertyBagKeys.REALM)) { webApplication.Properties.Add(Constants.PropertyBagKeys.REALM, this.SharePointTrustPoint); } else { Console.WriteLine("Updating realm. " + this.SharePointTrustPoint); webApplication.Properties[Constants.PropertyBagKeys.REALM] = this.SharePointTrustPoint; } Console.WriteLine("Realm: " + webApplication.Properties[Constants.PropertyBagKeys.REALM]); if (!webApplication.Properties.ContainsKey(Constants.PropertyBagKeys.SSO_ROOT)) { webApplication.Properties.Add(Constants.PropertyBagKeys.SSO_ROOT, this.SSOUrl); } else { Console.WriteLine("Updating the broker url. " + this.SSOUrl); webApplication.Properties[Constants.PropertyBagKeys.SSO_ROOT] = this.SSOUrl; } Console.WriteLine("Broker Url: " + webApplication.Properties[Constants.PropertyBagKeys.SSO_ROOT]); if (!webApplication.Properties.ContainsKey(Constants.PropertyBagKeys.TRUSTED_CERT_DNS_IDENT)) { webApplication.Properties.Add(Constants.PropertyBagKeys.TRUSTED_CERT_DNS_IDENT, dnsName); } else { Console.WriteLine("Updating trusted cert dns identity. " + dnsName); webApplication.Properties[Constants.PropertyBagKeys.TRUSTED_CERT_DNS_IDENT] = dnsName; } Console.WriteLine("Trusted Certificate Identity: " + webApplication.Properties[Constants.PropertyBagKeys.TRUSTED_CERT_DNS_IDENT]); webApplication.Update(true); } }
解决方案
从什么是新的:SharePoint的Windows PowerShell
Windows PowerShell取代了stsadm.exe管理工具。前进,您应该使用Windows PowerShell脚本技术在SharePoint Foundation 2010中开发任何新的命令行脚本。
以下是使用powershell部署的一些样本和脚本:
- 如何部署SharePoint 2010解决方案包使用Windows PowerShell
- 部署SharePoint 2010解决方案包使用PowerShell
- 使用PowerShell部署SharePoint 2010解决方案
- 在SharePoint 2010中添加和部署解决方案
以及以下是有关激活PowerShell中的功能的信息:
- 安装或卸载功能
- 在SharePoint 2010中激活和停用功能,并在SharePoint 2010中使用PowerShell 要回答您的具体问题,可以在C#中激活功能:
.Guid fDefId = new Guid(fDef.ID); site.Features.Add(fDefId);
有关详细信息,请参阅 spsite.features spfeaturecollection.add
其他提示
是完全诚实的,我从来没有看到任何在我可以直接用stsadm做的代码中做任何事情的重点。
所以我总是只使用相当于我所需要的东西:
stsadm -o deletesolution -name solution.wsp -override
stsadm -o addsolution -filename c:\path\solution.wsp
stsadm -o deploysolution -name solution.wsp -allowgacdeployment -local -force
.
然后...
激活功能
设置解决方案选项
应用主模板
创建子站点
创建列表
添加Web部件
设置权限
隐藏/显示导航和列
将任何数据添加到所需部署
完成
我不得不使用您使用的方法部署解决方案的许多问题(只是在这里发布的搜索,找不到解决方案)