From c1fd93208e18be22292373ac506922be92703caa Mon Sep 17 00:00:00 2001 From: juste Date: Fri, 7 Mar 2014 16:17:31 -0800 Subject: [PATCH] NuGetPackageImportStamp project property --- .../ProjectSystems/CpsProjectSystem.cs | 6 ++++ .../ProjectSystems/VsProjectSystem.cs | 30 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/ProjectSystems/CpsProjectSystem.cs b/src/VisualStudio/ProjectSystems/CpsProjectSystem.cs index f2d7fe1f..22662a25 100644 --- a/src/VisualStudio/ProjectSystems/CpsProjectSystem.cs +++ b/src/VisualStudio/ProjectSystems/CpsProjectSystem.cs @@ -60,6 +60,9 @@ namespace NuGet.VisualStudio Project, Project.ToVsHierarchy(), buildProject => NuGet.MSBuildProjectUtility.AddImportStatement(buildProject, relativeTargetPath, location)); + + // notify the project system of the change + UpdateImportStamp(Project); } public override void RemoveImport(string targetPath) @@ -98,6 +101,9 @@ namespace NuGet.VisualStudio Project, Project.ToVsHierarchy(), buildProject => NuGet.MSBuildProjectUtility.RemoveImportStatement(buildProject, relativeTargetPath)); + + // notify the project system of the change + UpdateImportStamp(Project); } } } \ No newline at end of file diff --git a/src/VisualStudio/ProjectSystems/VsProjectSystem.cs b/src/VisualStudio/ProjectSystems/VsProjectSystem.cs index 5591cbf9..6fe4226c 100644 --- a/src/VisualStudio/ProjectSystems/VsProjectSystem.cs +++ b/src/VisualStudio/ProjectSystems/VsProjectSystem.cs @@ -8,7 +8,9 @@ using System.Linq; using System.Reflection; using System.Runtime.Versioning; using EnvDTE; +using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using NuGet.VisualStudio.Resources; using MsBuildProject = Microsoft.Build.Evaluation.Project; using MsBuildProjectItem = Microsoft.Build.Evaluation.ProjectItem; @@ -391,8 +393,12 @@ namespace NuGet.VisualStudio } string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath); - Project.AddImportStatement(relativeTargetPath, location); + Project.AddImportStatement(relativeTargetPath, location); + Project.Save(this); + + // notify the project system of the change + UpdateImportStamp(Project); } public virtual void RemoveImport(string targetPath) @@ -404,6 +410,9 @@ namespace NuGet.VisualStudio string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath); Project.RemoveImportStatement(relativeTargetPath); Project.Save(this); + + // notify the project system of the change + UpdateImportStamp(Project); } public virtual bool IsSupportedFile(string path) @@ -470,6 +479,25 @@ namespace NuGet.VisualStudio return y.Path.CompareTo(x.Path); } + /// + /// Sets NuGetPackageImportStamp to a new random guid. This is a hack to let the project system know it is out of date. + /// The value does not matter, it just needs to change. + /// + protected static void UpdateImportStamp(Project project) + { + // There is no reason to call this for pre-Dev12 project systems. + if (VsVersionHelper.IsVisualStudio2013) + { + IVsBuildPropertyStorage propStore = project.ToVsHierarchy() as IVsBuildPropertyStorage; + if (propStore != null) + { + // af617720 + string stamp = Guid.NewGuid().ToString().Split('-')[0]; + ErrorHandler.ThrowOnFailure(propStore.SetPropertyValue("NuGetPackageImportStamp", string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, stamp)); + } + } + } + private static void TrySetCopyLocal(dynamic reference) { // Always set copy local to true for references that we add