Private设置对MSBuild项目文件中的ProjectReference执行了什么操作?

Bil*_*eal 103 msbuild visual-studio

我前几天在项目文件中看到了这个:

<ProjectReference Include="Foo\Bar\Baz.csproj">
    <Project>{A GUID HERE}</Project>
    <Name>Baz</Name>
    <Private>False</Private> <!-- ??? -->
    <ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
Run Code Online (Sandbox Code Playgroud)

a中的每个节点ProjectReference似乎都是自解释的(引用的项目文件,GUID,要在解决方案资源管理器中显示的名称,以及当前项目是否应该链接到引用的项目)Private,并且" 公共MSBuild项目项"页面没有t记录这个值.(有一个Private文件化的设置Reference,而不是ProjectReference-但它有Never,AlwaysPreserveNewest设置,而不是真假)

这个设置有什么作用?

Mit*_*tch 114

Private标签维护用户覆盖在Visual Studio中引用文件夹中的"复制本地"复选框.它控制是否从GAC使用引用,或者是否将引用的程序集复制到构建目录.

虽然我找不到任何这种效果的MSDN文档(quelle surprise),但从行为和应用它的注释中Microsoft.Common.CurrentVersion.targets:1742可以看出这一点:

  <!--
    ============================================================

                                        ResolveAssemblyReferences

    Given the list of assemblies, find the closure of all assemblies that they depend on. These are
    what we need to copy to the output directory.

        [IN]
        @(Reference) - List of assembly references as fusion names.
        @(_ResolvedProjectReferencePaths) - List of project references produced by projects that this project depends on.

            The 'Private' attribute on the reference corresponds to the Copy Local flag in IDE.
            The 'Private' flag can have three possible values:
                - 'True' means the reference should be Copied Local
                - 'False' means the reference should not be Copied Local
                - [Missing] means this task will decide whether to treat this reference as CopyLocal or not.

        [OUT]
        @(ReferencePath) - Paths to resolved primary files.
        @(ReferenceDependencyPaths) - Paths to resolved dependency files.
        @(_ReferenceRelatedPaths) - Paths to .xmls and .pdbs.
        @(ReferenceSatellitePaths) - Paths to satellites.
        @(_ReferenceSerializationAssemblyPaths) - Paths to XML serialization assemblies created by sgen.
        @(_ReferenceScatterPaths) - Paths to scatter files.
        @(ReferenceCopyLocalPaths) - Paths to files that should be copied to the local directory.
    ============================================================
    -->
Run Code Online (Sandbox Code Playgroud)

  • 正如Mitch所说,它控制属性中的Copy Local设置以供参考.此外,它只能包含值True和False.如果不存在则假定默认值为True (7认同)
  • @xmedeko,这是对的.我不确定@GPR在哪里"如果不存在则假定默认值为True",因为答案明确说"[Missing]意味着此任务将决定是否将此引用视为CopyLocal".大多数逻辑都在[`msbuild\Reference.cs:949`]中(https://github.com/Microsoft/msbuild/blob/master/src/Tasks/AssemblyDependency/Reference.cs#L949) (6认同)
  • 如果缺少“ &lt;Private&gt;”,则它不等同于“ True”。搜索“ MSBuild CopyLocal错误”。例如,请参阅/sf/ask/79257041/ (2认同)