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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:03:07+00:00 2026-05-16T07:03:07+00:00

I want to use MSBuild to grab and create the relevent elements for 2

  • 0

I want to use MSBuild to grab and create the relevent elements for 2 files. If it was just a single file extension, I would use:

<ItemGroup>
    <Compile Include="\Pages\*.cs" /> 
</ItemGroup>

In a .csproj file for a Silverlight build, each UserControl is set like with it’s own <Compile> element and a child <DependentUpon> element:

<ItemGroup>
    <Compile Include="Pages\SilverlightControl1.xaml.cs">
        <DependentUpon>SilverlightControl1.xaml</DependentUpon>
    </Compile>
    <Compile Include="Pages\SilverlightControl2.xaml.cs">
        <DependentUpon>SilverlightControl2.xaml</DependentUpon>
    </Compile>
</ItemGroup>

In the MSBuild file, I’d like to specify:

grab all the .cs files
and put those in the Include
attribute and get the same file name – minus the .cs and put that in the <DependentUpon> element.

So that it would just be something like (pseudo) to match the file pairs:

<ItemGroup>
    <Compile Include="Pages\*.cs">
        <DependentUpon>Pages\*.xaml</DependentUpon>
    </Compile>
</ItemGroup>

Is there a way to do put the above in MSBuild?

  • 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-16T07:03:08+00:00Added an answer on May 16, 2026 at 7:03 am

    MSBuild has two separate metadata properties called %(Filename) (which is the filename without the extension) and %(Extension) which would be the “.cs” in your example. So, I wonder if this is possible:

    <ItemGroup>
        <Compile Include="Pages\*.cs">
            <DependentUpon>%(Directory)%(Filename)</DependentUpon>
        </Compile>
    </ItemGroup>
    

    But, I don’t think you will like what it’s gonna do or even do what you want it to do.

    You really should only ever have “glob” type items (*.cs) within a target – you should not declare it as a top level item group, otherwise it will do funny things in visual studio and (for example) will add all the .cs files to version control and maybe even expand the *.cs into individual items in your project.

    Here’s what I would suggest in a NON Visual Studio msbuild project:

    <Target Name="PrepareCompileItems">
        <XamlFiles Include="Pages\*.cs">
            <DependentUpon>%(Directory)%(Filename)</DependentUpon>
        </XamlFiles>
    
        <Compile Include="@(XamlFiles)" />
    </Target>
    

    If you were doing this within a VS project, then it’s tricker – cos you want to add metadata to an already existing itemgroup to force the dependentUpon association before compile:

    <Target Name="AddDependentUponMetadata">
        <CsFiles Include="Pages\*.cs" />
    
        <XamlFiles Include="@(CsFiles)">
            <DependentUpon>%(Directory)%(Filename)</DependentUpon>
        </XamlFiles>
    
        <Compile Remove="@(CsFiles)" />    
        <Compile Include="@(XamlFiles)" />
    </Target>
    

    Although, I’m typing this without actually testing my assertions so YMMV…

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

Sidebar

Related Questions

I have a transaction log file in CSV format that I want use to
I come from an ant background, and I'm starting to use msbuild. I want
I'm a complete newbie to MSBuild and I want to use it over NANT.
I want MSBuild to build WIX 3.5 project containing static files and binaries from
I want to create a continuous build integration system for .NET using just Windows
I am using MSBuild to build my stuff. I want to use CruiseControl.net as
In our automatic build we use MSBuild in combination with web.config transformation to create
I use msbuild to compile a Visual Studio 2010 solution and need a successful
I want to create an ItemGroup of arbitrary strings / names in order to
I want use groovy findAll with my param to filtering closure filterClosure = {

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.