【问题标题】:How do I update multiple AssemblyInfo.cs files individually with the Albacore assemblyinfo task?如何使用 Albacore assemblyinfo 任务单独更新多个 AssemblyInfo.cs 文件?
【发布时间】:2011-11-07 19:18:39
【问题描述】:

我有一个包含多个项目的解决方案。我想单独更新每个项目中的AssemblyInfo.cs 文件。文件中的大部分信息都是相同的,但可能有一两件事我想有所不同。我还没有找到使用 Albacore assemblyinfo 任务的方法。

我所追求的语法类型是

# I know this won't work but I would like to be able to call the assemblyinfo 
# task a number of times and each time pass in at least the input_filename
task :update_assemblyinfo_files do
  assemblyinfo '/src/myproj1/properties/assemblyinfo.cs'
  assemblyinfo '/src/myproj2/properties/assemblyinfo.cs'
end

assemblyinfo :assemblyinfo do |asm|
  asm.version = version
  asm.input_file = <an-input-parameter>
end

【问题讨论】:

    标签: .net rake albacore


    【解决方案1】:

    一个想法可以是将常用的 assemblyinfo 参数存储在 rakefile 中的某个位置(或在外部文件中,例如使用 yaml),可以通过方法将其读取到 rake 中,然后按如下方式配置您的任务:

    task :update_assemblyinfo_files => [:update_a, :update_b, :update_c]
    

    然后在每个更新任务中

    assemblyinfo :update_a do |asm|
      common_info = get_common_assemblyinfo()
      asm.version = common_info[:version]
      asm.company_name = common_info[:company_name]
      asm.product_name = common_info[:product_name]
      asm.output_file = "your_file_path"
    end
    
    def get_common_assemblyinfo()
      #read your yaml here and return it
    end
    

    【讨论】:

      【解决方案2】:

      此任务将遍历解决方案中的每个项目并更新每个程序集信息文件。在此示例中,它会更新版本(假设您使用的是 VERSION 文件和 version_bumper)。

      @solutionpath = "c:/mysolution"
      
      desc "Updates each assembly version"
      task :version do |asm|
        FileList["#{@solutionpath}**/Properties/AssemblyInfo.cs"].each { |assemblyfile|   
          asm = AssemblyInfo.new()
          asm.use(assemblyfile)
          asm.version = bumper_version.to_s
          asm.file_version = bumper_version.to_s
          asm.execute
        }
      end
      

      【讨论】:

        【解决方案3】:

        让我们一次解决这个问题。如果您有多个 AssemblyInfo.cs 文件,您可以创建一个 FileList 来捕获所有文件。

        assembly_info_files = FileList['./source/**/AssemblyInfo.cs']
        

        并为每个文件动态创建一个assemblyinfo 任务。

        assembly_info_files.each do |file|
          assemblyinfo file do |asm|
            asm.input_file = file
            asm.version = version
          end
        end
        

        但是,我认为您是说 每个文件 可能有不同的参数。我建议您在单个文件中静态编码尽可能多的这些属性。您将需要某种文件的哈希值 => { name => value }。

        如果你总是覆盖相同的属性“property_A”和“property_B”

        assembly_info_properties = {
          './source/ProjectA/AssemblyInfo.cs' => { 
            :copyright => '2011'
            :version => '1.0.0'
          },
        
          './source/ProjectB/AssemblyInfo.cs' => {
            :copyright => '2012'
            :version => '0.1.0'
          }
        }
        
        assembly_info_properties.each do |file,properties|
          assmeblyinfo file do |asm|
            asm.input_file = file
            asm.copyright = properties[:copyright]
            asm.version = properties[:version]
          end
        end
        

        如果您覆盖不同的属性集,请使用散列的散列并使用一般的custom_attributes

        assembly_info_properties = {
          './source/ProjectA/AssemblyInfo.cs' => { 
            :Copyright => 'Someone Else (c) 2011'
          },
        
          './source/ProjectB/AssemblyInfo.cs' => {
            :Title => 'Custom Title'
          }
        }
        
        assembly_info_properties.each do |file,properties|
          assmeblyinfo file do |asm|
            asm.input_file = file
            asm.custom_attributes properties
          end
        end
        

        【讨论】:

          猜你喜欢
          • 2010-09-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-06-23
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多