简体   繁体   English

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

[英]MSBuild ProjectReference:private (“Copy Local”) - what are the allowed values and behaviour?

TL;DR Is there any official documentation that describes in detail how the <private> / "Copy Local" option works with MSBuild ? TL; DR是否有任何官方文档详细描述了<private> /“Copy Local”选项如何与MSBuild一起使用 And what values are supposed to go into it? 应该考虑什么价值?


When you add a project reference from one project in Visual Studio to another, it will add a <ProjectReference Include=".....csproj"> to the .csproj MSBuild file. 项目引用从Visual Studio中的一个项目添加到另一个项目时,它会将<ProjectReference Include=".....csproj">.csproj MSBuild文件中。

When you add a file reference from 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 .csproj MSBuild file. 当您 Visual Studio中的一个项目文件引用添加到文件系统中的程序集文件时,它将添加<Reference Include="Foo"> <HintPath>....Foo.dll</HintPath> ....csproj MSBuild文件。

In both cases, for the Visual Studio Setting Copy Local = True|False , a sub-element <Private>True</Private> or <Private>False</Private> will be added. 这两种情况下,对于Visual Studio设置Copy Local = True|False ,将添加子元素<Private>True</Private><Private>False</Private>

Reference and ProjectReference seem to be documented under Common MSBuild Project Items : ReferenceProjectReference似乎下记录在案常见的MSBuild项目项

 <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, 你会注意到,

  1. ProjectReference doesn't document the <private> Item at all ProjectReference 根本不记录 <private>
  2. Reference does not list True or False as possible values. Reference 不会将 TrueFalse列为可能的值。

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? 是否有任何官方文档(我会对一篇好的博客文章感到满意)详细描述了<private>选项的工作原理? Are the doc's just dead wrong or is there something more to it? 这些医生是错误的还是还有更多的东西?


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

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. 我通过在VS中手动设置参考属性并查看xml得到了上述答案。 I couldn't find official documentation of the Private item metadata. 我找不到私有项元数据的官方文档。

Checking the docs at https://msdn.microsoft.com/en-us/library/bb629388.aspx shows the accepted values as Never, Always, and PreserveNewest. 检查文档位于https://msdn.microsoft.com/en-us/library/bb629388.aspx,显示可接受的值为Never,Always和PreserveNewest。 These seem to be wrong and only available for the CopyLocal metadata, which is used on Content, None, and other file items. 这些似乎是错误的,仅适用于CopyLocal元数据,该元数据用于Content,None和其他文件项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM