Click here to Skip to main content
15,885,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have been assigned a VC++ project and its my first time am working on a VC++ project.
The project was earlier built on visual Studio 2015 and I can see a Post-Build event being mentioned in project properties where it is calling a batch file - "vsvars32.bat".

Am using Visual Studio 2017 and I have changed the file name to - "vsdevcmd.bat".

I was doing some research and some questions came up into my mind. I understood something and also found some more topics related to this, which I have mentioned in "What have u tried" section. I am googling till now to find the answers but I couldn't find any till now. Might be I can get a good explanation here.

1. Why this batch file needs to be executed?
2. Can I call this batch file for any other C#/other language projects also?
3. If I don't call this batch file for current VC++ project then what could be the consequences?

What I have tried:

As per the questions came into my mind, I started finding the answers and came to know that all these are part of "MSBUild".

Basically, "vsdevcmd.bat" file is used to setup environment variables.
Also, I came to know that we can build Visual Studio projects using "MSBuild" and it has a property named as "Platform Toolset", where we can specify for which platform am trying to build the application and it can be for driver and non-driver projects.

Now, again a lot of questions came into my mind:

1. What is the relation between Platform Toolset and Environment Variable?
2. Is this environment variable specifically for Visual Studio applications or the whole system (like we set after installation of many software e.g - Java SDK)?
3. I have worked on C# projects but never I set up these environment variables ever using this batch file. So, is it required for any VC++ project?
4. Am already writing the code in Visual Studio and building the application using VS Build, so it means its managed by CLR and so why I need to specify all these env variables or platform toolset?

Please help me to understand in core. Any links would also be helpful.

Thanks to all.
Posted
Updated 8-Feb-20 22:17pm

1 solution

1. The Platform Toolset is used to define the various library and platform versions required to generate the correct code for the application, e.g x86, x64, Windows version etc.

2. These environment settings are used only within Visual Studio, or in a batch process where you invoke the compiler from the command line.

3. The batch file vsvars32.bat sets up all required environment settings to allow a batch run of the VC compiler and linker. I have no idea why you would need to run that as a post build event, unless it is followed by some other command(s).

4. So is this pure C++ or C++/CLI?
 
Share this answer
 
Comments
Member 11072126 9-Feb-20 8:25am    
Thanks Richard for your response.
Regarding your doubt about why using vsvars32.bat as post-build event, honestly I have no idea as well and so started researching on this.

So, what I understood as of now is that if I build using Visual Studio Build option then I do not need to run this Post-Build event. If I am using any other IDE like Visual Studio Code or any other IDE who doesn't have in-built C++ compiler and configuration options (Build or Release) and also platform setting options, for those cases, we can use calling vsvars32.bat or vsdevcmd.bat to setup these platform and environment settings.

Regarding your last question, I feel its C++/CLI.
Richard MacCutchan 9-Feb-20 9:17am    
This is simple to test, just remove the Post Build event and try rebuilding the project.

As to your last answer what do you mean by "I feel its C++/CLI"? Either it is or it is not.
Member 11072126 10-Feb-20 22:53pm    
Well, actually I learnt C++ in my college days and now when I got this project, I simply considered it as C++. I didn't have any idea about CLI or pure C++.
Richard MacCutchan 11-Feb-20 3:59am    
So which is it?
Member 11072126 17-Feb-20 22:00pm    
This is MFC code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900