Cross-step global values?
-
Wednesday, September 19, 2012 11:45 AM
I'm using VS 2010 with C++, and I want to be able to set version related variables which will affect both the compilation, the resources and a post-build event.
I can set environment variables, but they don't take effect unless I restart VS. Otherwise they look like a good solution, since I can set them from within VS (which is most convenient) by using Setx in a pre-build event, and they seem to work in both preprocessor defines and the post build event (which is a script).
However, the restarting is annoying, so I'd like to find a solution which doesn't have that problem. I don't know MSBuild, but I imagine that something could be done using it to define such variables which will be accessible across all steps. Unfortunately I have no clue as where to even start looking.
I'd appreciate some help.
All Replies
-
Thursday, September 20, 2012 5:00 AMModerator
Hi,
The environment variables values are retrieved when msbuild.exe launches, or Visual Studio launches. So setting values in build process could not be used at the time of that first build.
However, my point is that: setting the environment variable is a one-time task, it doesn't look like a good idea to set "Version" as environment.
This requirement is covered by third party MSBuild Extension Pack: http://msbuildextensionpack.codeplex.com/
The author mentioned this functionality here: msdn thread
regards,
Forrest Guo | MSDN Community Support | Feedback to manager
-
Thursday, September 20, 2012 8:28 AM
Thanks Forrest. I'm only using environment variables because they're accessible by various parts of the system. I'm using Visual Studio to build, and I'm not familiar at all with using MSBuild alone, but I know it underlies the VS build system, which is why I posted here. If MSBuild has some variables I can set or anything like that, that would probably solve the problem.
I don't know enough to find the MSBuild Extension Pack helpful. I guess I could learn MSBuild, and I'm guessing that Visual Studio extensions could also be used to do what I want, but what I'm really looking for is someone to narrow my search down, hopefully giving me something which I can implement easily, without having to learn a lot and preferably without forcing anyone who wants to use the project to install something just to get it to compile.
-
Thursday, September 20, 2012 1:29 PM
I ended up creating a header file and using it for both source and resources, as well as parsing it using PowerShell for the post-build event. That's easily changed from within the IDE, so it fulfills all my needs.- Proposed As Answer by Forrest GuoMicrosoft Employee, Moderator Thursday, September 20, 2012 2:42 PM
- Marked As Answer by ET3D Sunday, September 23, 2012 6:41 AM
-
Thursday, September 20, 2012 2:41 PMModerator
Yes, that way is a little complicated, and not intuitive. I'm sorry that this suggestion doesn't help much. Below I'm referring to sample script for your information:
<!-- Get information on an assembly --> <MSBuild.ExtensionPack.Framework.Assembly TaskAction="GetInfo" NetAssembly="C:\Projects\CodePlex\MSBuildExtensionPack\Solutions\Main3.5\BuildBinaries\MSBuild.ExtensionPack.dll"> <Output TaskParameter="OutputItems" ItemName="Info"/> </MSBuild.ExtensionPack.Framework.Assembly> <Message Text="Identity: %(Info.Identity)" /> <Message Text="FullName: %(Info.FullName)" /> <Message Text="PublicKeyToken: %(Info.PublicKeyToken)" /> <Message Text="Culture: %(Info.Culture)" /> <Message Text="CultureDisplayName: %(Info.CultureDisplayName)" /> <Message Text="FileVersion: %(Info.FileVersion)" /> <Message Text="AssemblyVersion: %(Info.AssemblyVersion)" /> <Message Text="AssemblyInformationalVersion: %(Info.AssemblyInformationalVersion)" />
regards,Forrest Guo | MSDN Community Support | Feedback to manager

