1<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 2 <UsingTask 3 TaskName="HeaderFromHexdump" 4 TaskFactory="CodeTaskFactory" 5 AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" > 6 <ParameterGroup> 7 <RawFilePath Required="true" /> 8 <HeaderFilePath Required="true" /> 9 <SourceHeader Required="true" /> 10 <SourceFooter Required="true" /> 11 </ParameterGroup> 12 <Task> 13 <Using Namespace="System"/> 14 <Using Namespace="System.IO"/> 15 <Code Type="Fragment" Language="cs"> 16<![CDATA[ 17Log.LogMessage("msbuild inline hexdump task for " + RawFilePath + "."); 18if(File.Exists(RawFilePath) == false) { 19 Log.LogError("hexdump task could not locate " + RawFilePath + "."); 20} 21else { 22 FileInfo inFileInfo = new FileInfo(RawFilePath); 23 FileInfo outFileInfo = new FileInfo(HeaderFilePath); 24 25 if (outFileInfo.Exists == false || inFileInfo.LastWriteTime > outFileInfo.LastWriteTime) 26 { 27 using (Stream inStm = File.OpenRead(RawFilePath)) 28 { 29 using (StreamWriter sw = new StreamWriter(HeaderFilePath)) 30 { 31 sw.WriteLine(SourceHeader); 32 int count = 0; 33 int rawChar = inStm.ReadByte(); 34 while(rawChar != -1) 35 { 36 sw.Write("0x{0:x2}, ", rawChar); 37 count++; 38 if(count % 8 == 0) 39 { 40 sw.WriteLine(); 41 } 42 rawChar = inStm.ReadByte(); 43 } 44 sw.WriteLine(SourceFooter); 45 } 46 } 47 } 48} 49]]> 50 </Code> 51 </Task> 52 </UsingTask> 53</Project>