Search code examples
c#visual-studiobuildvisual-studio-2022

How to use $(ProjectName) an other macros in output path and other configurations?


I want to use the project's name in the output path property.

VisualStudio has a macro $(ProjectName).

enter image description here

is saved as <OutputPath>..\bin\Debug\Plugins\%24%28ProjectName%29\</OutputPath> in the project file.

This of course puts files into

..\bin\Debug\Plugins$(ProjectName)\

So how do I use the ProjectName in my output path?

I found several hints that I should replace the encoded string by

<OutputPath>..\bin\Debug\Plugins\$(ProjectName)</OutputPath>

But this does not have any effect. That string is neither displayed properly in Visual Studio nor does it result in the desired output path.

So what options do I have other than using build events?

..\bin\Debug\Plugins\$(Configuration) results in the expected output btw. so using macros is possible...


Solution

  • Using $(MSBuildProjectName) instead of $(ProjectName) solved it.