Access ProgramFilesFolder from Visual Studio post-build events - visual-studio

When building a C# project in Visual Studio, in the post-build events I need to call a program that is situated in C:\Program Files\\MyProgram.exe. How can I access the "C:\Program Files" folder from the post-build events?
At this link: http://msdn.microsoft.com/en-us/library/42x5kfw4.aspx there are several Macros that can be used in the post-build events section of Visual Studio. Is there a Macro or is there a way to access the default ProgramFilesFolder path?

Don't look for a macro, none is provided since you can also use environment variables in the pre/post-build steps. Just like you can with a .bat file, which is the way these build steps actually execute. You are probably looking for the %programfiles% environment variable. So to run that program, simply use:
"%programfiles%\myprogram.exe"

Sadly, using %programfiles% leads to the x86 program files folder. There's an environment variable for x86 program files folder (%programfiles(x86)%) but none for the x64 folder. Thus, you can't target the x64 program files folder, neither explicitly nor implicitly, when using standard environment variables. You'll always target the x86 folder. (vs2019 professional 16.10.1)

Related

Running vcvars32.bat before compiling in Code::Blocks?

I've installed Visual Studio C++ Express 2012 and want to use it's compiler with Code::Blocks. Starting cl.exe does not work (missing mspdb100.dll) until I run vcvars32.bat, but that does only hold on for the current session in the Command-line. The same applies to compiling with Code::Blocks.
How can I make it run the vcvars32.bat before compiling?
Workaround
That workaround is actually not what I was looking for, but it works, and that is important. Instead of letting Code::Blocks running cl.exe directly, I've set-up a simple batch-script that runs vcvars32.bat before running the actual compiler.
REM File: cl.bat
call vcvars32.bat
call cl.exe %1 %*
In the project properties, you have a section Build events. You can add vcvars32.bat to the pre-build event.
To run the .bat before compiling in Code Blocks(16.01), go to the project build options and its under the "pre/post build steps" tab. This tab only appears in the project settings, not the compiler settings.
However, adding "vcvars32.bat" (or "vcvars64.bat") to the pre build steps didn't fix the error for me.
I found the directory where the library is and added it to the linker search directories. This gave errors about further missing libraries. I added the following paths to my linker settings. These will almost certainly be different for you. I'm installed MSVS 2017 community edition. For some reason known only to Microsoft, the necessary libraries are installed on two different drives.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib\x64
D:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64
D:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x64
Note that the .bat script is no longer necessary if you add these paths by hand.

Batch Builds in Visual Studio 6 for VC++ project

In VS 2008 and VS 2010, one can easily create a solution and modify the "Solution Configuration". We can choose what configuration each project gets built in when we trigger a build at the solution level.
Is such a facility available in the Visual Studio 6.0?
In my experience:
when a configuration is chosen (form the list available) in VS6 for a VC++ project, the dependencies (which themselves have multiple configurations defined) get built in some random order. There is no way to control the configurations of dependencies at build time.
"Batch Build" does come close to this but is not as flexible for my purpose.
I have tried various options in the VS6.
Hope I am clear.
Here is a link on the MSDEV command line.
https://msdn.microsoft.com/en-us/library/aa699274(v=vs.60).aspx
There is a way to control the building of dependencies. Specify /NORECURSE and dependencies will not be built.
I use /REBUILD with /NORECURSE to keep the dependencies from getting built.
And I build each project one at a time inside the workspace in a bat file by doing a chdir to the subdirectory and calling MSDEV just for that subproject:
msdev myproject.dsp /MAKE "myproject - Win32 Debug" /REBUILD /NORECURSE > Build.log
Then I cd to the next project directory one at a time.
On a side note, I had difficulties for several years where NMAKE would not work for my specific tasks. Turns out that the PATH environment variable inside MSDEV (Visual Studio 6.0) is different from the PATH environment variable of a command shell you would run NMAKE on.
The Path used by the MSDEV shell is the %PATH% at the time Visual Studio 6 was installed. We use this and poke the registry as needed for MSDEV to get the correct path setup when switching revisions of our software; however this doesn't help update the %PATH%. The MSDEV path can be queried with a query script. I don't have my example handy.
That is why builds in MSDEV sometimes work when builds using the command line don't, as the path to DLLs differ, and any custom build steps that run .exe will not work outside of the MSDEV environment unless the path is updated.
I have a script somewhere that reads the queries the registry to extract the MSDEV path and update PATH of a shell so that batch scripts doing nmake will work as they would inside the MSDEV shell environment. The problem with the REGISTRY QUERY is that the return arguments differ with different flavors of Windows (XP/SERVER2003/...).
One thing I just discovered is that Incredibuild works with the old VS6.0 MSDEV IDE. This is a game changer. It distributes builds. I'm evaluating it now, but it might be useful to anyone waiting for long VS6.0 builds.

Custom Build Step Paths Between x86 and x64 in Visual Studio

For reference, I'm using Visual Studio 2010.
I have a custom build step defined as follows:
if exist "$(TargetDir)"server.dll copy "$(TargetDir)"server.dll "c:\program files (x86)\myapp\server.dll"
This works great on my desktop, which is running 64-bit Windows. However, when I build on my laptop, c:\Program Files (x86)\ doesn't exist because it's running 32-bit Windows. I'd like to put in something that will work between both editions of Windows, since the project files are under version control and it's a real pain to change the paths every time I work on my laptop.
If this were a *nix environment I'd just create a symlink and be done with it. Any ideas?
You can put this in your project file:
<PropertyGroup>
<ProgramFiles32 Condition="Exists('$(PROGRAMFILES) (x86)')">$(PROGRAMFILES) (x86)</ProgramFiles32>
<ProgramFiles32 Condition="$(ProgramFiles32) == ''">$(PROGRAMFILES)</ProgramFiles32>
</PropertyGroup>
And then you can use $(ProgramFiles32) in your post build event.
For more information check this stackoverflow question.

How do I setup environment variable INCLUDE for Visual Studio 2005?

Is there a script that I can run that will setup my %INCLUDE% environment variable?
I'm running PC-lint and it can't find my include header files. I went through the documentation and it appears that I need to setup the %INCLUDE% environment variable.
I was wondering if there's an easy way to do it.
Visual Studio comes with a VCVARS32 (it might be renamed by now) batch file in its directory that will set all of these environment variables for you, and give you a shell with them set. It has a start menu entry, if you installed normally -- or maybe it came with the Platform SDK? It's been a while.
From the Microsoft documentation on the subject:
To run vcvars32.bat
At the command prompt, change to the \bin subdirectory of your Visual C++ installation.
Run vcvars32.bat by typing VCVARS32.
Barring that, you can permanently set your environment variables (per-system or per-user) in Control Panel, under System.

How to get Program Files Path in Visual Studio configuration

I followed this tutorial to make NUnit tests debugable in Visual Studio. In the debugging options I set "Start external program:" to C:\Program Files\NUnit 2.4.8\bin\nunit-x86.exe.
Is there a way to get the program files directory dynamically to avoid problems when other people work with this solution on their system?
The environment variable $PROGRAMFILES holds this. Most properties in visual studio allow you to use environment variable expansion like this: "$(PROGRAMFILES)\NUnit 2.4.8\"
%ProgamFiles% if using in a Windows path.

Resources