Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:03:38+00:00 2026-06-17T12:03:38+00:00

I have a custom item template that I am adding to a Sharepoint project.

  • 0

I have a custom item template that I am adding to a Sharepoint project. I need to ensure that my modules are only associated with my feature, even if the project already contains other features.

Replacing IDs in projectItemReference elements within .feature files is trivial to do by modifying the replacementsDictionary in the RunStarted method.

For example, I have the following SampleModule_WebParts.feature file:

<?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>

Replacing $SampleModuleID$ and $SampleFeatureID$ by modifying the replacementsDictionary in the IWizard.RunStarted method is trivial. But how can I modify the generated .csproj file snippet?

<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>

In this case, I’d need to set the FeatureId and SharePointProjectItemId properties for the .feature and .spdata items. If I don’t do anything, Visual Studio will autogenerate those GUIDs, but they won’t match what I have in my replacementsDictionary. And that in turn leads to a broken reference in my .feature file and my module may get associated with the wrong feature.

How can I set those custom properties so that they are persisted into the .csproj file when the user saves it? IWizard.ProjectItemFinishedGenerating seems like the correct method to implement and I can inspect the ProjectItem parameter to figure out when the .spdata and .feature files have been generated, but what should I do there to set the FeatureId and SharePointProjectItemId properties?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:03:39+00:00Added an answer on June 17, 2026 at 12:03 pm

    The solution was to convert the Project reference into an ISharePointProject and calling
    ISharepointProject.Synchronize(). After that I could traverse the SharePoint project’s object model.

    var sp = project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
    var projectService = new ServiceProvider(sp).GetService(typeof(ISharePointProjectService)) as ISharePointProjectService;
    var sharepointProject = projectService.Convert<Project, ISharePointProject>(project);
    sharepointProject.Synchronize();
    

    After finding the my module and my feature from the collections returned by the ProjectItems and Features properties, I could simply associate the module with the feature:

    sampleFeature.ProjectItems.Add(sampleModule);
    

    Because I can fix the references programmatically, I can leave the old module GUID in the .feature file and clean up the invalid association by modifying the sampleFeature.Model.ProjectItems collection.

    var invalidSampleModuleAssociation = (from projectItem in sampleFeature.Model.ProjectItems
                                          where projectItem.ItemId == originalSampleModuleID
                                          select projectItem).First();
    sampleFeature.Model.ProjectItems.Remove(invalidSampleModuleAssociation);
    

    Finally, I need to remove my module from any other features that the project might have, because Visual Studio automatically associates a new module with the first feature with an appropriate scope.

    var unneededAssociations = (from otherFeature in sharepointProject.Features
                                where otherFeature.Name != sampleFeature.Name
                                from projectItem in otherFeature.ProjectItems
                                where projectItem.Name == sampleModule.Name
                                select new
                                {
                                    Feature = otherFeature,
                                    ModuleToRemove = projectItem
                                }).ToArray();
    foreach (var moduleAssociation in unneededAssociations)
    {
        moduleAssociation.Feature.ProjectItems.Remove(moduleAssociation.ModuleToRemove);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom media item template that allows users to add category filters
I have a number of custom Item and Project Templates for Visual Studio 2010.
I have a custom sitecore button which changes the template of the current item,
I have an editor template for a custom object. Inside that editor template I
I have a custom template for my WPF windows ComboBoxes, which display items that
I have a custom list template that is deployed as a .wsp. The list
I have created several custom attributes for my products. I have some that need
I have two methods that I'm using as custom tags in a template engine:
I have a custom ItemTemplate for a ListBox and I need to bind a
I have some custom type: [RdfSerializable] public class Item { [RdfProperty(true)] public string Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.