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 7173655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:52:11+00:00 2026-05-28T15:52:11+00:00

I have the following string called MasterVersion : 1.1-SNAPSHOT I need to split it

  • 0

I have the following string called MasterVersion:

1.1-SNAPSHOT

I need to split it by the . and the – so it becomes a string[] array called SplitVersion, i.e.:

1
1
SNAPSHOT

I’ve tried everything I can think of including about a dozen variations of the below, with no joy:

<!-- doesn't work -->
<ItemGroup>
    <VersionDelimiters Include="." />
    <VersionDelimiters Include="-" />
    <SplitVersion Include="$(MasterVersion.Split(@VersionDelimiters))" />
</ItemGroup>

<!-- doesn't work either -->
<ItemGroup>
    <SplitVersion Include="$(MasterVersion.Split([`.`; `-`]))" />
</ItemGroup>

What obscure MSBuild syntax am I missing/mucking up?

  • 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-05-28T15:52:12+00:00Added an answer on May 28, 2026 at 3:52 pm

    MSBuild 4.0 property functions cannot handle arrays (well basically), however when you do a

    Split(`,`, `-`)
    

    You are invoking the String.Split(params string[]) overload, which requires an array (even in C# the params keyword will create an array behind the scene and do something like Split(new string[] { ',', '-' }) internally).

    What you could do is the following:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
     ToolsVersion="4.0">
    
        <PropertyGroup>
            <MasterVersion>1.1-SNAPSHOT</MasterVersion>
        </PropertyGroup>
    
        <ItemGroup>
            <SplitVersion Include="$(MasterVersion.Replace(`-`, `.`).Split(`.`))" />
        </ItemGroup>
    
        <Target Name="Test">
            <Message Importance="high" Text="@(SplitVersion)"/>
        </Target>
    </Project>
    

    Or you could first create the (string) array to be passed to Split:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
        <PropertyGroup>
            <MasterVersion>1.1-SNAPSHOT</MasterVersion>
            <Delimiters>.;-</Delimiters>
            <DelimitersArray>$(Delimiters.Split(`;`))</DelimitersArray>
        </PropertyGroup>
        <ItemGroup>
            <SplitVersion Include="$(MasterVersion.Split($(DelimitersArray)))" />
        </ItemGroup>
        <Target Name="Test">
            <Message Importance="high" Text="@(SplitVersion)"/>
        </Target>
    </Project>
    

    Which is not really better in this case 😉

    Oh, and you might want to check out this MSDN blog entry for more useful information.

    Update for a comment:

    • The “content” of SplitVersion is technically an “array of ITaskItem”, yes.
      You would deal with it however you would deal with Items (of ItemGroups);
      including things like “batching”, etc.

    • You cannot really “access things by index” in msbuild project files. Expressions like
      $(SplitVersion)[0] or @(SplitVersion)[0] or @(SplitVersion[0]) don’t
      do what you’d think/like. If you really would to you could assign individual
      properties for “array elements” by “index”.

    Example:

    <PropertyGroup>
      <SplitVersion0>$(MasterVersion.Split($(DelimitersArray))[0])</SplitVersion0>
      <SplitVersion1>$(MasterVersion.Split($(DelimitersArray))[1])</SplitVersion1>
      <SplitVersion2>$(MasterVersion.Split($(DelimitersArray))[2])</SplitVersion2>
    </PropertyGroup>
    

    The array-indexing operator works here, because in this case you are still “in the context” of the .NET expression. Once that is assigned to a property (or item group) you cannot do that anymore.

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

Sidebar

Related Questions

I have the following string that I need to split from a field called
I have the following string: cn=abcd,cn=groups,dc=domain,dc=com Can a regular expression be used here to
I have the following string: string path = C:\Users\Username\Desktop\FileName.pdf; I need to take off
I have one class called Holder (holder.cs) that contain the following: string name; List<String>
I have a string like this This:string:must~:be:split:when:previous:char:is:not~:this I need to split the line with
I have the following code to parse a String variable called str. NumberFormat formatter
I have the following code in my controller called UserController : public ActionResult Details(string
I have the following string in a file called mib.txt: [name=1.3.6.1.2.1.1.5.0, value=myrouter.ad.local (OCTET STRING)]
I have following string String str = replace :) :) with some other string;
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,

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.