Skip to content

Commit 93d5668

Browse files
authored
Merge pull request #1 from dotnet-campus/t/lindexi
复制的时候如果存在相同名的文件就移动
2 parents 7b08bbd + e8e8f53 commit 93d5668

8 files changed

Lines changed: 401 additions & 10 deletions

.gitignore

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
.vs
9+
.idea
10+
11+
# Build results
12+
[Dd]ebug/
13+
[Dd]ebugPublic/
14+
[Rr]elease/
15+
[Rr]eleases/
16+
x64/
17+
x86/
18+
bld/
19+
[Bb]in/
20+
[Oo]bj/
21+
22+
# Roslyn cache directories
23+
*.ide/
24+
25+
# MSTest test Results
26+
[Tt]est[Rr]esult*/
27+
[Bb]uild[Ll]og.*
28+
29+
#NUNIT
30+
*.VisualState.xml
31+
TestResult.xml
32+
33+
# Build Results of an ATL Project
34+
[Dd]ebugPS/
35+
[Rr]eleasePS/
36+
dlldata.c
37+
38+
*_i.c
39+
*_p.c
40+
*_i.h
41+
*.ilk
42+
*.meta
43+
*.obj
44+
*.pch
45+
*.pdb
46+
*.pgc
47+
*.pgd
48+
*.rsp
49+
*.sbr
50+
*.tlb
51+
*.tli
52+
*.tlh
53+
*.tmp
54+
*.tmp_proj
55+
*.log
56+
*.vspscc
57+
*.vssscc
58+
.builds
59+
*.pidb
60+
*.svclog
61+
*.scc
62+
63+
# Chutzpah Test files
64+
_Chutzpah*
65+
66+
# Visual C++ cache files
67+
ipch/
68+
*.aps
69+
*.ncb
70+
*.opensdf
71+
*.sdf
72+
*.cachefile
73+
74+
# Visual Studio profiler
75+
*.psess
76+
*.vsp
77+
*.vspx
78+
79+
# TFS 2012 Local Workspace
80+
$tf/
81+
82+
# Guidance Automation Toolkit
83+
*.gpState
84+
85+
# ReSharper is a .NET coding add-in
86+
_ReSharper*/
87+
*.[Rr]e[Ss]harper
88+
*.DotSettings.user
89+
90+
# JustCode is a .NET coding addin-in
91+
.JustCode
92+
93+
# TeamCity is a build add-in
94+
_TeamCity*
95+
96+
# DotCover is a Code Coverage Tool
97+
*.dotCover
98+
99+
# NCrunch
100+
_NCrunch_*
101+
.*crunch*.local.xml
102+
103+
# MightyMoose
104+
*.mm.*
105+
AutoTest.Net/
106+
107+
# Web workbench (sass)
108+
.sass-cache/
109+
110+
# Installshield output folder
111+
[Ee]xpress/
112+
113+
# DocProject is a documentation generator add-in
114+
DocProject/buildhelp/
115+
DocProject/Help/*.HxT
116+
DocProject/Help/*.HxC
117+
DocProject/Help/*.hhc
118+
DocProject/Help/*.hhk
119+
DocProject/Help/*.hhp
120+
DocProject/Help/Html2
121+
DocProject/Help/html
122+
123+
# Click-Once directory
124+
publish/
125+
126+
# Publish Web Output
127+
*.[Pp]ublish.xml
128+
*.azurePubxml
129+
# TODO: Comment the next line if you want to checkin your web deploy settings
130+
# but database connection strings (with potential passwords) will be unencrypted
131+
*.pubxml
132+
*.publishproj
133+
134+
# NuGet Packages
135+
*.nupkg
136+
# The packages folder can be ignored because of Package Restore
137+
**/packages/*
138+
# except build/, which is used as an MSBuild target.
139+
!**/packages/build/
140+
# If using the old MSBuild-Integrated Package Restore, uncomment this:
141+
#!**/packages/repositories.config
142+
143+
# Windows Azure Build Output
144+
csx/
145+
*.build.csdef
146+
147+
# Windows Store app package directory
148+
AppPackages/
149+
150+
# Others
151+
sql/
152+
*.Cache
153+
ClientBin/
154+
[Ss]tyle[Cc]op.*
155+
~$*
156+
*~
157+
*.dbmdl
158+
*.dbproj.schemaview
159+
*.pfx
160+
*.publishsettings
161+
node_modules/
162+
163+
# RIA/Silverlight projects
164+
Generated_Code/
165+
166+
# Backup & report files from converting an old project file
167+
# to a newer Visual Studio version. Backup files are not needed,
168+
# because we have git ;-)
169+
_UpgradeReport_Files/
170+
Backup*/
171+
UpgradeLog*.XML
172+
UpgradeLog*.htm
173+
174+
# SQL Server files
175+
*.mdf
176+
*.ldf
177+
178+
# Business Intelligence projects
179+
*.rdl.data
180+
*.bim.layout
181+
*.bim_*.settings
182+
183+
# Microsoft Fakes
184+
FakesAssemblies/
185+
186+
# =========================
187+
# Operating System Files
188+
# =========================
189+
190+
# OSX
191+
# =========================
192+
193+
.DS_Store
194+
.AppleDouble
195+
.LSOverride
196+
197+
# Icon must end with two \r
198+
Icon
199+
200+
201+
# Thumbnails
202+
._*
203+
204+
# Files that might appear on external disk
205+
.Spotlight-V100
206+
.Trashes
207+
208+
# Directories potentially created on remote AFP share
209+
.AppleDB
210+
.AppleDesktop
211+
Network Trash Folder
212+
Temporary Items
213+
.apdisk
214+
215+
# Windows
216+
# =========================
217+
218+
# Windows image file caches
219+
Thumbs.db
220+
ehthumbs.db
221+
222+
# Folder config file
223+
Desktop.ini
224+
225+
# Recycle Bin used on file shares
226+
$RECYCLE.BIN/
227+
228+
# Windows Installer files
229+
*.cab
230+
*.msi
231+
*.msm
232+
*.msp
233+
234+
# VS 编译中间文件
235+
*_wpftmp.csproj
236+
**/SourceProject/*.Source.SourceProject.props

Code/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project>
2+
<PropertyGroup>
3+
<!-- 我们使用 $(MSBuildRuntimeType) 来判断编译器是 .NET Core 的还是 .NET Framework 的。
4+
然后选用对应的文件夹。-->
5+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.2\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
6+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net48\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
7+
</PropertyGroup>
8+
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.SafeOutputFileCopyTask"
9+
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
10+
11+
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
12+
Condition="$(MainProjectPath)!=''">
13+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
14+
<ItemGroup>
15+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
16+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
17+
</ItemGroup>
18+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(MainProjectPath)"></SafeOutputFileCopyTask>
19+
</Target>
20+
</Project>

Code/BuildMultiTargeting/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets renamed to Code/UsingMSBuildCopyOutputFileToFastDebug/BuildMultiTargeting/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets

File renamed without changes.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
}
84+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFrameworks>net48;netcoreapp2.2</TargetFrameworks>
6+
<Authors>dotnet-campus</Authors>
7+
<Product>dotnet-campus</Product>
8+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9+
<PackageProjectUrl>https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug</PackageProjectUrl>
10+
<RepositoryUrl>https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug</RepositoryUrl>
11+
<Description>
12+
Using MSBuild Copy Output File To Fast Debug
13+
通过复制输出文件让 VisualStudio 外部启动快速调试底层库
14+
</Description>
15+
<Copyright>Copyright (c) 2019 dotnet-campus</Copyright>
16+
<PackageTags>msbuild debug</PackageTags>
17+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
18+
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
19+
<NoPackageAnalysis>true</NoPackageAnalysis>
20+
<ApplicationIcon />
21+
<StartupObject />
22+
<Version>1.3.1</Version>
23+
<PackageId>dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug</PackageId>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<PackageReference Include="Microsoft.Build.Framework" Version="16.0.461" />
28+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />
29+
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<None Include="build\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\build"/>
34+
<None Include="buildMultiTargeting\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\buildMultiTargeting"/>
35+
</ItemGroup>
36+
</Project>

Code/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.nuspec renamed to Code/UsingMSBuildCopyOutputFileToFastDebug/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.nuspec

File renamed without changes.

0 commit comments

Comments
 (0)