$(TargetDir) 替代 SDK 样式的项目(类似于“$(MSBuildProjectDirectory)\”对于“$(ProjectDir)”)

$(TargetDir) replacement for SDK-style projects (analogue to "$(MSBuildProjectDirectory)\" for "$(ProjectDir)")

我有一个由 Visual Studio 生成的非 SDK 样式格式的旧项目。它包含一个 post-build 事件,其中使用了 $(ProjectDir)$(TargetDir)

我目前正在将项目转换为一个新的 SDK 风格的项目(csproj 文件)。 如果我只是将 post 构建事件转换为 Target Exec Command,我会收到错误消息。在命令前加上 echo 前缀后,我明白了原因:值 $(ProjectDir)$(TargetDir) 都是空的。

我发现用 $(MSBuildProjectDirectory)\ 替换 $(ProjectDir) 可以得到想要的结果,但是 $(TargetDir) 的等价物是什么?


请注意,我没有将 Visual Studio 用于新的 SDK 样式项目。我正在使用 Visual Studio 代码。似乎 Visual Studio 为 $(ProjectDir)/$(TargetDir)/others 设置了值,但 Visual Studio 代码没有。我使用 dotnet build.

构建我的项目

看来我找到了答案here:

The value of TargetDir is computed as the full absolute path of whatever you specify as the Output Path for your project, which is stored in the OutputPath property directly in your project file (.CSPROJ, .VBPROJ, etc.).

所以我认为 $(TargetDir) 会是 $(MSBuildProjectDirectory)$(OutputPath)