44using Microsoft . VisualStudio . Shell . Interop ;
55using System ;
66using System . ComponentModel . Composition ;
7- using Task = System . Threading . Tasks . Task ;
87using System . Threading . Tasks ;
8+ using FineCodeCoverage . Core . MsTestPlatform . CodeCoverage ;
99
1010namespace FineCodeCoverage . Engine . MsTestPlatform . CodeCoverage
1111{
@@ -14,14 +14,17 @@ internal class VsRunSettingsWriter : IVsRunSettingsWriter
1414 {
1515 private const string projectRunSettingsFilePathElementName = "RunSettingsFilePath" ;
1616 private readonly IServiceProvider serviceProvider ;
17+ private readonly IProjectSaver projectSaver ;
1718
1819 [ ImportingConstructor ]
1920 public VsRunSettingsWriter (
2021 [ Import ( typeof ( SVsServiceProvider ) ) ]
21- IServiceProvider serviceProvider
22+ IServiceProvider serviceProvider ,
23+ IProjectSaver projectSaver
2224 )
2325 {
2426 this . serviceProvider = serviceProvider ;
27+ this . projectSaver = projectSaver ;
2528 }
2629
2730 public async Task < bool > WriteRunSettingsFilePathAsync ( Guid projectGuid , string projectRunSettingsFilePath )
@@ -34,15 +37,15 @@ public async Task<bool> WriteRunSettingsFilePathAsync(Guid projectGuid, string p
3437 {
3538 if ( vsHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage )
3639 {
37- // care not to use 2 !
38- success = vsBuildPropertyStorage . SetPropertyValue ( projectRunSettingsFilePathElementName , null , 1 , projectRunSettingsFilePath ) == VSConstants . S_OK ;
40+ success = vsBuildPropertyStorage . SetPropertyValue ( projectRunSettingsFilePathElementName , string . Empty , ( uint ) _PersistStorageType . PST_PROJECT_FILE , projectRunSettingsFilePath ) == VSConstants . S_OK ;
3941 }
4042 }
4143 return success ;
4244 }
4345
4446 public async Task < bool > RemoveRunSettingsFilePathAsync ( Guid projectGuid )
4547 {
48+
4649 var ok = false ;
4750 await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
4851 var vsSolution = serviceProvider . GetService ( typeof ( SVsSolution ) ) as IVsSolution ;
@@ -51,7 +54,12 @@ public async Task<bool> RemoveRunSettingsFilePathAsync(Guid projectGuid)
5154 {
5255 if ( vsHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage )
5356 {
54- ok = vsBuildPropertyStorage . RemoveProperty ( projectRunSettingsFilePathElementName , null , 1 ) == VSConstants . S_OK ;
57+ ok = vsBuildPropertyStorage . RemoveProperty ( projectRunSettingsFilePathElementName , string . Empty , ( uint ) _PersistStorageType . PST_PROJECT_FILE ) == VSConstants . S_OK ;
58+
59+ if ( ok )
60+ {
61+ this . projectSaver . SaveProject ( vsHierarchy ) ;
62+ }
5563 }
5664 }
5765 return ok ;
0 commit comments