diff --git a/IceBuilder/DTEUtil.cs b/IceBuilder/DTEUtil.cs index 3a2159e..cb21b0c 100644 --- a/IceBuilder/DTEUtil.cs +++ b/IceBuilder/DTEUtil.cs @@ -208,6 +208,19 @@ public static IceBuilderProjectType IsIceBuilderEnabled(IVsProject project) return IceBuilderProjectType.None; } + public static bool EnsureFileIsCheckout(string path) + { + var sc = Package.Instance.DTE.SourceControl; + if(sc != null) + { + if(sc.IsItemUnderSCC(path) && !sc.IsItemCheckedOut(path)) + { + return sc.CheckOutItem(path); + } + } + return true; + } + public static readonly Guid cppProjectGUID = new Guid("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"); public static readonly Guid cppStoreAppProjectGUID = diff --git a/IceBuilder/MSBuildUtils.cs b/IceBuilder/MSBuildUtils.cs index 774b545..6f54180 100644 --- a/IceBuilder/MSBuildUtils.cs +++ b/IceBuilder/MSBuildUtils.cs @@ -96,6 +96,7 @@ public static bool AddProjectFlavorIfNotExists(Microsoft.Build.Evaluation.Projec { if(property.Value.IndexOf(flavor) == -1) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); if(string.IsNullOrEmpty(property.Value)) { property.Value = string.Format("{0};{1}", flavor, CSharpProjectGUI); @@ -113,6 +114,7 @@ public static bool AddProjectFlavorIfNotExists(Microsoft.Build.Evaluation.Projec } // ProjectTypeGuids not present + DTEUtil.EnsureFileIsCheckout(project.FullPath); project.Xml.AddProperty("ProjectTypeGuids", string.Format("{0};{1}", flavor, CSharpProjectGUI)); return true; } @@ -124,6 +126,7 @@ public static bool RemoveProjectFlavorIfExists(Microsoft.Build.Evaluation.Projec if(property != null && property.Value.IndexOf(flavor) != -1) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); property.Value = property.Value.Replace(flavor, "").Trim(new char[] { ';' }); if(property.Value.Equals(CSharpProjectGUI, StringComparison.CurrentCultureIgnoreCase)) { @@ -176,6 +179,7 @@ private static bool AddGlobalProperty(Microsoft.Build.Evaluation.Project project p => p.Label.Equals("Globals", StringComparison.CurrentCultureIgnoreCase)); if(globals == null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); globals = project.Xml.AddPropertyGroup(); globals.Label = "Globals"; globals.Parent.RemoveChild(globals); @@ -186,6 +190,7 @@ private static bool AddGlobalProperty(Microsoft.Build.Evaluation.Project project p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if(property == null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); property = globals.AddProperty(name, value); return true; } @@ -198,6 +203,7 @@ public static bool EnsureIceBuilderImports(Microsoft.Build.Evaluation.Project pr t => t.Name.Equals("EnsureIceBuilderImports", StringComparison.CurrentCultureIgnoreCase)); if(target == null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); target = project.Xml.AddTarget("EnsureIceBuilderImports"); target.BeforeTargets = "PrepareForBuild"; @@ -227,6 +233,7 @@ private static bool RemoveGlobalProperty(Microsoft.Build.Evaluation.Project proj p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if(property != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); globals.RemoveChild(property); return true; } @@ -239,6 +246,7 @@ private static bool RemoveProperty(Microsoft.Build.Evaluation.Project project, s p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if(property != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); property.Parent.RemoveChild(property); return true; } @@ -251,6 +259,7 @@ private static bool AddImportAfter(Microsoft.Build.Evaluation.Project project, { if(!HasImport(project, import)) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); ProjectImportElement props = project.Xml.CreateImportElement(import); props.Condition = string.Format("Exists('{0}')", import); project.Xml.InsertAfterChild(props, after); @@ -265,6 +274,7 @@ private static bool UpdateImport(Microsoft.Build.Evaluation.Project project, str p => p.Project.Equals(oldValue, StringComparison.CurrentCultureIgnoreCase)); if(import != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); import.Project = newValue; import.Condition = string.Format("Exists('{0}')", newValue); return true; @@ -278,6 +288,7 @@ private static bool RemoveImport(Microsoft.Build.Evaluation.Project project, str p => p.Project.Equals(import, StringComparison.CurrentCultureIgnoreCase)); if(element != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); if(element.Parent != null) { element.Parent.RemoveChild(element); @@ -496,14 +507,14 @@ public static bool RemoveIceBuilderFromProject(Microsoft.Build.Evaluation.Projec modified = RemoveCsharpGlobalProperties(project); modified = RemoveImport(project, IceBuilderCSharpProps) || modified; modified = RemoveImport(project, IceBuilderCSharpTargets) || modified; - - RemoveProjectFlavorIfExists(project, IceBuilderProjectFlavorGUID); + modified = RemoveProjectFlavorIfExists(project, IceBuilderProjectFlavorGUID) || modified; } ProjectPropertyGroupElement group = project.Xml.PropertyGroups.FirstOrDefault( g => g.Label.Equals("IceBuilder", StringComparison.CurrentCultureIgnoreCase)); if(group != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); group.Parent.RemoveChild(group); } @@ -514,6 +525,7 @@ public static bool RemoveIceBuilderFromProject(Microsoft.Build.Evaluation.Projec t => t.Name.Equals("EnsureIceBuilderImports", StringComparison.CurrentCultureIgnoreCase)); if(target != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); if(target.Parent != null) { target.Parent.RemoveChild(target); @@ -529,6 +541,7 @@ public static bool RemoveIceBuilderFromProject(Microsoft.Build.Evaluation.Projec public static void SetProperty(Microsoft.Build.Evaluation.Project project, string label, string name, string value) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); ProjectPropertyGroupElement group = project.Xml.PropertyGroups.FirstOrDefault( g => g.Label.Equals(label, StringComparison.CurrentCultureIgnoreCase)); if(group == null) @@ -593,6 +606,7 @@ public static void SetIceHome(List projects, string iceHome, string g => g.Label.Equals("IceHome", StringComparison.CurrentCultureIgnoreCase)); if(group != null) { + DTEUtil.EnsureFileIsCheckout(project.FullPath); group.SetProperty(Package.IceHomeValue, iceHome); group.SetProperty(Package.IceVersionValue, iceVersion); group.SetProperty(Package.IceIntVersionValue, iceIntVersion); diff --git a/IceBuilder/Package.cs b/IceBuilder/Package.cs index 441eb1a..dd706ba 100644 --- a/IceBuilder/Package.cs +++ b/IceBuilder/Package.cs @@ -961,6 +961,7 @@ public void AddIceBuilderToProject(IVsProject p) { String projectPath = ProjectUtil.GetProjectFullPath(p); bool cppProject = DTEUtil.IsCppProject(p); + DTEUtil.EnsureFileIsCheckout(projectPath); ProjectUtil.SaveProject(p); Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(projectPath, cppProject, false); if(MSBuildUtils.AddIceBuilderToProject(project)) @@ -1016,6 +1017,7 @@ private void RemoveIceBuilderFromProject(object sender, EventArgs e) private void RemoveIceBuilderFromProject(IVsProject p) { string path = ProjectUtil.GetProjectFullPath(p); + DTEUtil.EnsureFileIsCheckout(path); foreach(IVsProject p1 in _buildProjects) { if(path.Equals(ProjectUtil.GetProjectFullPath(p1))) diff --git a/IceBuilder/ProjectConverter.cs b/IceBuilder/ProjectConverter.cs index fafeaae..9041193 100644 --- a/IceBuilder/ProjectConverter.cs +++ b/IceBuilder/ProjectConverter.cs @@ -325,8 +325,9 @@ public static void Upgrade(List projects, UpgradeProgressCallback pr public static bool Upgrade(IVsProject project) { OldConfiguration oldConfiguration = new OldConfiguration(); - Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(project), DTEUtil.IsCppProject(project), true); - + var fullPath = ProjectUtil.GetProjectFullPath(project); + Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(fullPath, DTEUtil.IsCppProject(project), true); + DTEUtil.EnsureFileIsCheckout(fullPath); if(oldConfiguration.Load(msbuildProject, true)) { if(DTEUtil.IsCppProject(project)) diff --git a/IceBuilder/ProjectUtil.cs b/IceBuilder/ProjectUtil.cs index 53cc1a1..086b568 100644 --- a/IceBuilder/ProjectUtil.cs +++ b/IceBuilder/ProjectUtil.cs @@ -255,7 +255,9 @@ public static string GetProperty(IVsProject project, string name, string default public static void SetProperty(IVsProject project, string name, string value) { - MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(GetProjectFullPath(project), DTEUtil.IsCppProject(project), true), "IceBuilder", name, value); + var fullPath = GetProjectFullPath(project); + DTEUtil.EnsureFileIsCheckout(fullPath); + MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(fullPath, DTEUtil.IsCppProject(project), true), "IceBuilder", name, value); } public static string GetEvaluatedProperty(IVsProject project, string name)