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

  • SEARCH
  • Home
  • 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 7874407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:48:01+00:00 2026-06-03T02:48:01+00:00

I’m trying to create a C# regular expression that detects when references in our

  • 0

I’m trying to create a C# regular expression that detects when references in our .csproj files do not have < SpecificVersion> set to False (had to add a space after all <‘s to make it show up properly in StackOverflow). So these are the cases that I need to handle:

1. <Reference Include="IQ.MyStuff1, Version=4.1.0.0, Culture=neutral, processorArchitecture=MSIL" />
2. <Reference Include="IQ.MyStuff2, Version=4.7.22.21777, Culture=neutral, processorArchitecture=MSIL">
    <HintPath>..\..\DebugDLLFiles\IQ.MyStuff2.dll</HintPath>
</Reference>
3. <Reference Include="IQ.MyStuff3, Version=4.1.0.0, Culture=neutral, processorArchitecture=MSIL">
    <HintPath>..\..\DebugDLLFiles\IQ.MyStuff3.dll</HintPath>
    <SpecificVersion>True</SpecificVersion>
</Reference>
4. <Reference Include="IQ.MyStuff4, Version=4.5.3.17401, Culture=neutral, processorArchitecture=MSIL">
    <SpecificVersion>True</SpecificVersion>
</Reference>

So basically any file reference that doesn’t explicitly have “< SpecificVersion>False< /SpecificVersion>” in it.

So let’s ignore the first case because it doesn’t have a body like the other 3 and can be treated differently. So here is what I have so far:

<Reference(\s|\n|\r)*?  # Match against '<Reference '.
Include=""IQ\..*?""     # Match against the entire Include attribute; We only care about IQ DLLs.
(\s|\n\r)*?>            # Eat any whitespace and match against the closing tag character.
[What should go here?]
</Reference>            # Match against the closing tag.

So I’ve tried numerous things in the [What should go here?] block, but can’t seem to get any to work quite perfectly. The closest I came was using the following for this block:

(?!                     # Do a negative look-ahead to NOT match against this Reference tag if it already has <SpecificVersion>False</SpecificVersion>.
    (.|\n|\r)*?         # Eat everything before the <SpecificVersion> tag, if it even exists.
    <SpecificVersion>(\s|\n|\r)*?False(\s|\n|\r)*?</SpecificVersion>    # Specify that we don't want to match if this tag already has <SpecificVersion>False</SpecificVersion>.
)
(.|\n|\r)*?             # Eat everything after the <SpecificVersion> tag, if it even existed.

This works for all cases, except for where there is a valid reference below any of the ones I want to match against, where a valid reference would look something like:

<Reference Include=\"IQ.MyStuff5, Version=4.5.3.17401, Culture=neutral, processorArchitecture=MSIL\">
    <SpecificVersion>False</SpecificVersion>
</Reference>

It seems that the look-ahead I’m using doesn’t stop at the < /Reference> tag, but continues looking down the entire file to make sure no text below it has “< SpecificVersion>False< /SpecificVersion>”.

How can I make my look-ahead stop at the first “< /Reference>” it encounters, or if you have another way to solve my problem I’m open to that too. Any suggestions are appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 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-06-03T02:48:02+00:00Added an answer on June 3, 2026 at 2:48 am

    So following spender’s advice I looked into regex alternatives. I discovered Linq To XML and it made solving my problem very easy. Here is the code I ended using to solve my problem. It finds all references in a .csproj file to IQ DLL files and ensures that they all have a < SpecificVersion>False< /SpecificVersion> element. Just for some background info, the reason I need to do this is that our builds run fine on our local machines when Specific Version is set to True, but it breaks on our TFS build server unless it is set to False. I’m pretty sure the reason for this is that our TFS build updates the version number, so then the version that each project is set to use is out-of-date. Anyways, here’s the code 🙂

    // Let's parse us some XML!
    XElement xmlFile = XElement.Load(filePath);
    
    // Grab all of the references to DLL files.
    var iqReferences = xmlFile.Descendants().Where(e => e.Name.LocalName.Equals("Reference", StringComparison.InvariantCultureIgnoreCase));
    
    // We only care about iQ DLL files.
    iqReferences = iqReferences.Where(r => r.Attribute("Include") != null && r.Attribute("Include").Value.StartsWith("IQ.", StringComparison.InvariantCultureIgnoreCase));
    
    // If this project file doesn't reference any iQ DLL files, move on to the next project file.
    if (!iqReferences.Any())
        continue;
    
    // Make sure they all have <SpecificVersion> set to False.
    foreach (XElement reference in iqReferences)
    {
        // If this Reference element already has a child SpecificVersion element whose value is false, skip this reference since it is good.
        if (reference.Elements().Where(e => e.Name.LocalName.Equals("SpecificVersion", StringComparison.InvariantCultureIgnoreCase))
            .Any(e => e.Value.Equals("False", StringComparison.InvariantCultureIgnoreCase)))
            continue;
    
        // Add this reference to the list of bad references.
        badReferences.AppendLine("\t" + reference.Attribute("Include").Value);
    
        // Fix the reference.
        reference.SetElementValue(reference.Name.Namespace + "SpecificVersion", "False");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is

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.