Hi there,
I am building a wizard to add some VC source files. I have the wizard running correctly, However I am having problems running using VCCodeModel from the IWizard implementation.
The following code runs correctly :
public void ProjectItemFinishedGenerating(
EnvDTE.ProjectItem projectItem ) {
var project = projectItem.ContainingProject;
var codeModel = (VCCodeModel)project.CodeModel;
codeFile = projectItem.FileNames[0];
codeModel.AddInclude("foo.h", codeFile);
}The following code returns an E_FAIL from AddInclude(). The documentation is not helpful ( it does not describe any error conditions for that method ).
public void ProjectItemFinishedGenerating(
EnvDTE.ProjectItem projectItem ) {
var project = projectItem.ContainingProject;
var codeModel = (VCCodeModel)project.CodeModel;
codeFile = projectItem.FileNames[0];
firstInclude = codeModel.Includes.Item(1);
// This fails
codeModel.AddInclude("foo.h", codeFile, firstInclude);
}According to the 'AddInclude' documentation, (http://msdn.microsoft.com/en-US/library/microsoft.visualstudio.vccodemodel.vccodemodel.addinclude(v=vs.110).aspx) the third parameter to AddInclude can be a code element after which to insert the new include directive. 'firstInclude' in this example is the 'stdafx.h' include ( I have verified this in the debugger ).
Any help would be appreciated. I am using VS2012 Premium Update 1