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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:01:49+00:00 2026-05-13T06:01:49+00:00

I have an msbuild project file that is used for building several C++ projects

  • 0

I have an msbuild project file that is used for building several C++ projects (*.vcproj). Here’s a part of a typical project file, in which global environment variables for the build are overridden as properties:

<PropertyGroup>
  <MYBINDIR>d:\buildsysroot\bin</MYBINDIR>
  <MYLIBDIR>d:\buildsysroot\lib</MYLIBDIR>
  ...
</PrpertyGroup>

<ItemGroup>
  <MyItems Include="d:\buildsysroot\myproject\myproject.vcproj"/>
</ItemGroup>

<Target Name="Release_x64">
  <VCBuild Projects="@(MyItems)" Configuration="Release_dll|x64"/>
</Target>

These environment variables are used by all vcproj files, through property sheets.
Here’s an excerpt of a vcproj:

<Configuration
  Name="Release_dll|x64"
  ConfigurationType="1"
  InheritedPropertySheets="$(BUILDPROPSDIR)\defaults.vsprops;$(BUILDPROPSDIR)\build_dll.vsprops"
>

And this is how the property sheets look:

<VisualStudioPropertySheet
  Name="defaults"
  OutputDirectory="$(MYBINDIR)\_$(ConfigurationName)_$(PlatformName)"
  IntermediateDirectory="$(MYBUILDDIR)_$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
  >
  <Tool
    Name="VCLinkerTool"
    AdditionalLibraryDirectories="&quot;$(MYLIBDIR)&quot;"
  />
<VisualStudioPropertySheet/>

The problem is: when building, the value for the environment variables declared in the msbuild file (MYBINDIR, MYLIBDIR) do not make it into the property sheets, but seem to be local to the msbuild file only: within the msbuild project MYBINDIR expands to “d:\buildsysroot\bin”, but within the vc project MYBINDIR expands to “d:\projects\bin”, which is the value that I set globally (eg via MyComputer->Advanced->EnvironmentVariables) and which must stay there because it’s how my main development environment is set up.

How do I pass the environment set in the msbuild file to the VCBuild task?

I know that this problem could be solved by using a batch file and declaring the environment there using ‘set’, and not in the msbuild file; that’s how I used to do it, but I prefer the method above as it’s just one call to msbuild with one argument and that’s it.

EDIT

I needed a solution quickly and came up with a custom task that sets the environment in the same way a batch file would do, but with the bonus of doing it within msbuild.. The tasks’s Execute() method simply does Environment.SetEnvironmentVariable( var, val ).
This still requires setting the proces’ environment, I’d be glad to hear if there is another way!

  • 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-13T06:01:50+00:00Added an answer on May 13, 2026 at 6:01 am

    since nobody else answered/commented I’m going with my own answer: a custom task that sets the process’ environment using Environment.SetEnvironmentVariable( var, val )

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

Sidebar

Related Questions

We have a standard MSBuild project file that is used for our different deployment
I have a few .net / C# projects that I'm building with MSBuild. In
I have a solution that is being referenced by a MSBuild project. In the
I have created an MSBuild tasks for building my projects, but for various reasons
Short version: I have an MSBuild project that imports another project. There is a
I have a solution file that's become 'unstuck' from the projects it references, so
I have a .sln solution file that references a .csproj project file that has
I have an imported MSBuild project (appconfig.transformation.targets) that defines some tasks and puts them
I have created a msbuild file which will build a solution file(NOTE: not a
I've got an msbuild project that tries to establish a global root directory thus:

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.