Visual Studio project systems like an IVs
* interface for adding items
with explicitly specified item types. Normally this is sufficient because
the project system can pick reasonable defaults for item types based
on file extension or expected project behavior. These defaults can be
augmented. If you still need to explicitly
specify an item type for a project item, follow these steps:
ConfiguredProject configuredProject;
IProjectItemProvider sourceItems = configuredProject.Services.SourceItems;
await sourceItems.AddAsync("CustomItemType", "projectRelativePath\ToYourFile.xpp");
When using this approach to add source files to the project, CPS will:
- Add the source file to source control, if it is within the project directory.
- Automatically add the item to Solution Explorer, DTE, and raise other appropriate events if indeed the item you're adding has an item type that belongs to the set of source item types.
CPS will not:
- Copy the file into the project directory if it is not already there.
- Expand an item template