This repository was archived by the owner on Jul 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1
- using System ;
1
+ using Microsoft . CodeAnalysis . MSBuild ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Text ;
6
+ using System . Threading ;
5
7
using System . Threading . Tasks ;
6
8
7
9
namespace XUnitConverter
@@ -10,7 +12,38 @@ internal static class Program
10
12
{
11
13
internal static void Main ( string [ ] args )
12
14
{
15
+ if ( args . Length != 1 )
16
+ {
17
+ Console . WriteLine ( "xunitconverter <project>" ) ;
18
+ return ;
19
+ }
13
20
21
+ var cts = new CancellationTokenSource ( ) ;
22
+ Console . CancelKeyPress += delegate { cts . Cancel ( ) ; } ;
23
+ RunAsync ( args [ 0 ] , cts . Token ) . Wait ( ) ;
24
+ }
25
+
26
+ private static async Task RunAsync ( string projectPath , CancellationToken cancellationToken )
27
+ {
28
+ var workspace = MSBuildWorkspace . Create ( ) ;
29
+ workspace . LoadMetadataForReferencedProjects = true ;
30
+
31
+ var project = await workspace . OpenProjectAsync ( projectPath , cancellationToken ) ;
32
+ var solution = project . Solution ;
33
+ var xunitConverter = new XUnitConverter ( ) ;
34
+ foreach ( var id in project . DocumentIds )
35
+ {
36
+ var document = solution . GetDocument ( id ) ;
37
+ var syntaxNode = await document . GetSyntaxRootAsync ( cancellationToken ) ;
38
+ if ( syntaxNode == null )
39
+ {
40
+ continue ;
41
+ }
42
+
43
+ solution = await xunitConverter . ProcessAsync ( document , syntaxNode , cancellationToken ) ;
44
+ }
45
+
46
+ workspace . TryApplyChanges ( solution ) ;
14
47
}
15
48
}
16
49
}
Original file line number Diff line number Diff line change 15
15
using System . Runtime . Serialization ;
16
16
using System . IO ;
17
17
18
- namespace Microsoft . DotNet . CodeFormatting . Rules
18
+ namespace XUnitConverter
19
19
{
20
20
internal sealed class XUnitConverter
21
21
{
You can’t perform that action at this time.
0 commit comments