Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is '$OutDir' defined in the script file in Visual Studio?

There are bunch of macros that Visual Studio uses in project settings which are listed here. I am unable to locate where are these macros or identifiers defined in the actual script file (not in project settings).

In my case I am trying to change the output folder for a project to that of the solution debug or release folder (one level up) but changing 'Output Directory' in project settings has no effect.

There is no mention of these macros in .vcxproj file either so I really don't know where they defined? I am most interested in the $(OutDir) that I want to change to solution debug/release folder. Does anyone knows where these are defined?

like image 949
zar Avatar asked Feb 20 '13 20:02

zar


People also ask

What is OutDir Visual Studio?

$(OutDir) is a Visual Studio Build Property Macro. You can see the values of macros using the Macros >> button in many Properties dialogs. For instance, in Properties->General->Output Directory, click the dropdown in the value text box, choose Edit..., and in the resulting dialog, click the Macros >> button.

How do I find the build path in Visual Studio?

Right-click on the project node in Solution Explorer and select Properties. Expand the Build section, and select the Output subsection. Find the Base output path for C#, and type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that folder instead.

How do I view macros in Visual Studio?

View the current properties and macrosSelect Edit and then in the Edit dialog box, choose the Macros button. The current set of properties and macros visible to Visual Studio is listed along with the current value for each.

How do I change the file path in Visual Studio?

In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.


2 Answers

The majority of those macros are defined in the MSBuild targets file that is included in every VS2010 project. Somewhere in your project file, probably near the bottom, you will find a line like this:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

If you follow the chain of path variables back you will eventually find the folder that contains Microsoft.Cpp.targets, which itself will contain:

    <Import Project="Microsoft.Common.targets" />

In this file you'll find the following note:

Several properties must be set in the main project file, before using this .TARGETS file. However, if the properties are not set, we pick some defaults.

OutDir: Indicates the final output location for the project or solution. When building a solution,

The defaults that MSBuild picks is to default $(OutDir) to $(OutputPath) if it's not explicitly set. $(OutputPath) is defined in your project file, so changing that property before the targets file gets included will change the default value of $(OutDir). You can also just specify a value for $(OutDir) on the msbuild command line using /p:OutDir=bin\DebugElsewhere or whatever and that will override whatever defaults MSBuild wants to use. (This is what TFSBuild does, for example, to get everything in a solution dumped into the same folder.)

Also, for possible future reference, most of the remaining macros are also defined in this file, somewhat further down:

<PropertyGroup>
  <TargetDir Condition="'$(OutDir)' != ''">$([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`))))</TargetDir>
  <TargetPath Condition=" '$(TargetPath)' == '' ">$(TargetDir)$(TargetFileName)</TargetPath>
  <ProjectDir Condition=" '$(ProjectDir)' == '' ">$(MSBuildProjectDirectory)\</ProjectDir>
  <ProjectPath Condition=" '$(ProjectPath)' == '' ">$(ProjectDir)$(ProjectFileName)</ProjectPath>
      .
      .
      .
</PropertyGroup>
like image 38
Michael Edenfield Avatar answered Oct 05 '22 22:10

Michael Edenfield


In Visual Studio 2010, the main project settings will define an output folder, the macro that is set from this folder assignment is $(OutDir). There are other predefined macros that you cannot modify, but this one you can.

If I understand what you're trying to do, then follow these steps:

  1. Open your project's properties dialog.
  2. At the top of the dialog are two drop-lists, one for "Configuration" and one for "Platform". Select the "All" option for the Configuration list.
  3. On the General settings page at the top is a folder designated the "Output Directory". Change it to the following (quotes optional) "$(SolutionDir)$(Configuration)\" . The trailing backslash is important. This is the setting that $(OutDir) eventually picks by the way.
  4. Open the "Linker" item in the left-tree. then select "General" settings.
  5. In the right-pane at the top of the list is the "Output File" option. It should default to "$(OutDir)$(TargetName)$(TargetExt)". If it isn't, then set it as such.
  6. Rebuild the world.

Note: If you have multiple platform targets (win32 and x64 for example) this is a little more involved, but not that bad. Hope this helps.


EDIT OP also would like the PDB and incremental link files not to be published in the same folder, but does want the import library published there. So.....

To change the location where the PDB file is created:

  1. Open the project file, Once again select the "All" option to change all build configuration targets (see #2 above).
  2. Select the Linker/Debugging settings in the left-tree.
  3. Second item from the top should be the "Generate Program Database File" setting. Change it to "$(IntDir)$(TargetName).pdb"

The incremental link file must be (to my knowledge) in the same folder as the final target. You can disable incremental linking if you want, however. This is done at the following location:

  1. Open the project file, Once again select the "All" option to change all build configuration targets (see #1 above).
  2. Select the Linker/General settings of the project.
  3. Fourth item down should be "Enable Incremental Linking". Set it to No.
  4. If you do disable incremental linking, you cannot use the Edit & Continue PDB debug format feature of Visual Studio, but the UI is too dumb to fix this for you when you disable incremental linking, so.. Select C++/General in the project pane. then, if it is set to "Program Database for Edit/Continue" switch it to Program Database /Zi.

To move where the import library is built.

  1. Open the project file, Once again select the "All" option to change all build configuration targets (see #2 above).
  2. Select Linker/Advanced
  3. In the right pane will be an item about halfway down, Import Library. Change it to "$(OutDir)$(TargetName).lib"

Don't ask me how to get rid of the export-list file (.exp) because I honestly don't know.

like image 128
WhozCraig Avatar answered Oct 05 '22 23:10

WhozCraig