11using System ;
22using System . Collections . Generic ;
3- using System . Collections . Immutable ;
43using System . ComponentModel . DataAnnotations ;
54using System . Diagnostics ;
6- using System . IO ;
75using System . Linq ;
86using System . Runtime . CompilerServices ;
97using System . Text ;
108using System . Threading ;
119using System . Threading . Tasks ;
12- using ICSharpCode . CodeConverter ;
1310using ICSharpCode . CodeConverter . Common ;
1411using ICSharpCode . CodeConverter . CSharp ;
1512using ICSharpCode . CodeConverter . Util ;
1613using ICSharpCode . CodeConverter . VB ;
1714using Microsoft . CodeAnalysis ;
18- using Microsoft . CodeAnalysis . Diagnostics ;
1915using Microsoft . CodeAnalysis . MSBuild ;
2016using Microsoft . VisualStudio . Threading ;
2117
@@ -26,27 +22,26 @@ namespace ICSharpCode.CodeConverter.CommandLine;
2622/// </summary>
2723public sealed class MsBuildWorkspaceConverter
2824{
25+ private readonly JoinableTaskFactory _joinableTaskFactory ;
2926 private readonly SolutionLoader _solutionLoader ;
3027 private AsyncLazy < Solution > ? _cachedSolution ;
3128
3229 // The other parameters are ignored for compatibility
33- public MsBuildWorkspaceConverter ( string solutionFilePath , bool bestEffortConversion = false , Dictionary < string , string > ? buildProps = null )
30+ public MsBuildWorkspaceConverter ( JoinableTaskFactory joinableTaskFactory , string solutionFilePath , bool bestEffortConversion = false , Dictionary < string , string > ? buildProps = null )
3431 {
32+ _joinableTaskFactory = joinableTaskFactory ;
3533 _solutionLoader = new SolutionLoader ( solutionFilePath , bestEffortConversion , buildProps ) ;
3634 }
3735
3836
3937 public async IAsyncEnumerable < ConversionResult > ConvertProjectsWhereAsync ( Func < Project , bool > shouldConvertProject , Language ? targetLanguage , IProgress < ConversionProgress > progress , [ EnumeratorCancellation ] CancellationToken token )
4038 {
4139 var strProgress = new Progress < string > ( s => progress . Report ( new ConversionProgress ( s ) ) ) ;
42- #pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed - Shouldn't need main thread, and I can't access ThreadHelper without referencing VS shell.
43- _cachedSolution ??= new AsyncLazy < Solution > ( async ( ) => await _solutionLoader . AnalyzeSolutionAsync ( strProgress ) ) ;
44- #pragma warning restore VSTHRD012 // Provide JoinableTaskFactory where allowed
40+ _cachedSolution ??= new AsyncLazy < Solution > ( async ( ) => await _solutionLoader . AnalyzeSolutionAsync ( strProgress ) , _joinableTaskFactory ) ;
41+
4542 var solution = await _cachedSolution . GetValueAsync ( token ) ;
4643
47- if ( ! targetLanguage . HasValue ) {
48- targetLanguage = solution . Projects . Any ( p => p . Language == LanguageNames . VisualBasic ) ? Language . CS : Language . VB ;
49- }
44+ targetLanguage ??= solution . Projects . Any ( p => p . Language == LanguageNames . VisualBasic ) ? Language . CS : Language . VB ;
5045
5146 var languageConversion = targetLanguage == Language . CS
5247 ? ( ILanguageConversion ) new VBToCSConversion ( )
@@ -89,17 +84,8 @@ public async Task<Solution> AnalyzeSolutionAsync(IProgress<string> progress, str
8984 } ;
9085
9186 using var workspace = MSBuildWorkspace . Create ( properties ) ;
92- workspace . WorkspaceFailed += HandleWorkspaceFailure ;
9387
94- Solution solution ;
95- try
96- {
97- solution = await workspace . OpenSolutionAsync ( _solutionFilePath ) ;
98- }
99- finally
100- {
101- workspace . WorkspaceFailed -= HandleWorkspaceFailure ;
102- }
88+ Solution solution = await workspace . OpenSolutionAsync ( _solutionFilePath ) ;
10389
10490 var errorString = await GetCompilationErrorsAsync ( workspace , solution . Projects ) ;
10591 if ( string . IsNullOrEmpty ( errorString ) ) return solution ;
0 commit comments