DEV Community

Wahid Bitar
Wahid Bitar

Posted on

Answer: Find MSBuildProjectDirectory Parent Directory

In case someone like me is still interested in this, here is how I did it in 2022 ^_^

<PropertyGroup> 
    <ParentFolderPath>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</ParentFolderPath>
    <ParentFolder>$([System.IO.Path]::GetFileName($(ParentFolderPath)))</ParentFolder>
...
</PropertyGroup> 

I'm using this technique to auto-name the assemblies and default namespaces in the complex solutions.

<AssemblyName>$(ParentFolder).$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(ParentFolder).$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>

Top comments (0)