Environment variables get lost between MSBuild projects
I have a .NET solution containing following projects:
- web application (WAP)
- web deployment (WDP, .wdproj)
- wix setup (WIX, .wixproj)
In the WDP I've used a custom MSBuild task (SetEnvVar) to set some env. variables for further use in the build process. After setting them I can use them without prob. in the WDP but in the WIX they are empty/undefined. The strange thing is that when I reference those env. vars in the WIX files (by using properties in .wxs or preproc vars in .wxi) I get the values as expected.
Do you have any idea why the env. vars get lost/are undefined in .wixproj?
By the way the (solution) build process is triggered from inside VS 2010.
Update
This is basically my task code:
Environment.SetEnvironmentVariable(this.Variable, this.Value);
Is a MSBuild solution build not one process?
Will MSBuild spawn a new process for 开发者_JAVA百科every project in the solution?
is it possible your SetEnvVar task sets the environment variables for a single process instead of globally (which it should do to be safe btw)? In that case, it's likely that the WIX thingie is started as a different process in some way, so with it's own private copy of the current global environment set.
Here are the significant parts of the project files:
WDP (.wdproj)
<Target Name="AfterBuild">
<SetEnvVar Variable="MAJOR" Value="$(MajorNumber)" />
<SetEnvVar Variable="MINOR" Value="$(MinorNumber)" />
<SetEnvVar Variable="REVISION" Value="$(RevisionNumber)" />
<SetEnvVar Variable="BUILD" Value="$(BuildNumber)" />
</Target>
WIX (.wixproj)
<Target Name="AfterBuild">
<Message Text="Major: $(MAJOR) Minor: $(MINOR) Revision: $(REVISION)" />
<Move SourceFiles=".\bin\$(Configuration)\$(OutputName).msi" DestinationFiles=".\bin\$(Configuration)\Product_$(MAJOR).$(MINOR).$(REVISION).msi" />
</Target>
The Message task's log output is "Major: Minor: Revision: " therefore MAJOR, MINOR and REVISION vars are not availabe to the WIX project and for that the MSI package name is Product_...msi.
The project build order is of course WAP -> WDP -> WIX.
精彩评论