Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 898703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:05:25+00:00 2026-05-15T15:05:25+00:00

I’m using a rake script to tag the AssemblyInfo.cs files in my .NET projects,

  • 0

I’m using a rake script to tag the AssemblyInfo.cs files in my .NET projects, but there’s a phantom carriage return (or newline, etc.) being introduced that’s breaking the compilation. The method that gets the version number is:

def get_version()
  version = ''
  IO.popen("#{SVNVERSION_APPLICATION} #{build_info.root_dir}") do |output|
    output.readlines.each do |line|
      version << line.gsub(/\:.*/, '')
    end
  end
  result = version
end

If there’s a better way to do that, please let me know. I’m mostly tinkering here (and this is actually the first Ruby I’ve ever worked on, so bear with me). As you can see (and my regex skills have never really been ninja-level) I’m just trying to get rid of the first colon and everything after it. Svnversion returns things like “64:67M” and I’m interested only in the first number.

Then I tag the files as such:

contents = contents.gsub(/AssemblyVersion\(\"([\d.*]*)\"\)/, "AssemblyVersion(\"#{helper.build_info.build_number_template}\")")

Naturally, there’s more code surrounding these bits. This is just the meat of what’s going on. Basically, in the task I call get_version to store the version number on a helper object and that object is later used in a method that reads AssemblyInfo.cs files into “contents” and does the substitution and writes it back out.

Everything is working fine except for a phantom newline in the output:

[assembly: AssemblyVersion("1.1.0.62
")]
[assembly: AssemblyFileVersion("1.1.0.62
")]

I’ve tried adding another .gsub to try to filter out \n and \r with no luck, I’ve tried .chomp, etc. It always seems to put that newline in the resulting file.

Am I missing something obvious?

[Edit in response to first answer:]

Here’s the method that edits the AssemblyInfo.cs file:

def replace_assembly_strings(file_path, helper)

    if not (File.exists?(file_path) || File.writable?(file_path))
      raise "the file_path \"#{file_path}\" can not be written to.  Does it exist?"
    end

    path = Pathname.new(file_path)
    contents = path.read
    puts "AssemblyVersion(\"#{helper.build_info.build_number_template}\")"
    contents = contents.gsub(/AssemblyVersion\(\"([\d.*]*)\"\)/, "AssemblyVersion(\"#{helper.build_info.build_number_template}\")")
    contents = contents.gsub(/AssemblyFileVersion\(\"([\d.*]*)\"\)/, "AssemblyFileVersion(\"#{helper.build_info.build_number_template}\")")
    contents = contents.gsub(/AssemblyCompany\(\"(.*)\"\)/, "AssemblyCompany(\"#{helper.build_info.company}\")")
    contents = contents.gsub(/AssemblyCopyright\(\"(.*)\"\)/, "AssemblyCopyright(\"#{helper.build_info.copyright}\")")

    File.open(file_path, 'w') {|f| f.write(contents)}

  end

That puts line outputs AssemblyVersion("1.1.0.62") but the resulting file shows AssemblyVersion("1.1.0.>")

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:05:26+00:00Added an answer on May 15, 2026 at 3:05 pm

    Readlines doesn’t implicitly remove the newline from the end of the line. Usually people invoke chomp! on the result. You can figure things like this out with the p method (or debugger, I guess), adding p line before you invoke your gsub. Then you should see (unless I’m astoundingly wrong) that your versions actually look like "64:67M\n" However, you have an easier solution available, String#to_i will convert the string to an int until it finds a non digit. So "64:67M".to_i # => 64 and "64:67M\n".to_i # => 64 Which saves you from having to to be a regex ninja, and resolves your newline issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.