我有一个要添加到 Sharepoint 项目的自定义项目模板。我需要确保我的模块仅与我的功能相关联,即使项目已经包含其他功能。
通过修改方法中的projectItemReference
.feature 文件中的元素替换 ID很简单。replacementsDictionary
RunStarted
例如,我有以下SampleModule_WebParts.feature
文件:
<?xml version="1.0" encoding="utf-8"?>
<feature xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="$SampleFeatureID$" activateOnDefault="false" description="Sample Web Part" featureId="$SampleFeatureID$" scope="Site" solutionId="00000000-0000-0000-0000-000000000000" title="Contoso Intranet Sample Module Web Parts" version="" deploymentPath="$SharePoint.Project.FileNameWithoutExtension$_$SharePoint.Feature.FileNameWithoutExtension$" xmlns="http://schemas.microsoft.com/VisualStudio/2008/SharePointTools/FeatureModel">
<projectItems>
<projectItemReference itemId="$SampleModuleID$" />
</projectItems>
</feature>
替换$SampleModuleID$
和$SampleFeatureID$
修改方法是微不足道replacementsDictionary
的。IWizard.RunStarted
但是如何修改生成的.csproj
文件片段?
<None Include="Features\SampleModule_WebParts\SampleModule_WebParts.feature">
<FeatureId>{78185D58-6398-4ED2-B0D0-3DC20946FF8F}</FeatureId>
</None>
<Compile Include="SPItems\SampleModule\SampleWebPart\SampleWebPart.cs" />
<Compile Include="SPItems\SampleModule\SampleWebPart\SampleWebPartUserControl.ascx.cs">
<DependentUpon>SampleWebPartUserControl.ascx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="SPItems\SampleModule\SampleWebPart\SampleWebPartUserControl.ascx.designer.cs">
<DependentUpon>SampleWebPartUserControl.ascx.cs</DependentUpon>
</Compile>
<None Include="SPItems\SampleModule\SampleWebPart\SampleWebPart.webpart" />
<None Include="SPItems\SampleModule\SampleWebPart\SharePointProjectItem.spdata">
<SharePointProjectItemId>{D982D304-E7FB-4E8C-899B-7D4096A55892}</SharePointProjectItemId>
</None>
在这种情况下,我需要为and项设置FeatureId
andSharePointProjectItemId
属性。如果我什么都不做,Visual Studio 将自动生成这些 GUID,但它们与我的. 这反过来会导致我的文件中的引用损坏,并且我的模块可能与错误的功能相关联。.feature
.spdata
replacementsDictionary
.feature
如何设置这些自定义属性,以便.csproj
在用户保存文件时将它们持久保存到文件中?IWizard.ProjectItemFinishedGenerating
似乎是正确的实现方法,我可以检查ProjectItem
参数以确定何时生成.spdata
和.feature
文件,但我应该在那里设置FeatureId
和SharePointProjectItemId
属性?