.net MSBuild ProjectReference:private ("Copy Local") - 允许的值和行为是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26168401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MSBuild ProjectReference:private ("Copy Local") - what are the allowed values and behaviour?
提问by Martin Ba
TL;DRIs there any official documentation that describes in detail how the <private>/ "Copy Local" option works with MSBuild? And what values are supposed to go into it?
TL;DR是否有任何官方文档详细描述了<private>/"Copy Local" 选项如何与 MSBuild 配合使用?它应该包含哪些价值观?
When you add a projectreferencefrom one project in Visual Studio to another, it will add a <ProjectReference Include=".....csproj">to the .csprojMSBuild file.
当您将Visual Studio 中一个项目的项目引用添加到另一个项目时,它将添加<ProjectReference Include=".....csproj">到.csprojMSBuild 文件中。
When you add a filereferencefrom one project in Visual Studio to an assembly file in the file system, it will add a <Reference Include="Foo"> <HintPath>....Foo.dll</HintPath> ...to the .csprojMSBuild file.
当您将Visual Studio 中一个项目的文件引用添加到文件系统中的程序集文件时,它将添加<Reference Include="Foo"> <HintPath>....Foo.dll</HintPath> ...到.csprojMSBuild 文件中。
In bothcases, for the Visual Studio Setting Copy Local = True|False, a sub-element <Private>True</Private>or <Private>False</Private>will be added.
在这两种情况下,对于 Visual Studio Setting Copy Local = True|False,都会添加一个子元素<Private>True</Private>or <Private>False</Private>。
Referenceand ProjectReferenceseem to be documented under Common MSBuild Project Items:
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> 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
You will notice that,
你会注意到,
ProjectReferencedoesn't documentthe<private>Item at allReferencedoes not listTrueorFalseas possible values.
ProjectReference根本不记录该<private>项目Reference没有列出True或False作为可能的值。
So. Huh?Is there any official documentation (I'll be more than happy with a good blog entry) that describes in detail how the <private>option works? Are the doc's just dead wrong or is there something more to it?
所以。嗯?是否有任何官方文档(我会对一个好的博客条目感到非常满意)详细描述了该<private>选项的工作原理?医生是完全错误的还是有更多的东西?
Example snippet from my VS 2013 Express here:
来自我的 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>
...
回答by Matt Slagle
For Reference and ProjectReference items, the accepted values for Private are: True or False
对于 Reference 和 ProjectReference 项,Private 的可接受值为:True 或 False
This property in msbuild corresponds with the project reference property in VS as Copy Local.
msbuild 中的此属性对应于 VS 中的项目引用属性为 Copy Local。
I got the above answer by manually setting the reference properties in VS and viewing the xml. I couldn't find official documentation of the Private item metadata.
我通过在 VS 中手动设置引用属性并查看 xml 得到了上述答案。我找不到私有项目元数据的官方文档。
Checking the docs at https://msdn.microsoft.com/en-us/library/bb629388.aspxshows the accepted values as Never, Always, and PreserveNewest. These seem to be wrong and only available for the CopyLocal metadata, which is used on Content, None, and other file items.
检查https://msdn.microsoft.com/en-us/library/bb629388.aspx 上的文档将接受的值显示为 Never、Always 和 PreserveNewest。这些似乎是错误的,仅适用于 CopyLocal 元数据,该元数据用于 Content、None 和其他文件项。

