@@ -33,16 +33,13 @@ static int Main(string[] args)
3333
3434 try
3535 {
36- return CommandLine . Parse ( args ) . AddHandler < CleanOptions > ( c =>
37- {
38- Logger . Message ( $ "Enter CleanOptions") ;
39- } )
40- . AddHandler < CopyOutputFileOptions > ( c =>
41- {
42- Logger . Message ( $ "Enter CopyOutputFileOptions") ;
43- CopyOutputFile ( c ) ;
44- } )
45- . Run ( ) ;
36+ return CommandLine . Parse ( args ) . AddHandler < CleanOptions > ( c => { Logger . Message ( $ "Enter CleanOptions") ; } )
37+ . AddHandler < CopyOutputFileOptions > ( c =>
38+ {
39+ Logger . Message ( $ "Enter CopyOutputFileOptions") ;
40+ CopyOutputFile ( c ) ;
41+ } )
42+ . Run ( ) ;
4643 }
4744 catch ( Exception e )
4845 {
@@ -53,14 +50,21 @@ static int Main(string[] args)
5350
5451 private static void CopyOutputFile ( CopyOutputFileOptions copyOutputFileOptions )
5552 {
56- var targetFolder = GetTargetFolder ( copyOutputFileOptions ) ;
57- if ( TargetFrameworkChecker . CheckCanCopy ( targetFolder , copyOutputFileOptions ) is false )
53+ var destinationFolder = GetDestinationFolder ( copyOutputFileOptions ) ;
54+ if ( TargetFrameworkChecker . CheckCanCopy ( destinationFolder , copyOutputFileOptions ) is false )
5855 {
5956 // 如果当前的框架是兼容的,那就进行拷贝,否则不做任何拷贝逻辑
6057 return ;
6158 }
6259
6360 var outputFileList = GetOutputFileList ( copyOutputFileOptions . OutputFileToCopyList ) ;
61+ var safeOutputFileCopyTask = new SafeOutputFileCopyTask ( )
62+ {
63+ DestinationFolder = destinationFolder . FullName ,
64+ CleanFile = copyOutputFileOptions . CleanFilePath ,
65+ SourceFiles = outputFileList . Select ( t => t . FullName ) . ToArray ( )
66+ } ;
67+ safeOutputFileCopyTask . Execute ( ) ;
6468 }
6569
6670 private static List < FileInfo > GetOutputFileList ( string outputFileToCopyList )
@@ -80,7 +84,7 @@ private static List<FileInfo> GetOutputFileList(string outputFileToCopyList)
8084 /// </summary>
8185 /// <param name="copyOutputFileOptions"></param>
8286 /// <returns></returns>
83- private static DirectoryInfo GetTargetFolder ( CopyOutputFileOptions copyOutputFileOptions )
87+ private static DirectoryInfo GetDestinationFolder ( CopyOutputFileOptions copyOutputFileOptions )
8488 {
8589 var mainProjectPath = copyOutputFileOptions . MainProjectPath ;
8690 // 如果用户有设置此文件夹,那就期望是输出到此文件夹
@@ -94,6 +98,7 @@ private static DirectoryInfo GetTargetFolder(CopyOutputFileOptions copyOutputFil
9498
9599 return new DirectoryInfo ( mainProjectPath ) ;
96100 }
101+
97102 // 尝试去读取 LaunchSettings 文件
98103 var launchSettingsParser = new LaunchSettingsParser ( ) ;
99104 if ( launchSettingsParser . Execute ( ) )
@@ -118,31 +123,25 @@ public static class TargetFrameworkChecker
118123 {
119124 public static bool CheckCanCopy ( DirectoryInfo targetFolder , CopyOutputFileOptions copyOutputFileOptions )
120125 {
121-
122126 return true ;
123127 }
124128 }
125129
126130 [ Verb ( "CopyOutputFile" ) ]
127131 public class CopyOutputFileOptions
128132 {
129- [ Option ( "MainProjectPath" ) ]
130- public string MainProjectPath { set ; get ; } = null ! ;
133+ [ Option ( "MainProjectPath" ) ] public string MainProjectPath { set ; get ; } = null ! ;
131134
132- [ Option ( "CleanFilePath" ) ]
133- public string CleanFilePath { set ; get ; }
135+ [ Option ( "CleanFilePath" ) ] public string CleanFilePath { set ; get ; }
134136
135- [ Option ( "OutputFileToCopyList" ) ]
136- public string OutputFileToCopyList { set ; get ; }
137+ [ Option ( "OutputFileToCopyList" ) ] public string OutputFileToCopyList { set ; get ; }
137138
138- [ Option ( "TargetFramework" ) ]
139- public string TargetFramework { set ; get ; }
139+ [ Option ( "TargetFramework" ) ] public string TargetFramework { set ; get ; }
140140 }
141141
142142 [ Verb ( "Clean" ) ]
143143 public class CleanOptions
144144 {
145- [ Option ( "CleanFilePath" ) ]
146- public string CleanFilePath { set ; get ; }
145+ [ Option ( "CleanFilePath" ) ] public string CleanFilePath { set ; get ; }
147146 }
148147}
0 commit comments