.net-corevisual-studio-2017post-build-eventpre-build-eventbuild-events

Pre- Post- Build Event Variables in Visual Studio are Empty


Have a .NET Core app that I'm trying to use $(ProjectDir) with and when I attempt to pass in that macro, I get an empty value. I tried what was suggested in Issue 26748846, but that didn't seem to solve my issue.


Solution

  • This happens because in .NET Core projects, the pre- and post build macros are set too early and the $(ProjectDir) property is not yet available. Note that pre- and post build macros are deprecated and should be replaced by proper targets (see https://github.com/dotnet/project-system/issues/1569).

    A quick fix would be to replace $(ProjectDir) with $(MSBuildProjectDirectory)\.