Brief
I'm generating .cs files and then automatically including the files in specified projects (If you're interested on how view this question). I can run the function and the files are included as expected.
Issue
I remove the files manually from the project and save. I then rerun the function but the project object still contains the removed items - event though the project has been Reevaluated.
The GetItemsByEvaluatedInclude function returns an item even though i've removed it and it's no longer inthe .csproj file
The code i'm currently using:
var project = ProjectCollection.GlobalProjectCollection.LoadedProjects.FirstOrDefault(pr => pr.FullPath == projectLocation);
if (project == null)
{
project = new Microsoft.Build.Evaluation.Project(projectLocation);
}
project.ReevaluateIfNecessary();
var loc = Path.Combine(location, FileName);
if (!File.Exists(loc))
{
File.Create(loc).Dispose();
}
var items = project.GetItemsByEvaluatedInclude(loc); // Issue here
if (items == null || items.Count == 0)
{
project.AddItem("Compile", loc);
}
Notes
Visual Studios Professional 2012