@@ -102,14 +102,22 @@ public async Task SaveAsync()
102
102
/// <summary>
103
103
/// Tries to set an attribute in the project file for the item.
104
104
/// </summary>
105
- public async Task < bool > TrySetAttributeAsync ( string name , string value )
105
+ public Task < bool > TrySetAttributeAsync ( string name , string value )
106
+ {
107
+ return TrySetAttributeAsync ( name , value , ProjectStorageType . ProjectFile ) ;
108
+ }
109
+
110
+ /// <summary>
111
+ /// Tries to set an attribute in the project file for the item, storing the value in the specified storage type.
112
+ /// </summary>
113
+ public async Task < bool > TrySetAttributeAsync ( string name , string value , ProjectStorageType storageType )
106
114
{
107
115
await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
108
116
GetItemInfo ( out IVsHierarchy hierarchy , out _ , out _ ) ;
109
117
110
118
if ( hierarchy is IVsBuildPropertyStorage storage )
111
119
{
112
- storage . SetPropertyValue ( name , "" , ( uint ) _PersistStorageType . PST_PROJECT_FILE , value ) ;
120
+ storage . SetPropertyValue ( name , "" , ToPersistStorageType ( storageType ) , value ) ;
113
121
return true ;
114
122
}
115
123
@@ -120,20 +128,38 @@ public async Task<bool> TrySetAttributeAsync(string name, string value)
120
128
/// Tries to retrieve an attribute value from the project file for the item.
121
129
/// </summary>
122
130
/// <returns><see langword="null"/> if the attribute doesn't exist.</returns>
123
- public async Task < string ? > GetAttributeAsync ( string name )
131
+ public Task < string ? > GetAttributeAsync ( string name )
132
+ {
133
+ return GetAttributeAsync ( name , ProjectStorageType . ProjectFile ) ;
134
+ }
135
+
136
+ /// <summary>
137
+ /// Tries to retrieve an attribute value from the project file for the item, getting the value from the specfied storage type.
138
+ /// </summary>
139
+ /// <returns><see langword="null"/> if the attribute doesn't exist.</returns>
140
+ public async Task < string ? > GetAttributeAsync ( string name , ProjectStorageType storageType )
124
141
{
125
142
await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
126
143
GetItemInfo ( out IVsHierarchy hierarchy , out _ , out _ ) ;
127
144
128
145
if ( hierarchy is IVsBuildPropertyStorage storage )
129
146
{
130
- storage . GetPropertyValue ( name , "" , ( uint ) _PersistStorageType . PST_PROJECT_FILE , out string ? value ) ;
147
+ storage . GetPropertyValue ( name , "" , ToPersistStorageType ( storageType ) , out string ? value ) ;
131
148
return value ;
132
149
}
133
150
134
151
return null ;
135
152
}
136
153
154
+ private static uint ToPersistStorageType ( ProjectStorageType type )
155
+ {
156
+ return ( uint ) ( type switch
157
+ {
158
+ ProjectStorageType . UserFile => _PersistStorageType . PST_USER_FILE ,
159
+ _ => _PersistStorageType . PST_PROJECT_FILE
160
+ } ) ;
161
+ }
162
+
137
163
/// <summary>
138
164
/// Determines whether the project is loaded.
139
165
/// </summary>
@@ -194,4 +220,19 @@ private async Task RefreshAsync(IVsSolution solution, Guid guid)
194
220
Update ( await hierarchy . ToHierarchyItemAsync ( itemId ) ) ;
195
221
}
196
222
}
223
+
224
+ /// <summary>
225
+ /// Defines the type of file that project data is stored in.
226
+ /// </summary>
227
+ public enum ProjectStorageType
228
+ {
229
+ /// <summary>
230
+ /// The <c>.csproj</c> file (or <c>.vbproj</c>, etc.)
231
+ /// </summary>
232
+ ProjectFile ,
233
+ /// <summary>
234
+ /// The <c>.csproj.user</c> file (or <c>.vbproj.user</c>, etc.)
235
+ /// </summary>
236
+ UserFile
237
+ }
197
238
}
0 commit comments