【问题标题】:How not to hard code the path of the DocumentationFile path in Visual Studio 2019 .csproj如何不对 Visual Studio 2019 .csproj 中的 DocumentationFile 路径的路径进行硬编码
【发布时间】:2026-01-02 13:15:01
【问题描述】:

如何动态设置DocumentationFile 来引用当前用户的主盘?是否有要设置的$ 变量?我将我的项目签入到 TFS。当我团队的另一个成员将源代码克隆到他的工作站时,.csproj 中的以下节点仍然引用我硬盘上的文件夹,并且编译失败。到目前为止,我们必须手动编辑.csproj 文件。谢谢。

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

【问题讨论】:

    标签: visual-studio path environment-variables visual-studio-2019


    【解决方案1】:

    感谢您的回复。它引导我找到 $(MSBuildProjectDirectory) 变量。这是 PropertyGroup

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

    【讨论】:

      【解决方案2】:

      Visual Studio 中有一个list 的常用宏。

      你可能想要的是$(ProjectDir)

      您还可以使用存储在注册表中的环境变量。见this

      例子:

      &lt;FinalOutput&gt;$(BIN_PATH)\MyAssembly.dll&lt;/FinalOutput&gt;

      <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>
      

      【讨论】:

        最近更新 更多