private IVstaProjectHostItem AddProjectHostItemInternal(string itemName, string templateName, string itemEntryPoint)
{
foreach (IVstaProjectHostItem existingItem in this.hostAdapter.ProjectHostItems)
{
if (existingItem.ProgrammingModelHostItem.Cookie == itemName)
return null; // Do not add existing one.
}
// Make sure the template is not read-only.
string languageFolder = null;
string languageExtension = null;
if (this.language == SupportedLanguage.CSharp)
{
languageFolder = "CSharp";
languageExtension = ".cs";
}
else
{
languageFolder = "VisualBasic";
languageExtension = ".vb";
}
string templatePath = this.hostItemTemplatesPath + @"\" + languageFolder + @"\" + templateName + languageExtension;
FileInfo fileInfo = new FileInfo(templatePath);
bool isReadOnly = fileInfo.IsReadOnly;
fileInfo.IsReadOnly = false;
IVstaProjectHostItem projectHostItem = null;
try
{
projectHostItem = hostAdapter.ProjectHostItems.AddProjectHostItem(
itemName,
"Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp." + itemEntryPoint,
"Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint",
itemName,
this.hostItemTemplatesPath + @"\" + languageFolder + @"\" + templateName);
this.project.Save(this.project.FileName);
}
finally
{
fileInfo.IsReadOnly = isReadOnly;
}
if (projectHostItem != null)
return projectHostItem;
else
throw new InvalidOperationException("Fail to add project host item.");
}