@@ -77,7 +77,7 @@ private static IVsOutputWindowPane CreateCustomPane()
77
77
string customTitle = "CodegenCS Template" ;
78
78
outWindow . CreatePane ( ref codegenCSOutputPane , customTitle , 1 , 1 ) ;
79
79
IVsOutputWindowPane customPane ;
80
- outWindow . GetPane ( ref codegenCSOutputPane , out customPane ) ;
80
+ outWindow . GetPane ( ref codegenCSOutputPane , out customPane ) ;
81
81
return customPane ;
82
82
}
83
83
@@ -156,7 +156,7 @@ public async Task RunAsync()
156
156
void ClearPreviousErrors ( ErrorListProvider errorListProvider )
157
157
{
158
158
// For VS2022 edition (libraries version >=17.x) the tasks (even ErrorTask) all inherit from Microsoft.VisualStudio.Shell.TaskListItem
159
- foreach ( var task in errorListProvider . Tasks . OfType < TaskListItem > ( ) )
159
+ foreach ( var task in errorListProvider . Tasks . OfType < TaskListItem > ( ) . ToList ( ) )
160
160
{
161
161
if ( task . Document == _templateItemPath || ! File . Exists ( task . Document ) )
162
162
errorListProvider . Tasks . Remove ( task ) ;
@@ -350,15 +350,42 @@ async Task AddFilesToSolutionAsync(string outputFolder, ProjectItem parentItem)
350
350
outputItem = parentItem . ProjectItems . AddFromFile ( fullPath ) ;
351
351
await Task . Delay ( 1 ) ; // let UI refresh
352
352
}
353
- if ( outputItem . Properties . Item ( "DependentUpon" ) . Value . ToString ( ) != parentItem . Name )
354
- outputItem . Properties . Item ( "DependentUpon" ) . Value = parentItem . Name ; // TODO: check if DependentUpon works for old non-sdk-style. If needed check https://github.com/madskristensen/FileNesting
355
- if ( outputItem . Properties . Item ( "ItemType" ) . Value . ToString ( ) != o . FileType . ToString ( ) )
356
- outputItem . Properties . Item ( "ItemType" ) . Value = o . FileType . ToString ( ) ;
353
+ if ( await ContainsPropertyAsync ( outputItem , "DependentUpon" ) && outputItem . Properties . Item ( "DependentUpon" ) . Value . ToString ( ) != parentItem . Name )
354
+ await SetItemPropertyAsync ( outputItem , "DependentUpon" , parentItem . Name ) ; // for non-sdk projects this property doesn't exist but the item is just nested automatically?!
355
+ if ( await ContainsPropertyAsync ( outputItem , "ItemType" ) && outputItem . Properties . Item ( "ItemType" ) . Value . ToString ( ) != o . FileType . ToString ( ) )
356
+ await SetItemPropertyAsync ( outputItem , "ItemType" , o . FileType . ToString ( ) ) ;
357
357
break ;
358
358
}
359
359
}
360
360
}
361
361
362
+ public static async Task < bool > ContainsPropertyAsync ( ProjectItem projectItem , string propertyName )
363
+ {
364
+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
365
+ if ( projectItem . Properties != null )
366
+ {
367
+ foreach ( Property item in projectItem . Properties )
368
+ {
369
+ if ( item != null && item . Name == propertyName )
370
+ return true ;
371
+ }
372
+ }
373
+ return false ;
374
+ }
375
+
376
+ private static async Task < bool > SetItemPropertyAsync ( ProjectItem item , string propertyName , string value )
377
+ {
378
+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
379
+ if ( await ContainsPropertyAsync ( item , propertyName ) )
380
+ {
381
+ item . Properties . Item ( propertyName ) . Value = value ;
382
+ return true ;
383
+ }
384
+
385
+ return false ;
386
+ }
387
+
388
+
362
389
void AddError ( string errorMessage , TaskCategory category , int line , int column )
363
390
{
364
391
#if VS2022_OR_NEWER
0 commit comments