Skip to content

Commit f7a8e0e

Browse files
committed
清理文件
1 parent 7d69bf4 commit f7a8e0e

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

Code/UsingMSBuildCopyOutputFileToFastDebug/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
3838
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
3939
</ItemGroup>
40-
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(MainProjectPath)"
40+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)"
41+
DestinationFolder="$(MainProjectPath)"
42+
CleanFile="$(IntermediateOutputPath)$(CleanFile)"
4143
Condition="$(MainProjectPath)!=''"></SafeOutputFileCopyTask>
4244

43-
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(LaunchMainProjectPath)"
45+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)"
46+
DestinationFolder="$(LaunchMainProjectPath)"
47+
CleanFile="$(IntermediateOutputPath)$(CleanFile)"
4448
Condition="$(LaunchMainProjectPath)!='' and $(MainProjectPath)==''"></SafeOutputFileCopyTask>
4549
</Target>
4650
</Project>

Code/UsingMSBuildCopyOutputFileToFastDebug/SafeOutputFileCopyTask.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public class SafeOutputFileCopyTask : Microsoft.Build.Utilities.Task
1111
public string[] SourceFiles { set; get; }
1212
public string DestinationFolder { set; get; }
1313

14+
/// <summary>
15+
/// 用于清理文件
16+
/// </summary>
17+
public string CleanFile { set; get; }
18+
1419
public override bool Execute()
1520
{
1621
if (SourceFiles == null || !SourceFiles.Any())
@@ -54,6 +59,7 @@ public override bool Execute()
5459
{
5560
File.Move(destinationFile, newFileName);
5661
Console.WriteLine($"移动文件完成,将{destinationFile}移动到{newFileName}");
62+
AddToClean(newFileName);
5763
break;
5864
}
5965
}
@@ -72,5 +78,22 @@ public override bool Execute()
7278
//Tracer = str.ToString();
7379
return true;
7480
}
81+
82+
private void AddToClean(string newFileName)
83+
{
84+
// 加入到清理文件
85+
86+
for (int i = 0; i < 10; i++)
87+
{
88+
try
89+
{
90+
File.AppendAllLines(CleanFile, new[] { newFileName });
91+
}
92+
catch (Exception)
93+
{
94+
// 忽略
95+
}
96+
}
97+
}
7598
}
7699
}

0 commit comments

Comments
 (0)