@@ -18,17 +18,17 @@ private static int Main(string[] args)
1818 {
1919 if ( args . Length < 1 )
2020 {
21- Console . WriteLine ( "CodeFormatter <solution> [<rule types>] [/file <filename>]" ) ;
21+ Console . WriteLine ( "CodeFormatter <project or solution> [<rule types>] [/file <filename>]" ) ;
2222 Console . WriteLine ( " <rule types> - Rule types to use in addition to the default ones." ) ;
2323 Console . WriteLine ( " Use ConvertTests to convert MSTest tests to xUnit." ) ;
2424 Console . WriteLine ( " <filename> - Only apply changes to files with specified name." ) ;
2525 return - 1 ;
2626 }
2727
28- var solutionPath = args [ 0 ] ;
29- if ( ! File . Exists ( solutionPath ) )
28+ var projectOrSolutionPath = args [ 0 ] ;
29+ if ( ! File . Exists ( projectOrSolutionPath ) )
3030 {
31- Console . Error . WriteLine ( "Solution {0} doesn't exist." , solutionPath ) ;
31+ Console . Error . WriteLine ( "Project or solution {0} doesn't exist." , projectOrSolutionPath ) ;
3232 return - 1 ;
3333 }
3434
@@ -59,15 +59,24 @@ private static int Main(string[] args)
5959
6060 Console . CancelKeyPress += delegate { cts . Cancel ( ) ; } ;
6161
62- RunAsync ( solutionPath , ruleTypes , filenames , ct ) . Wait ( ct ) ;
62+ RunAsync ( projectOrSolutionPath , ruleTypes , filenames , ct ) . Wait ( ct ) ;
6363 Console . WriteLine ( "Completed formatting." ) ;
6464 return 0 ;
6565 }
6666
67- private static async Task RunAsync ( string solutionFilePath , IEnumerable < string > ruleTypes , IEnumerable < string > filenames , CancellationToken cancellationToken )
67+ private static async Task RunAsync ( string projectOrSolutionPath , IEnumerable < string > ruleTypes , IEnumerable < string > filenames , CancellationToken cancellationToken )
6868 {
6969 var workspace = MSBuildWorkspace . Create ( ) ;
70- await workspace . OpenSolutionAsync ( solutionFilePath , cancellationToken ) ;
70+
71+ string extension = Path . GetExtension ( projectOrSolutionPath ) ;
72+ if ( StringComparer . OrdinalIgnoreCase . Equals ( extension , ".sln" ) )
73+ {
74+ await workspace . OpenSolutionAsync ( projectOrSolutionPath , cancellationToken ) ;
75+ }
76+ else
77+ {
78+ await workspace . OpenProjectAsync ( projectOrSolutionPath , cancellationToken ) ;
79+ }
7180
7281 var engine = FormattingEngine . Create ( ruleTypes , filenames ) ;
7382 await engine . RunAsync ( workspace , cancellationToken ) ;
0 commit comments