4

I have inherited a C# solution where the projects have a configured "Post-build command line". In this command line, there are a couple of user-defined property sheet macros that copy various output files to specific folders. However, when I build any of the projects, the macros are incorrectly defined as empty strings.

E.g.

copy "$(TargetPath)" "$(PluginPath)\$(ConfigurationName)"

The standard macros, e.g. $(TargetPath), work great, but I can't see any way of controlling the value of the user-defined macros. In the post-build step there is a "Macros >>" button which shows the standard macros, but there's no way that I can see to either to edit their values or add new, user defined macros.

It looks like the previous developer had this working, so what am I missing?

I have read that macros can be defined in .vsprops files, but only Visual C++ projects support these files. When I look in the Property Manager window, I see only the message "No Visual C++ project is loaded". (I'd expect that user-defined property sheet macros would be equally as useful in the "Post-build command line" of C++ projects as they are in C# or projects in any language.)

Tim Williams
  • 873
  • 8
  • 10

2 Answers2

5

With a quick search I found this, it might help.

Update: After adding the following to my .csproj project file, I can use the PluginPath as a macro in the post-build command line with copy "$(TargetPath)" "$(PluginPath)\$(ConfigurationName)" (tested in Visual Studio 2008)

    ...
    <PluginPath>C:\apps\</PluginPath>
</PropertyGroup>
Community
  • 1
  • 1
JTK
  • 191
  • 4
  • 12
  • Excellent. Just what I needed. I also found that to avoid editing the project file directly, instead, one can add the macros to a separate .csproj.user file, thus the entire file is simply: ` ShowAllFiles the property value ` **One note: after changing this file, the project needs to be reloaded.** – Tim Williams Jun 18 '14 at 10:33
  • I know this is bit old, but should that macro be visible on macros list in Edit Post-build dialog? I was able to add my own macro, but I would like to have in on list. – Misiu May 27 '15 at 15:01
1

You can follow any solution as described below.

  1. Create batch file and insert following code

    set MY_INCLUDES_DIR=D:\MyIncludes call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat" "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" D:\MySolution.sln

Start Visual studio solution by double clicking this file. Advantage of this solution is all projects can use same environment variable.

  1. Define following xml tag in visual studio project file.

    <PropertyGroup>
        <MY_INCLUDES_DIR>D:\MyIncludes\</MY_INCLUDES_DIR>
    </PropertyGroup>
  2. Create system environment variable named MY_INCLUDES_DIR and simply use $(MY_INCLUDES_DIR) in visual studio.

Sagar Gupta
  • 131
  • 2
  • 8