Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio post-build event macros are empty

In Visual Studio 2013 (or 2015), I have a particular project that in the post-build event, I'm trying to pass $(TargetDir) to a batch file.

The problem is, all the macros are empty, except for the macros beginning in "Solution". Also, all the macros are shown correctly in the "Edit Post-build Event Command line" dialog.

Example

echo ConfigurationName is "$(ConfigurationName)"

Results in

Configuration name is ""
like image 480
Nathan Goings Avatar asked Nov 05 '14 02:11

Nathan Goings


3 Answers

I had the same problem. According to https://social.msdn.microsoft.com/Forums/vstudio/en-US/179716e8-89eb-40ff-ba13-339e2d25d1c8/outdir-and-targetpath-macros-are-empty?forum=msbuild, you have to delete the PropertyGroup in the csproj file, and then to add the build event in Visual Studio again. enter image description here

After you add it again, it will be at the end of the csproj file, and the macros should work.

like image 188
Manuel Avatar answered Nov 11 '22 14:11

Manuel


Try $(Configuration) instead of $(ConfigurationMode), I was having this issue too and this solved it, although I don't know why it happens...

like image 35
Casey Avatar answered Nov 11 '22 14:11

Casey


Had the same problem when migrating a project file from old .NET framework format to SDK style.

It seems the structure of the PostBuildEvent changed and is not converted by the "upgrade assistant" tool.

This was the command before:

<PropertyGroup>
  <PostBuildEvent>echo ProjectDir: $(ProjectDir)</PostBuildEvent>
</PropertyGroup>

This is the new version:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="echo ProjectDir: $(ProjectDir)" />
</Target>

To do the migration: open the code file (right click on project, "Properties"). Then cut the post build snippet and save the file. Paste the snippet again - now it should have the new format.

like image 1
wknauf Avatar answered Nov 11 '22 12:11

wknauf