internal static void UnloadProject(MSBuild.Evaluation.ProjectCollection projectCollection, MSBuild.Evaluation.Project project) { lock (SolutionProjectCollectionLock) { projectCollection.UnloadProject(project); } }
private static void addReference(string projectFile, string filename) { using (var collection = new Microsoft.Build.Evaluation.ProjectCollection()) { collection.LoadProject(projectFile); var project = collection.LoadedProjects.FirstOrDefault(o => o.FullPath == projectFile); var items = project.GetItems("Compile"); if (!items.Any(o => o.EvaluatedInclude == filename || o.UnevaluatedInclude == filename)) { project.AddItem("Compile", filename); project.Save(); } collection.UnloadProject(project); } }