How do I update multiple AssemblyInfo.cs files individually with the Albacore assemblyinfo task?

StackOverflow https://stackoverflow.com/questions/8041392

  •  23-02-2021
  •  | 
  •  

Question

I have a solution with a number of projects. I would like to update the AssemblyInfo.cs file in each project individually. Most of the info in the files will be the same, but there may be one or two things that I want to be different. I haven't been able to figure out a way to do this with the Albacore assemblyinfo task.

The type of syntax I am after would be

# 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
Was it helpful?

Solution

An idea can be to store your common assemblyinfo params somewhere in your rakefile (or in an external file, using yaml for example) that can be read by a method into rake and then configure your task as follows:

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

and then in each update task

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

OTHER TIPS

This task will iterate through each project in your solution and update each assembly info file. In this example it updates the version (assuming you are using a VERSION file and 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

Let's tackle this one bit at a time. If you have multiple AssemblyInfo.cs files, you could create a FileList that captures them all.

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

And create an assemblyinfo task per file dynamically.

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

But, I think you're saying that you might have different parameters per file. I recommend you encode as many of those properties statically in the individual files. You'll need some kind of hash of hashes of files => { name => value }.

If you always override the same properties "property_A" and "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

If you override different sets of properties, use the hash of hashes and use the general 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top