Passing Items to MSBuild Task

后端 未结 1 1490
悲&欢浪女
悲&欢浪女 2020-12-19 14:35

I would like to use the \"MSBuild\" task in my target in order to build another project, while passing some items (with their metadata) from the current project to the proje

1条回答
  •  -上瘾入骨i
    2020-12-19 15:23

    It is fairly straightforward to write a custom task to dump items and their metadata to a file, to be picked up by another process. Instead of just dumping the items in raw text form though, generate a valid MSBuild project file containing the item group (with item meta data) and have that generated file imported by the project being executed by the MSBuild task. You can even use an MSBuild 4.0 inline task to dump the file.

    (response to comment)

    
      
        
        
      
      
        
        
      ");
        writer.WriteLine("");
        writer.WriteLine("  ");
    
        foreach (var item in Items)
        {
          string meta1 = item.GetMetadata("Meta1");
          string meta2 = item.GetMetadata("Meta2");
          writer.WriteLine("    ", item.ItemSpec);
          writer.WriteLine("      {0}", meta1);
          writer.WriteLine("      {0}", meta2);
          writer.WriteLine("    ");
        }
        writer.WriteLine("  ");    
        writer.WriteLine("");    
      }
      ]]>
        
      
    
    
    
      
        A1
        A2
      
      
        B1
        B2
      
    
    
      
      
    
    

    0 讨论(0)
提交回复
热议问题