diff --git a/SharedProject/Core/MsTestPlatform/CodeCoverage/ProjectSaver.cs b/SharedProject/Core/MsTestPlatform/CodeCoverage/ProjectSaver.cs new file mode 100644 index 00000000..e5f03004 --- /dev/null +++ b/SharedProject/Core/MsTestPlatform/CodeCoverage/ProjectSaver.cs @@ -0,0 +1,40 @@ +using Microsoft; +using Microsoft.VisualStudio; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; +using System; +using System.ComponentModel.Composition; + +namespace FineCodeCoverage.Core.MsTestPlatform.CodeCoverage +{ + interface IProjectSaver + { + void SaveProject(IVsHierarchy projectHierarchy); + } + + [Export(typeof(IProjectSaver))] + internal class ProjectSaver : IProjectSaver + { + private IServiceProvider serviceProvider; + + [ImportingConstructor] + public ProjectSaver( + [Import(typeof(SVsServiceProvider))] + IServiceProvider serviceProvider + ) + { + this.serviceProvider = serviceProvider; + } + + public void SaveProject(IVsHierarchy projectHierarchy) + { + ThreadHelper.ThrowIfNotOnUIThread(); + var _solution = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution)); + Assumes.Present(_solution); + int hr = _solution.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, projectHierarchy, 0); + if (ErrorHandler.Failed(hr)) + { + } + } + } +} diff --git a/SharedProject/Core/MsTestPlatform/CodeCoverage/VsRunSettingsWriter.cs b/SharedProject/Core/MsTestPlatform/CodeCoverage/VsRunSettingsWriter.cs index 8f9f7519..fa603582 100644 --- a/SharedProject/Core/MsTestPlatform/CodeCoverage/VsRunSettingsWriter.cs +++ b/SharedProject/Core/MsTestPlatform/CodeCoverage/VsRunSettingsWriter.cs @@ -4,8 +4,8 @@ using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Composition; -using Task = System.Threading.Tasks.Task; using System.Threading.Tasks; +using FineCodeCoverage.Core.MsTestPlatform.CodeCoverage; namespace FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage { @@ -14,14 +14,17 @@ internal class VsRunSettingsWriter : IVsRunSettingsWriter { private const string projectRunSettingsFilePathElementName = "RunSettingsFilePath"; private readonly IServiceProvider serviceProvider; + private readonly IProjectSaver projectSaver; [ImportingConstructor] public VsRunSettingsWriter( [Import(typeof(SVsServiceProvider))] - IServiceProvider serviceProvider + IServiceProvider serviceProvider, + IProjectSaver projectSaver ) { this.serviceProvider = serviceProvider; + this.projectSaver = projectSaver; } public async Task WriteRunSettingsFilePathAsync(Guid projectGuid, string projectRunSettingsFilePath) @@ -34,8 +37,7 @@ public async Task WriteRunSettingsFilePathAsync(Guid projectGuid, string p { if (vsHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage) { - // care not to use 2 ! - success = vsBuildPropertyStorage.SetPropertyValue(projectRunSettingsFilePathElementName, null, 1, projectRunSettingsFilePath) == VSConstants.S_OK; + success = vsBuildPropertyStorage.SetPropertyValue(projectRunSettingsFilePathElementName, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, projectRunSettingsFilePath) == VSConstants.S_OK; } } return success; @@ -43,6 +45,7 @@ public async Task WriteRunSettingsFilePathAsync(Guid projectGuid, string p public async Task RemoveRunSettingsFilePathAsync(Guid projectGuid) { + var ok = false; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var vsSolution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution; @@ -51,7 +54,12 @@ public async Task RemoveRunSettingsFilePathAsync(Guid projectGuid) { if (vsHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage) { - ok = vsBuildPropertyStorage.RemoveProperty(projectRunSettingsFilePathElementName, null, 1) == VSConstants.S_OK; + ok = vsBuildPropertyStorage.RemoveProperty(projectRunSettingsFilePathElementName, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE) == VSConstants.S_OK; + + if (ok) + { + this.projectSaver.SaveProject(vsHierarchy); + } } } return ok; diff --git a/SharedProject/SharedProject.projitems b/SharedProject/SharedProject.projitems index c12aa91f..23fbaf57 100644 --- a/SharedProject/SharedProject.projitems +++ b/SharedProject/SharedProject.projitems @@ -94,6 +94,7 @@ +