看看FileSystemWatcher类。它监视对文件甚至文件夹的更改。
看看这个例子:
using System; 使用System.IO; using System.Security.Permissions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Run(@"C:\Users\Hanlet\Desktop\Watcher\ConsoleApplication1\bin\Debug");
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path =path;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "*.xml";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
if(e.FullPath.IndexOf("resource.xml") > - 1)
Console.WriteLine("The file was: " + e.ChangeType);
}
}
}
这种显示器和卡子每次所述resource.xml文件遭受某种变化(创建,删除或更新)。祝你好运!
这是你贴在这里另外一个问题重复http://stackoverflow.com/questions/14997308/how-can-set-the-custom- tool-property-of-an-xml-file-to-a-t4-file/15037150#15037150 – 2013-02-23 04:48:07