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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:44:38+00:00 2026-06-15T11:44:38+00:00

I just joined a team that has no CI process in place (not even

  • 0

I just joined a team that has no CI process in place (not even an overnight build) and some sketchy development practices. There’s desire to change that, so I’ve now been tasked with creating an overnight build. I’ve followed along with this series of articles to: create a master solution that contains all our projects (some web apps, a web service, some Windows services, and couple off tools that compile to command line executables); created an MSBuild script to automatically build, package, and deploy our products; and created a .cmd file to do it all in one click. Here’s a task that I’m trying to accomplish now as part of all this:

The team currently has a practice of keeping the web.config and app.config files outside of source control, and to put into source control files called web.template.config and app.template.config. The intention is that the developer will copy the .template.config file to .config in order to get all of the standard configuration values, and then be able to edit the values in the .config file to whatever he needs for local development/testing. For obvious reasons, I would like to automate the process of renaming the .template.config file to .config. What would be the best way to do this?

Is it possible to do this in the build script itself, without having to stipulate within the script every individual file that needs to be renamed (which would require maintenance to the script any time a new project is added to the solution)? Or might I have to write some batch file that I simply run from the script?

Furthermore, is there a better development solution that I can suggest that will make this entire process unnecessary?

  • 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-15T11:44:39+00:00Added an answer on June 15, 2026 at 11:44 am

    After a lot of reading about Item Groups, Targets, and the Copy task, I’ve figured out how to do what I need.

    <ItemGroup>
        <FilesToCopy Include="..\**\app.template.config">
            <NewFilename>app.config</NewFilename>
        </FilesToCopy>
        <FilesToCopy Include="..\**\web.template.config">
            <NewFilename>web.config</NewFilename>
        </FilesToCopy>
        <FilesToCopy Include"..\Hibernate\hibernate.cfg.template.xml">
            <NewFilename>hibernate.cfg.xml</NewFilename>
        </FilesToCopy>
    </ItemGroup>
    
    <Target Name="CopyFiles"
            Inputs="@(FilesToCopy)"
            Outputs="@(FilesToCopy->'%(RootDir)%(Directory)%(NewFilename)')">
        <Message Text="Copying *.template.config files to *.config"/>
    <Copy SourceFiles="@(FilesToCopy)"
          DestinationFiles="@(FilesToCopy->'%(RootDir)%(Directory)%(NewFilename)')"/>
    

    I create an item group that contains the files that I want to copy. The ** operator tells it to recurse through the entire directory tree to find every file with the specified name. I then add a piece of metadata to each of those files called “NewFilename”. This is what I will be renaming each file to.

    This snippet adds every file in the directory structure named app.template.config and specifies that I will be naming the new file app.config:

    <FilesToCopy Include="..\**\app.template.config">
        <NewFilename>app.config</NewFilename>
    </FilesToCopy>
    

    I then create a target to copy all of the files. This target was initially very simple, only calling the Copy task in order to always copy and overwrite the files. I pass the FilesToCopy item group as the source of the copy operation. I use transforms in order to specify the output filenames, as well as my NewFilename metadata and the well-known item metadata.

    The following snippet will e.g. transform the file c:\Project\Subdir\app.template.config to c:\Project\Subdir\app.config and copy the former to the latter:

    <Target Name="CopyFiles">
        <Copy SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy->'%(RootDir)%(Directory)%(NewFileName)')"/>
    </Target>
    

    But then I noticed that a developer might not appreciate having his customized web.config file being over-written every time the script is run. However, the developer probably should get his local file over-written if the repository’s web.template.config has been modified, and now has new values in it that the code needs. I tried doing this a number of different ways–setting the Copy attribute “SkipUnchangedFiles” to true, using the “Exist()” function–to no avail.

    The solution to this was building incrementally. This ensures that files will only be over-written if the app.template.config is newer. I pass the names of the files as the target input, and I specify the new file names as the target output:

    <Target Name="CopyFiles"
            Input="@(FilesToCopy)"
            Output="@(FilesToCopy->'%(RootDir)%(Directory)%(NewFileName)')">
          ...
    </Target>
    

    This has the target check to see if the current output is up-to-date with respect to the input. If it isn’t, i.e. the particular .template.config file has more recent changes than its corresponding .config file, then it will copy the web.template.config over the existing web.config. Otherwise, it will leave the developer’s web.config file alone and unmodified. If none of the specified files needs to be copied, then the target is skipped altogether. Immediately after a clean repository clone, every file will be copied.

    The above turned out be a satisfying solution, as I’ve only started using MSBuild and I’m surprised by its powerful capabilities. The only thing I don’t like about it is that I had to repeat the exact same transform in two places. I hate duplicating any kind of code, but I couldn’t figure out how to avoid this. If anyone has a tip, it’d be greatly appreciated. Also, while I think the development practice that necessitates this totally sucks, this does help in mitigating that suck factor.

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

Sidebar

Related Questions

I've just joined a team that for whatever reasons do not check in their
I've just joined a team which has been working in a main-always mode for
I have just joined a project that has a connection string which is defined
I recently joined a team that is working on a ASP.NET MVC project.. they
The project that I have just joined uses the command pattern quite extensively for
I just joined a team thats developing a asp.net mvc 1 application. I only
Our customer has just joined the iOS Developer Enterprise Program. They have signed the
i just joined this new group and basically haven't even really done any heavy
This is not a homework question, just something at work that's bugging me. I'm
I am new to working with Spring and I just joined a team of

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.