How can I find out the value of $(ProjectDir)? - visual-studio

Where can I execute and find out the value of $(ProjectDir)?

To find out what it is right now (rather than at build time, where it may be different depending on what is going on):
right click on your project in the Solution Explorer, select Properties
select the Build Events tab
click the Edit pre-build or Edit post-build button, either is fine
in the window that pops up, click the Macros button
scroll down the list till you find ProjectDir, in the next pane is its actual value

Do a pre/post build step.
Example:
echo $(ProjectDir)

The answer from slugster did not work for me (most possible my fault).
In Visual Studio 2008
right click on your project in the Solution Explorer, select Properties
Go to Configuration Properties and then to Debugging
Click on the arrow in the Command Field and click the Edit Button
In Edit clik "Macros>>" You will see there the values of ProjectDir... etc..

In Visual Studio 2015, you can find ProjectDir by clicking on Macros in additional Include Directories and then clicking on Macros (for me there was nothing in Build Events) :

Open the project properties (Alter+Enter) and then go to "Build Events", select any of the build events, then select "Command Line", click "Edit", then press the "Macros >>" button.

Same here in Visual Studio 2019, you can find ProjectDir by clicking on Macros in additional Include Directories and then clicking on Macros (for me there was nothing in Build Events), like the answer in above Visual Studio 2015.

For me it was the path to the directory containing *.vcxproj file.
From https://learn.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties:
The directory of the project (defined as drive + path); includes the
trailing backslash ''.

