Home > OS >  How not to hard code the path of the DocumentationFile path in Visual Studio 2019 .csproj
How not to hard code the path of the DocumentationFile path in Visual Studio 2019 .csproj

Time:09-21

How to set the DocumentationFile dynamically to reference the current user's home drive? Is there a $ variable to set? I checked in my project to TFS. When another member of my team clones the source code to his workstation, the following node in the .csproj still references to the folder on my hard drive, and fails the compilation. So far we have to manually edit the .csproj file. Thanks.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>C:\Users\myName\source\repos\orgName\solutionName\projectName\.xml</DocumentationFile>
  </PropertyGroup>

CodePudding user response:

Thanks for your reply. It leads me to find the $(MSBuildProjectDirectory) variable. Here is the PropertyGroup

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>$(MSBuildProjectDirectory)\.xml</DocumentationFile>
  </PropertyGroup>

CodePudding user response:

There is a list of common macros in Visual Studio.

The one you probably want is $(ProjectDir)

You can also use environment variables stored in the registry. See this.

Examples:

<FinalOutput>$(BIN_PATH)\MyAssembly.dll</FinalOutput>

<Project DefaultTargets="FakeBuild">
    <PropertyGroup>
        <FinalOutput>$(BIN_PATH)\myassembly.dll</FinalOutput>
        <ToolsPath Condition=" '$(ToolsPath)' == '' ">
            C:\Tools
        </ToolsPath>
    </PropertyGroup>
    <Target Name="FakeBuild">
        <Message Text="Building $(FinalOutput) using the tools at $(ToolsPath)..."/>
    </Target>
</Project>
  • Related