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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:20:51+00:00 2026-05-27T00:20:51+00:00

In MsBuild it is possible to create a build.proj.user file which is parsed by

  • 0

In MsBuild it is possible to create a build.proj.user file which is parsed by the Microsoft.Common.Targets build file.

I want to have a similar system in place where it is possible to have a .user file in the root of the folder and make msbuild pick up the config settings from this file.

Take for example these paths:

c:\working\build.proj.user
c:\working\solution1\build.proj.user
c:\working\solution1\project1\
c:\working\solution1\project2\
c:\working\solution1\project3\build.proj.user

c:\working\solution2\
c:\working\solution2\project1\
c:\working\solution2\project2\

I want to achieve that for solution1/project1 the file c:\working\solution1\build.proj.user is read and for solution2/project1 the file c:\working\build.proj.user

The purpose is to allow integration test connectionstring properties to be customized per solution and or project.

The current solutions I see are:

  • Make a custom msbuild task which will go look for this file
  • Construct a shell command to find the file.
  • Have it hard-coded look in the parent and parent of parent path

I am not a fan of either solution and wonder if there isn’t a more elegant way of achieving my goal (with 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-27T00:20:51+00:00Added an answer on May 27, 2026 at 12:20 am

    Add this to your project files:

    <Import Project="build.proj.user" Condition="Exists('build.proj.user')"/>
    <Import Project="..\build.proj.user" Condition="!Exists('build.proj.user') and Exists('..\build.proj.user')"/>
    <Import Project="..\..\build.proj.user" Condition="!Exists('build.proj.user') and !Exists('..\build.proj.user') and Exists('..\..\build.proj.user')"/>
    

    EDIT:
    You can also do it using MsBuild inline task. It is little bit slower, but more generic 🙂
    Inline tasks are supported from MsBuild 4.0

    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion="4.0">
      <UsingTask TaskName="FindUserFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
        <ParameterGroup>
          <CurrentDirName ParameterType="System.String" Required="true" />
          <FileToFind ParameterType="System.String" Required="true" />
          <UserFileName ParameterType="System.String" Output="true" />
        </ParameterGroup>
        <Task>
          <Using Namespace="System"/>
          <Using Namespace="System.IO"/>
          <Code Type="Fragment" Language="cs">
            <![CDATA[
              Log.LogMessage("FindUserFile parameters:");
              Log.LogMessage("CurrentDirName = " + CurrentDirName);
              Log.LogMessage("FileToFind = " + FileToFind);
    
              while(CurrentDirName != Directory.GetDirectoryRoot(CurrentDirName) && !File.Exists(CurrentDirName + Path.DirectorySeparatorChar + FileToFind))
                 CurrentDirName = Directory.GetParent(CurrentDirName).FullName;
              if(File.Exists(CurrentDirName + Path.DirectorySeparatorChar + FileToFind)) 
                 UserFileName = CurrentDirName + Path.DirectorySeparatorChar + FileToFind;
    
              Log.LogMessage("FindUserFile output properties:");
              Log.LogMessage("UserFileName = " + UserFileName);
            ]]>
          </Code>
        </Task>
      </UsingTask>
    
      <Target Name="FindUserFileTest" >
        <FindUserFile CurrentDirName="$(MSBuildThisFileDirectory)" FileToFind="build.proj.user">
         <Output PropertyName="UserFileName" TaskParameter="UserFileName" />
        </FindUserFile>
    
        <Message Text="UserFileName = $(UserFileName)"/>
        <Error Condition="!Exists('$(UserFileName)')" Text="File not found!"/>
    
      </Target>
    </Project>
    

    How it works:
    FindUserFile is inline task written in C# language. It tries to find file specified in FileToFind parameter. Then iterate trough all parent folders and it returns the first occurrence of the FileToFind file in UserFileName output property. UserFileName output property is empty string if file was not found.

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

Sidebar

Related Questions

MSBuild 3.5 I have the following project structure: trunk/MainSolution.sln trunk/Build/MyBuild.Proj trunk/Library/... trunk/etc... So far,
I have an MsBuild file which shells out to TFS using tf.exe for a
Possible Duplicate: create smart device cab through msbuild I know MSBUild struggles to build
I want to create a pre processed file with msbuild for diagnostic reasons. The
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
In msbuild/xbuild I'd like to have a libPath property which can be ovveridden on
I am using MSBuild to build my stuff. I want to use CruiseControl.net as
Is it possible to automaticaly create msbuild.xml from VS project?
We're using Hudson and msbuild.exe to build C# software, and I know it's possible
Is it possible to use an msbuild task to build a smart device project

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.