Tools -> External Tools
create command for Powershell.exe or Csc.exe
copy exe to c:\ for shorter paths
Name it and check Prompt for arguments
now click Tools -> Click name of your tool
with dialog displayed, click Argument button and choose $(ProjectDir) or whatever.
Your $(ProjectDir) is displayed in Command Line after Powershell.exe or csc.exe
Clear Arguments and click argument button again
Your next selection is display again after command (repeat to view all 16 environment variables.
this is without executing command but command is required to save.
if you use csc.exe from this path
"C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\Roslyn\csc.exe"
copy Roslyn folder to
C:\Roslyn
csc.exe needs other files to work, you need whole directory.
Roslyn folder is only 34 Mb

Related

Is there a way to set a keyboard shortcut to open containing folder of a selected file in Solution Explorer in Visual Studio?

When I click on a C++ project in Visual Studio, I get this menu:
And so I can quickly press Alt+F,F(Command ProjectandSolutionContextMenus.Project.OpenFolderinFileExplorer) to open the folder of the project.
I also found that I can open containing folder if I open the file in the Text Editor in Visual Studio:
I bound it to Alt+F,F as well. I set it to only be active in Text Editor, it's the File.OpenContainingFolder command.
But when I click on files inside the project in the Solution Explorer, there is no context menu:
I tried to make the File.OpenContainingFolder command global, but it still doesn't work in the Solution Explorer when I just click on a file once. If I double click it and open it in the text editor, it works.
And I can't find a command in the Keyboard section in options of Visual Studio to open containing folder of a file selected in the Solution Explorer.
Maybe someone knows how to do it?
You can create an external tool menu item, and then bind a shortcut to that item.
Go to Tools > External Tools.
Click Add.
In Title edit box type Show in Explorer.
In Command edit box type explorer.exe.
In Arguments edit box type /select, $(ItemPath). There is a space between a comma and a dollar sign.
Click OK.
Make note at the position of the new command in the list. It could be first, it could be fifth, or something else. Let's assume it's the fifth one.
Assign a shortcut to the command Tools.ExternalCommand5. Restrict the shortcut to Solution Explorer.
That's it.

How to make visual studio project into exe file and give UI

I have a code which detects the FACES from the image file (C++ file). I am using Visual Studio-2010 and OpenCV-2.4.10 for this project.
Now I want to create an EXE file and I want to give User Interface which will ask the user to upload an image and produces the Output image back on to the User Interface.
So how can I do this.
Please help me in this regards.
Thankz in advance.
To build a solution that's open in Visual Studio and selected in Solution Explorer, you can:
On the menu bar, choose Build, Build Solution.
Or, in Solution Explorer, open the shortcut menu for the solution and then choose Build Solution.
Or, press F7. (This is the default keyboard shortcut for the C/C++ development settings.)
Or, in the Command Window (on the menu bar, choose View, Other Windows, Command Window), enter Build.BuildSolution.
Or, in the Quick Launch box, enter build build solution.
To build a project that's selected in Solution Explorer, you can:
On the menu bar, choose Build, Build .
Or, in Solution Explorer, open the shortcut menu for the project and then choose Build.
Or, in the Command Window (on the menu bar, choose View, Other Windows, Command Window), enter Build.BuildOnlyProject.
Or, in the Quick Launch box, enter build project only build only .
You can then navigate to the build location, either /debug or /release depending on the option you have chosen, you will find your .exe there
You need to use Publish from right-clicked project in Solution Explorer

Is there a Visual Studio option or add-on to add an "Open Explorer Here" when I right click on a project in the solution folder?

When I right click on a project in the solution explorer I'd like to be able to select an option that would open a new windows "Explorer" that lists the contents of the build directory. I'd settle for the project directory... but getting me into /bin/x86/Debug vs /bin/x86/Release based on the active build configuration would be major bonus.
I find myself manually navigating to that folder fairly often for various reasons - usually on Utility applications which don't have installers / cmd line build scripts etc
I currently use 2005 express. But, am open to upgrading.
A couple things that might be close enough:
add an "external tool" to the Tools menu. In the "Tools | External Tools..." dialog:
Click "Add" and give the new tool whatever name you want
Command: %systemroot%\system32\cmd.exe
Argument: /k "c:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86
Initial directory: $(TargetDir) // (or whatever appropriate macro)
Right click on a open document's tab and select "Open containing folder"
My VS 2005 Standard IDE already had a "Visual Studio 2005 Command Prompt" tool, but it landed the command window in the VC installation directory. Changing the "Argument" and "Initial directory" fields as above made it land in the project's target directory.
The drawbacks are they don't show up in the right menu for the project and they might not land you exactly where you want, but they should land you pretty close.
No sure this is what you want but the "Open file" icon will pop up a FileOpen dialog in the project folder. From there you can right click the Release or Debug folders to open them in an Explorer (and Cancel the dialog).

Blame source file from within visual studio

I'm using AnkSVN within Visual Studio 2010, and it covers ~95% of my SVN needs. The biggest missing feature is that I can't find a way to blame a file from directly within VS. The workaround I currently use is to right click on the file within the tablist, and select Open Containing Folder, and then right clicking on the file in Explorer to call Blame.
It's called Annotate in AnhkSVN.
Subversion -> Annotate in the context menu.
I didn't like AnkhSVN's Annotate feature. So I used the following:How to integrate TortoiseSVN into Visual Studio.
Content from above url:
If you're using Visual Studio, you can integrate TortoiseSVN commands to various context menus.
The first step is to add the TortoiseSVN commands as external tools, under the menu TOOLS->External Tools....
Add the name of the command, the path to TortoiseProc.exe and then the parameters for the command.
Use the VS variables wherever needed. Since I add my commands to the context menu of the open file tab, here's the parameters I used:
/command:blame /path:"$(ItemPath)" /line:$(CurLine)
/command:diff /path:"$(ItemPath)"
/command:log /path:"$(ItemPath)"
Notice the /line: parameter: this will make TortoiseBlame automatically scroll to the same line the cursor is located in the opened file in Visual Studio.
Now to add those new commands to the file tab context menu, go to TOOLS->Customize..., select the Commands tab, click the radio button Context menu and then select Other Context Menus | Easy MDI Document Window.
Now you have to select the commands. Problem is that the custom commands are not shown with their title but only as External Command X with X being the number of the external command.
In my case, the commands were number 9-11, you might have to do some trial-and-error here. Just add the commands you think are the ones you added and then check if the right ones show up in the context menu.
NOTE: In Visual Studio 2010 to add a command to the right-click menu of a document’s tab, first you’ll need to right-click on a Visual Studio document tab to work around a Visual Studio bug. (Otherwise the Easy MDI Document Window context menu doesn’t show up in the Customize dialog.) Source

Output path for build in visual studio 2010

I need to output the project dll in program files. "$(PROGRAMFILES)\Microsoft..." It is not building in program files, but in the project itself in a folder called "$(PROGRAMFILES)"!
How do I build in program files??
In Solution Explorer, right click your project, click "Unload Project"
After the project unloads, right click on it again, click "Edit MYPROJECT.csproj"
In the XML editor window that opens, change <OutputPath> elements to <OutputPath>$(ProgramFiles)</OutputPath> -- either all of them, or only those for the configurations that interest you
Save and close
Right click on project again, choose "Reload Project"
Done!
And if you just made a new environment variable, reload visual studio as well, else it will use 'C:\' instead of your variable content.
This sounds like a good case for a post-build event that copies the project output to the folder you want:
copy $(TargetPath) $(PROGRAMFILES)\Microsoft...
right click on project select properties. Select Build tab you have output section
In output path give the specific path for you program file/microsoft. This should work. I Tested it.
You need to open the csproj file in a text editor and manually enter your environment variables in the OutputPath section. Visual Studio escapes the '$', '(' and ')' when you try to do this from the IDE.

Resources