Created
November 20, 2020 20:00
-
-
Save adalon/6f1ee743b9a9221abae9bfa6b026ee2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static string sourceDir; | |
static string targetDir; | |
static string[] fileExtensions = new[] { ".dll", ".pdb" }; | |
static void Main(string[] args) | |
{ | |
sourceDir = Path.GetFullPath(args.Length == 1 ? args[0] : @"c:\code\bin\Debug.AnyCPU\VSIntegration.Client") + Path.DirectorySeparatorChar; | |
targetDir = Path.GetFullPath(args.Length == 2 ? args[1] : @"c:\Program Files (x86)\Microsoft Visual Studio\2019\main\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer") + Path.DirectorySeparatorChar; | |
var watcher = new FileSystemWatcher(sourceDir); | |
watcher.Created += Watcher_Changed; | |
watcher.Changed += Watcher_Changed; | |
watcher.IncludeSubdirectories = true; | |
watcher.EnableRaisingEvents = true; | |
while (true) Console.ReadKey(); | |
} | |
private static void Watcher_Changed(object sender, FileSystemEventArgs e) | |
{ | |
try | |
{ | |
if (File.Exists(e.FullPath) && fileExtensions.Contains(Path.GetExtension(e.FullPath).ToLowerInvariant())) | |
{ | |
var targetFile = Path.Combine(targetDir, e.FullPath.Replace(sourceDir, string.Empty)); | |
if (!Directory.Exists(Path.GetDirectoryName(targetFile))) | |
Directory.CreateDirectory(Path.GetDirectoryName(targetFile)); | |
if (!File.Exists(targetFile) || File.GetLastWriteTime(targetFile) < File.GetLastWriteTime(e.FullPath)) | |
{ | |
Console.WriteLine($"Copying {e.FullPath} to {targetFile}..."); | |
File.Copy(e.FullPath, targetFile, true); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment