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

1

12

I have an old project in non-SDK-style format generated by Visual Studio. It contains a post-build event in which $(ProjectDir) and $(TargetDir) are used.

I am currently transforming the project into a new SDK-style project (csproj file). If I just turn that post build event into a Target Exec Command, I get errors. After prefixing the command with echo I could see why: The values $(ProjectDir) and $(TargetDir) were both empty.

I figured out that replacing $(ProjectDir) by $(MSBuildProjectDirectory)\ gives the desired result, but what is the equivalent for $(TargetDir)?


Note that I am not using Visual Studio for the new SDK-style project. I am using Visual Studio Code. It seems that Visual Studio sets values for $(ProjectDir)/$(TargetDir)/others, but Visual Studio Code does not. I build my project using dotnet build.

Trident answered 10/2, 2022 at 10:9 Comment(0)
T
16

Seems I found the answer 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.).

So I believe $(TargetDir)would be $(MSBuildProjectDirectory)\$(OutputPath).

Trident answered 10/2, 2022 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.