我有一个包含许多功能的 wsp 包。 wsp 包中包含的一些功能依赖于 wsp 包中的其他功能。
在我的例子中,两种内容类型是通过特性创建的(内容类型 A 和内容类型 B),内容类型 B 继承自内容类型 A。
显然,包含内容类型 A(功能 A)的功能需要在包含内容类型 B(功能 B)的功能之前部署。
有没有办法让功能 A 在功能 B 之前部署?理想情况下,这两个功能都将通过 onet.xml 文件自动激活,而功能 A 将在之前部署,但我不知道该怎么做...
我不一定要寻找解决此特定问题的解决方案,但我想知道的是:您如何处理依赖于 SharePoint 项目中其他功能的功能?
谢谢!
最佳答案
您还可以创建一个事件处理程序并按照您想要的顺序激活这些功能。我发现依靠在代码中手动执行操作而不是使用 xml 文件执行操作总是更好。
看看 SPWeb.Features 和 FeatureCollections.Add
这是我如何在事件处理程序中编码的示例
public void ActivateFeatures(SPFeatureReceiverProperties properties)
{
logger.Info("Creating content types");
// feature is scoped at Site, so the parent is type SPSite rather than SPWeb..
using (SPSite site = properties.Feature.Parent as SPSite)
{
SPWeb currentWeb = null;
if (site != null)
{
currentWeb = site.RootWeb;
}
else
{
currentWeb = properties.Feature.Parent as SPWeb;
}
using (currentWeb)
{
if (currentWeb == null) return;
try
{
currentWeb.Site.Features.Add(new Guid("01A27C0C-2E44-4298-A74F-8F50601A20B0")); // ctCategory
currentWeb.Site.Features.Add(new Guid("496DFE3E-A41E-46e8-B627-29775F376017")); // ctChapter
currentWeb.Site.Features.Add(new Guid("F2ECBD5A-4766-49bf-A158-62550661E141")); // ctChapterList
currentWeb.Site.Features.Add(new Guid("8C91646F-1466-49d7-BB53-B666F164AA96")); // ctComments
currentWeb.Site.Features.Add(new Guid("112E1564-FA1C-41fd-853A-F7569C555905")); // ctDocument
currentWeb.Site.Features.Add(new Guid("48BD5A07-8DD1-46ef-9F05-9824380BA26E")); // ctExternalReviewer
currentWeb.Site.Features.Add(new Guid("20553A8E-8272-400c-816D-6EE8E02F34E9")); // ctStandard
currentWeb.Site.Features.Add(new Guid("E84259BD-E4B3-465e-8928-1745F8760F2D")); // ctSuggestion
currentWeb.Site.Features.Add(new Guid("0B313654-D296-4bfa-8F21-E4FF33C1DD6C")); // ctTask
currentWeb.Site.Features.Add(new Guid("EFDA877B-B686-4954-9F1A-65ADB32B2E50")); // ctDepartment
currentWeb.Site.Features.Add(new Guid("4E4B984E-65E2-4601-A216-2C4D08AA97AE")); // ctInnerWork
currentWeb.Site.Features.Add(new Guid("4D85D4B9-1909-45cd-81C7-CDBB0874492F")); // ctOtherDocuments
logger.Info("Content types added successfully");
}
catch (Exception ex)
{
logger.Error("Could not in activate content types.", ex);
}
}
}
}
关于sharepoint - SharePoint 功能部署中的时间安排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1477930/