How to get Program Files Path in Visual Studio configuration - visual-studio

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.

Related

Access ProgramFilesFolder from Visual Studio post-build events

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)

Visual Studio Command Prompt (2010) can't find paths / includes

I am trying to use this tutorial from MS to verify I can build a .cpp file from the command line on my system. I seem to be having problems with my VS Command Prompt. It cannot find cl.exe or the needed include files. I added C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin and C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE to my path so it would find cl.exe. Now my error is:
test.cpp(1) : fatal error C1034: iostream: no include path set
Isn't the whole point of the VS Command Prompt to setup all these environment vars for me? Why isn't it setting it up properly?
I'm not sure exactly what your problem is but you might want to do the following to help determine the actual cause.
You may have noticed that the VS command prompt shortcut is a bat file. The first line is
#echo off
Change it to
REM #echo off
Run it again and see if you get any errors. If you don't it may be in one of the processor specific batch files to know which one that is look for the call to other batch like this.
C:\Program Files\Microsoft Visual Studio 10.0\VC>call "C:\Program Files\Microsof
t Visual Studio 10.0\VC\bin\vcvars32.bat"
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
Again REM out the #echo off in the batch and then run it again and see what errors you get.
Update from comment
The error ERROR: Cannot determine the location of the VS Common Tools folder
means your missing the Environment Variable %VS100COMNTOOLS% which is usually set to
"c:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\"
You can simply add it back using system properties -> Advanced -> New (under system variables)
See this superuser question for more on environment variables
I just figured it out. Thanks to Conrad Frix for the debugging tip.
It is surely due to some lovely security policy I have here on my workstation. Running the shortcut as administrator works. My account is a local admin account, but the admins do all kinds of weird stuff to our machines here...sigh. So, much of our development has to happen by "elevating".
Note, I was able to change the shortcut to run as under administrative privileges by selecting Properties->Advanced->Run as administrator.

Env vars for Visual Studio command prompt

I'm doing an RDP into a machine that has just the CLR installed, and doesn't have Visual Studio on it. Can I somehow load all the Visual Studio-specific environment variables on to the regular command prompt and convert it into the VS command prompt so that I'm able to build my projects via command line?
I looked at the vcvarsall.bat file. That calls the appropriate processor-specific batch file. Couldn't get any inputs from there.
Short of installing all VS, or tracing thru all the various batch files to find out what's getting set, you may be able to simply capture the env vars that are set.
Open up a VS command prompt, and run set > vars.bat
Then open up vars.bat, and put a set command in front of each line.
Not sure how much this will help, since you're going to be missing all the utilities that come with Visual Studio, but it does answer your question.
I don't recommend trying to copy only what you need. You'll need other header files, libraries, dlls, etc... You can instead install VS express edition.
If you are trying to debug a problem you can use remote debugging in Visual Studio or use WinDbg on the computer.

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.

nmake, visualstudio, and .mak files

I was given a C++ project that was compiled using MS Visual Studio .net 2003 C++ compiler, and a .mak file that was used to compile it. I am able to build it from the command line using nmake project.mak, but the compiler complains that afxres.h was not found. I did a little searching around and the afxres.h is in the Visual Studio directory in an includes file. Where am I supposed to specify to nmake where to look for this header file?
There should be an icon in your Start menu under Programs that opens a cmd.exe instance with all the correct MSVS environment variables set up for command line building.
Another option is running the appropriate vars batch file from a regular command prompt. The name and location varies from version to version. For VS2003, I believe it's
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat

Resources