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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:40:31+00:00 2026-06-16T00:40:31+00:00

I’m trying to us MSBuild to add a linked file to my .csproj file.

  • 0

I’m trying to us MSBuild to add a linked file to my .csproj file.

This is .Net Framework 3.5 (and not 4.0). I mention that because I’m seen some 4.0 specific stuff trying to manipulate the XML.

Here is what I’m starting with:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>

  <ItemGroup>
    <Compile Include="MySuperCoolClass.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

</Project>

This is what I’m trying to get:

   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
      <ItemGroup>
        <Reference Include="System" />
        <Reference Include="System.Core">
          <RequiredTargetFramework>3.5</RequiredTargetFramework>
        </Reference>
        <Reference Include="System.Data" />
        <Reference Include="System.Xml" />
      </ItemGroup>

      <ItemGroup>
        <Compile Include="MySuperCoolClass.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
      </ItemGroup>


      <ItemGroup>
        <Content Include="..\..\SomeFunFolder\MyLinkFile.ext">
          <Link>MyLinkFile.ext</Link>
        </Content>
      </ItemGroup>    

      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    </Project>  

I have:

  • MSBuild.Community.Tasks.dll

and

  • MSBuild.ExtensionPack.dll

available.

Any concrete help?

One liner comments like use ‘MSBuild.ExtensionPack.Xml.XmlFile’ won’t be helpful.

But I appreciate any pointers or coded examples immensely.

  • 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-16T00:40:31+00:00Added an answer on June 16, 2026 at 12:40 am

    Well, I opened up the code for “MSBuild.ExtensionPack.Xml.XmlFile(.cs)” and looked around.
    Thank goodness for open source.

    I figured out..you gotta “build it up”.
    And I had to add a little voodoo trick (with the “MyUniqueKeyHelper123” seen below).

    I’ll post here.
    If you’re having trouble with “MSBuild.ExtensionPack.Xml.XmlFile(.cs)”, get the source code and look at it. You can figure out how to set the properties by looking at the method.
    It was a little tricky at first, but figure-out-able.

    <PropertyGroup>
        <MSBuildExtensionPackPath Condition="'$(MSBuildExtensionPackPath)' == ''">.\ExtensionPackFiles</MSBuildExtensionPackPath>
        <MSBuildExtensionPackLib>$(MSBuildExtensionPackPath)\MSBuild.ExtensionPack.dll</MSBuildExtensionPackLib>
    </PropertyGroup>    
    
    
    <UsingTask AssemblyFile="$(MSBuildExtensionPackLib)" TaskName="MSBuild.ExtensionPack.Xml.XmlFile" />
    
    
    <Target Name="XmlTest01Target">
    
        <Message Text="MSBuildExtensionPackLib = $(MSBuildExtensionPackLib)" />
    
        <!--
    
        The goal is:
    
        <ItemGroup>
        <Content Include="..\..\SomeFunFolder\MyLinkFile.ext">
        <Link>MyLinkFile.ext</Link>
        </Content>
        </ItemGroup>    
    
        -->
    
        <!-- Define a custom namespace.  I used "peanut" just to show it is any name you give it  -->
    
        <ItemGroup>
            <Namespaces Include="Mynamespace">
                <Prefix>peanut</Prefix>
                <Uri>http://schemas.microsoft.com/developer/msbuild/2003</Uri>
            </Namespaces>       
        </ItemGroup>
    
        <!-- 
            Add the <ItemGroup> (new) Element.  HOWEVER, since there will probably be multiple <ItemGroup> nodes, tag it with some unique identifier.  Will Clean up later.
        -->
        <XmlFile 
            TaskAction="AddElement" 
                        Namespaces="@(Namespaces)" 
                     File=".\MyCSharpProjectFile.csproj"
                     Element="ItemGroup"
                     Key="MyUniqueKeyHelper123"
                     Value ="MyUniqueValueHelper123"
                     XPath="//peanut:Project" 
            />
    
        <!-- 
            Add the <Content> (new) Element.  With Attribute Value.
        -->         
        <XmlFile 
            TaskAction="AddElement" 
                     File=".\MyCSharpProjectFile.csproj"
                     Element="Content"
                     Key="Include"
                     Value ="..\..\SomeFunFolder\MyLinkFile.ext"
                                    Namespaces="@(Namespaces)" 
                     XPath="//peanut:Project/peanut:ItemGroup[@MyUniqueKeyHelper123='MyUniqueValueHelper123']" 
            />
    
        <!-- 
            Add the <Content> (new) Element.  With Element Value Value.
        -->                 
        <XmlFile 
            TaskAction="AddElement" 
                     File=".\MyCSharpProjectFile.csproj"
                     Element="Link"
                     InnerText ="MyLinkFile.ext"
                        Namespaces="@(Namespaces)" 
                     XPath="//peanut:Project/peanut:ItemGroup[@MyUniqueKeyHelper123='MyUniqueValueHelper123']" 
            />
    
        <!-- 
            Clean up the "unique" attribute to leave clean xml.
        -->             
        <XmlFile 
            TaskAction="RemoveAttribute" 
                     File=".\MyCSharpProjectFile.csproj"
                     Element="Link"
                     Key="MyUniqueKeyHelper123"
                        Namespaces="@(Namespaces)" 
                     XPath="//peanut:Project/peanut:ItemGroup[@MyUniqueKeyHelper123='MyUniqueValueHelper123']" 
            />
    
    </Target>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.