Skip to content

Commit 12721a5

Browse files
committed
删除不使用代码
1 parent e8e8f53 commit 12721a5

1 file changed

Lines changed: 75 additions & 83 deletions

File tree

  • Code/UsingMSBuildCopyOutputFileToFastDebug
Lines changed: 75 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,76 @@
1-
using Microsoft.Build.Framework;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.IO;
5-
using System.Linq;
6-
7-
namespace UsingMSBuildCopyOutputFileToFastDebug
8-
{
9-
class Program
10-
{
11-
static void Main(string[] args)
12-
{
13-
14-
}
15-
}
16-
17-
public class SafeOutputFileCopyTask : Microsoft.Build.Utilities.Task
18-
{
19-
public string[] SourceFiles { set; get; }
20-
public string DestinationFolder { set; get; }
21-
22-
public override bool Execute()
23-
{
24-
if (SourceFiles == null || !SourceFiles.Any())
25-
{
26-
Console.WriteLine("warning: 没有传入需要复制的文件,请给 SourceFiles 赋值需要赋值的文件列表");
27-
return true;
28-
}
29-
30-
var str = new System.Text.StringBuilder();
31-
32-
str.Append("当前传入需要复制的文件\r\n");
33-
foreach (var sourceFile in SourceFiles)
34-
{
35-
str.Append(sourceFile);
36-
str.Append("\r\n"); // AppendLine 干什么去了
37-
}
38-
39-
str.Append("将要复制到的文件夹为");
40-
str.Append(DestinationFolder);
41-
str.Append("\r\n");
42-
43-
Console.WriteLine(str.ToString());
44-
45-
foreach (var sourceFile in SourceFiles.Select(sourceFile => new FileInfo(sourceFile)))
46-
{
47-
var destinationFile = Path.Combine(DestinationFolder, sourceFile.Name);
48-
49-
if (File.Exists(destinationFile))
50-
{
51-
Console.WriteLine("发现需要复制的文件已经存在");
52-
53-
var sourceFileName = Path.GetFileNameWithoutExtension(sourceFile.FullName);
54-
55-
Console.WriteLine("开始移动文件");
56-
57-
for (int i = 0; i < 65535; i++)
58-
{
59-
var newFileName = Path.Combine(DestinationFolder,
60-
$"{sourceFileName}{i + 1}{sourceFile.Extension}.bak");
61-
if (!File.Exists(newFileName))
62-
{
63-
File.Move(destinationFile, newFileName);
64-
Console.WriteLine($"移动文件完成,将{destinationFile}移动到{newFileName}");
65-
break;
66-
}
67-
}
68-
69-
}
70-
71-
Console.WriteLine("开始复制文件 " + destinationFile);
72-
73-
File.Copy(sourceFile.FullName, destinationFile);
74-
75-
Console.WriteLine("完成复制文件 " + destinationFile);
76-
}
77-
78-
Console.WriteLine("全部复制完成");
79-
80-
//Tracer = str.ToString();
81-
return true;
82-
}
83-
}
1+
using Microsoft.Build.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace UsingMSBuildCopyOutputFileToFastDebug
8+
{
9+
public class SafeOutputFileCopyTask : Microsoft.Build.Utilities.Task
10+
{
11+
public string[] SourceFiles { set; get; }
12+
public string DestinationFolder { set; get; }
13+
14+
public override bool Execute()
15+
{
16+
if (SourceFiles == null || !SourceFiles.Any())
17+
{
18+
Console.WriteLine("warning: 没有传入需要复制的文件,请给 SourceFiles 赋值需要赋值的文件列表");
19+
return true;
20+
}
21+
22+
var str = new System.Text.StringBuilder();
23+
24+
str.Append("当前传入需要复制的文件\r\n");
25+
foreach (var sourceFile in SourceFiles)
26+
{
27+
str.Append(sourceFile);
28+
str.Append("\r\n"); // AppendLine 干什么去了
29+
}
30+
31+
str.Append("将要复制到的文件夹为");
32+
str.Append(DestinationFolder);
33+
str.Append("\r\n");
34+
35+
Console.WriteLine(str.ToString());
36+
37+
foreach (var sourceFile in SourceFiles.Select(sourceFile => new FileInfo(sourceFile)))
38+
{
39+
var destinationFile = Path.Combine(DestinationFolder, sourceFile.Name);
40+
41+
if (File.Exists(destinationFile))
42+
{
43+
Console.WriteLine("发现需要复制的文件已经存在");
44+
45+
var sourceFileName = Path.GetFileNameWithoutExtension(sourceFile.FullName);
46+
47+
Console.WriteLine("开始移动文件");
48+
49+
for (int i = 0; i < 65535; i++)
50+
{
51+
var newFileName = Path.Combine(DestinationFolder,
52+
$"{sourceFileName}{i + 1}{sourceFile.Extension}.bak");
53+
if (!File.Exists(newFileName))
54+
{
55+
File.Move(destinationFile, newFileName);
56+
Console.WriteLine($"移动文件完成,将{destinationFile}移动到{newFileName}");
57+
break;
58+
}
59+
}
60+
61+
}
62+
63+
Console.WriteLine("开始复制文件 " + destinationFile);
64+
65+
File.Copy(sourceFile.FullName, destinationFile);
66+
67+
Console.WriteLine("完成复制文件 " + destinationFile);
68+
}
69+
70+
Console.WriteLine("全部复制完成");
71+
72+
//Tracer = str.ToString();
73+
return true;
74+
}
75+
}
8476
}

0 commit comments

Comments
 (0)