MSBuild ProjectReference:private("Copy Local") - 允许的值和行为是什么?

Mar*_* Ba 59 .net msbuild copy-local visual-studio msbuild-projectreference

TL; DR是否有任何官方文档详细描述<private>/"复制本地"选项如何与MSBuild一起使用?应该考虑什么价值?


当你添加一个项目引用从一个项目在Visual Studio中的另一个,它会加入<ProjectReference Include=".....csproj">.csproj的MSBuild文件.

当您 Visual Studio中的一个项目文件引用添加到文件系统中的程序集文件时,它将添加<Reference Include="Foo"> <HintPath>....Foo.dll</HintPath> ....csprojMSBuild文件.

这两种情况下,Visual Studio的设置Copy Local = True|False,一个子元素<Private>True</Private><Private>False</Private>将增加.

Reference并且ProjectReference似乎在Common MSBuild Project Items下记录:

<ProjectReference>
  Represents a reference to another project.

  Item Name    Description
  -------------------------
   Name         ...
   Project      ...
   Package      ...

<Reference>
  Represents an assembly (managed) reference in the project.

  Item Name     Description
  --------------------------
   HintPath      Optional string. Relative or absolute path of the assembly.
   Name          ...
   ...
   Private       Optional string. Determines whether to copy the file to the output directory. 
                 Values are:
                     1. Never
                     2. Always
                     3. PreserveNewest
Run Code Online (Sandbox Code Playgroud)

你会注意到,

  1. ProjectReference 根本不记录<private>项目
  2. Reference 没有列出 TrueFalse作为可能的值.

所以.咦?是否有任何官方文档(我会对一篇好的博客文章感到满意)详细描述该<private>选项的工作原理?这些医生是错误的还是还有更多的东西?


来自我的VS 2013 Express的示例代码段:

...
  <ItemGroup>
    <Reference Include="ClassLibrary2">
      <HintPath>C:\Somewhere\ClassLibrary2.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="System" />
...
  <ItemGroup>
    <ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj">
      <Project>{861dd746-de2e-4961-94db-4bb5b05effe9}</Project>
      <Name>ClassLibrary1</Name>
      <Private>False</Private>
    </ProjectReference>
...
Run Code Online (Sandbox Code Playgroud)

小智 19

对于Reference和ProjectReference项,Private的可接受值为:True或False

msbuild中的此属性与VS中的项目引用属性对应为Copy Local.

我通过在VS中手动设置参考属性并查看xml得到了上述答案.我找不到私有项元数据的官方文档.

检查文档位于https://msdn.microsoft.com/en-us/library/bb629388.aspx,显示可接受的值为Never,Always和PreserveNewest.这些似乎是错误的,仅适用于CopyLocal元数据,该元数据用于Content,None和其他文件项.

  • 看来 https://msdn.microsoft.com/en-us/library/bb629388.aspx 上的文档已更新为:Private:Optional boolean。指定是否应将引用复制到输出文件夹。此属性与 Visual Studio IDE 中引用的“复制本地”属性相匹配。 (2认同)