MsBuild & VCBuild task setting /useenv
I'm replacing our Nant scripts with MSBuild for building all our projects. We rely on LIB & INCLUDE being set in the environment when building VC projects. When building these projects via the MsBuild task (i.e. building the solution), vcbuild gets invoked without the /useenv parameter, so the environment gets ignored. The VCBuild task doesn't include a Useenv property either.
Is there a sneaky way to do this ? For now I can work around it by using the Exec task to invoke VCBuild directly, but it would be nice to write:
<Project DefaultTargets="build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Include="project1.vcproj""/>
<Compile Include="project2.csproj""/>
</ItemGroup>
<Target Name="build" >
<MSBuild Projects="@(Compile)" ></MSBuild>
</Target>
</Project>
ie be able to call different custom targets for a group of MsBuild files easily without worrying if they're C++, C#, etc.
Odpovědi
- Mark,
This is a limitation of Beta 2 (fixed for RTM). For RTM you will be able to pass the MSBuild task a property that will instruct the VCBuild task to launch with /userenv
You'll be able to write the following (in your example):
<MSBuild Projects="@(Compile)" Properties="VCBuildUserEnvironment=true" />
In the mean-time, the <Exec /> task on vcbuild.exe with the /userenv switch on the command line will have to see you through until RTM.
Hope that helps!
Kieran
MSBuild Team.
Všechny reakce
- Mark,
This is a limitation of Beta 2 (fixed for RTM). For RTM you will be able to pass the MSBuild task a property that will instruct the VCBuild task to launch with /userenv
You'll be able to write the following (in your example):
<MSBuild Projects="@(Compile)" Properties="VCBuildUserEnvironment=true" />
In the mean-time, the <Exec /> task on vcbuild.exe with the /userenv switch on the command line will have to see you through until RTM.
Hope that helps!
Kieran
MSBuild Team. - Thanks Kieran. That sounds ideal.
Look forward to RTM. - /userenv is an invalid command line option to vcbuild.exe It's supposed to pass /USEENV (note: no 'R').
I had hope that the final version of Visual studio.Net 2005 would fix this. It does not.
MSBuild.exe BEIUtilityvsn8.vcproj /t:Build /p:Configuration=Debug,Platform=Win32,VCBuildUserEnvironment=true
Microsoft (R) Build Engine Version 2.0.50727.42
[Microsoft .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation 2005. All rights reserved.
Build started 10/28/2005 4:55:07 PM.
__________________________________________________
Project "H:\dev\2000\BEIUtility\BEIUtilityvsn8.vcproj" (Build target(s)):
Target Build:
H:\dev\2000\BEIUtility\BEIUtilityvsn8.vcproj : warning MSB4098: MSBuild is invoking VCBuild to build this project. Project-to-project references between VC++ projects (.VCPROJ) and C#/VB/VJ# proje
cts (.CSPROJ, .VBPROJ, .VJSPROJ) are not supported by the command-line build systems when building stand-alone VC++ projects. Projects that contain such project-to-project references will fail to build. Please build the solution file containing this project instead.
VCBuild.exe /userenv H:\dev\2000\BEIUtility\BEIUtilityvsn8.vcproj "Debug|Win32"
vcbuild.exe : warning VCBLD6002: invalid option /userenv specified. The option was ignored.
- MacJohnMcC,
You're right that we shipped with this bug. It was discovered too late, unfortunately. The exact same misspelling was in the test for it, so it was passing just fine and we didn't detect it.
Note that the VCBuild task has an AdditionalOptions property that can be used to work around this. Specifically,
/p:VCBuildAdditionalOptions="/useenv"
is equivalent to what
/p:VCBuildUserEnvironment="true"
should do.
Dan This bites. I just want to let MSBuild build off the SLN file. Is there a way to get MSBuild to build the vcproj file and inherit env vars I have exported in the parent MSBuild process?
Ya know it would be really nice if VC project files and SLN files were also MSBuild files. This kind of goofiness wouldn't be a problem. The vcproj msbuild file could just use msbuild properties.

