4
4
using Microsoft . VisualStudio . Shell . Interop ;
5
5
using System ;
6
6
using System . ComponentModel . Composition ;
7
- using Task = System . Threading . Tasks . Task ;
8
7
using System . Threading . Tasks ;
8
+ using FineCodeCoverage . Core . MsTestPlatform . CodeCoverage ;
9
9
10
10
namespace FineCodeCoverage . Engine . MsTestPlatform . CodeCoverage
11
11
{
@@ -14,14 +14,17 @@ internal class VsRunSettingsWriter : IVsRunSettingsWriter
14
14
{
15
15
private const string projectRunSettingsFilePathElementName = "RunSettingsFilePath" ;
16
16
private readonly IServiceProvider serviceProvider ;
17
+ private readonly IProjectSaver projectSaver ;
17
18
18
19
[ ImportingConstructor ]
19
20
public VsRunSettingsWriter (
20
21
[ Import ( typeof ( SVsServiceProvider ) ) ]
21
- IServiceProvider serviceProvider
22
+ IServiceProvider serviceProvider ,
23
+ IProjectSaver projectSaver
22
24
)
23
25
{
24
26
this . serviceProvider = serviceProvider ;
27
+ this . projectSaver = projectSaver ;
25
28
}
26
29
27
30
public async Task < bool > WriteRunSettingsFilePathAsync ( Guid projectGuid , string projectRunSettingsFilePath )
@@ -34,15 +37,15 @@ public async Task<bool> WriteRunSettingsFilePathAsync(Guid projectGuid, string p
34
37
{
35
38
if ( vsHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage )
36
39
{
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 ;
39
41
}
40
42
}
41
43
return success ;
42
44
}
43
45
44
46
public async Task < bool > RemoveRunSettingsFilePathAsync ( Guid projectGuid )
45
47
{
48
+
46
49
var ok = false ;
47
50
await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
48
51
var vsSolution = serviceProvider . GetService ( typeof ( SVsSolution ) ) as IVsSolution ;
@@ -51,7 +54,12 @@ public async Task<bool> RemoveRunSettingsFilePathAsync(Guid projectGuid)
51
54
{
52
55
if ( vsHierarchy is IVsBuildPropertyStorage vsBuildPropertyStorage )
53
56
{
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
+ }
55
63
}
56
64
}
57
65
return ok ;
0 commit comments