I am trying to constrcut a net core console app project programmatically. To do this, I coded like below. The problem is ..... FileCodeModel instance "fcm" is always null in the code. if I forcefully show the messagebox after calling AddFromTemplate(), the issue does not occur. but i do not prefer this workaround. does anyone know why this issue ouucrs and how to avoid it?
string itemName = "View.cs";
string itemTemplatePath =solution2.GetProjectItemTemplate("CodeFile", "CSharp");
destProject.ProjectItems.AddFromTemplate(itemTemplatePath, itemName);
//if I forcefully show the msgbox, fcm is not null.!!
//MessageBox.show("ok","ok");
ProjectItem destProjectItem = null;
foreach(ProjectItem projectItem in destProject.ProjectItems)
{
if(projectItem.Name == itemName)
{
destProjectItem = projectItem;
break;
}
}
FileCodeModel fcm = destProjectItem.FileCodeModel;
if (fcm == null)
throw new ArgumentNullException("fcm is null!!");
fcm.AddNamespace("MyNameSpace");
now I am using VS 2017 latest version wit net core sdk.