【发布时间】:2014-11-27 21:20:53
【问题描述】:
TL;DR 是否有任何官方文档详细描述了<private> /“复制本地”选项如何与 MSBuild 一起工作?应该包含哪些价值观?
当您将 add a project reference 从 Visual Studio 中的一个项目转移到另一个项目时,它会将 <ProjectReference Include=".....csproj"> 添加到 .csproj MSBuild 文件中。
当您从 Visual Studio 中的一个项目add a file reference 到文件系统中的程序集文件时,它会将<Reference Include="Foo"> <HintPath>....Foo.dll</HintPath> ... 添加到.csproj MSBuild 文件中。
在两种情况中,对于 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
你会注意到,
-
ProjectReference没有记录<private>项目 -
Reference没有列出True或False作为可能的值。
所以。嗯? 有没有详细描述<private> 选项如何工作的官方文档(我会很高兴有一篇好的博客文章)? 文档是完全错了还是有其他问题?
这里是我的 VS 2013 Express 中的示例 sn-p:
...
<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>
...
【问题讨论】:
-
有趣的一点(仍然找不到确切的问题)。我发现的唯一一个使用 Private 值的地方是 Microsoft.Common.targets 中的第 3612 行: Condition="'@(_MSBuildProjectReferenceExistent)' != '' 和 '$(_GetChildProjectCopyToOutputDirectoryItems)' == 'true'和 '%(_MSBuildProjectReferenceExistent.Private)' != 'false' 和 '$(UseCommonOutputDirectory)' != 'true'"
-
或者这个元数据也可能在 MSBuild 任务的某个地方被转换为更常见的“CopyLocal”——不确定我是否要反编译并一一扫描它们。无论如何,我同意 - 它没有记录,而且 .targets 文件中也没有提供太多关于它的信息......
-
@AlexeyShcherbak - 感谢您的信息。我试着编辑了一下,所以这里有一个实际的问题:-)
-
回答您的问题 - 我认为文档并非 100% 正确。但我可以接受 - msdn 文档不时会发生这种情况。我们可以花费 X 时间并将“私有”元数据跟踪到某些任务 - 它被复制\使用,但正如我所说 - 我的直觉是我们最终会发现它接近 CopyLocal 或非常相似的东西。这只是 MSBuild 中的不一致。您是否有任何实际任务需要了解此元数据的确切行为?
-
我的猜测是 VS 开发人员最初将其称为“Private Copy”,一些早期的 Alpha 测试人员表示“Private”可能会让人们认为它就像源代码中的
private修饰符。因此,作为高效的开发人员,他们更改了 VS UI 中的标签并保留了内部引用。我们中有多少人在一个数据库列或代码变量被“重新设计”以包含一些稍微不同的数据但从未重构名称的系统上工作?如果你不举手,你就从来没有在企业级开发商店工作过! :-)
标签: .net visual-studio msbuild copy-local msbuild-projectreference