我前几天在项目文件中看到了这个:
<ProjectReference Include="Foo\Bar\Baz.csproj">
<Project>{A GUID HERE}</Project>
<Name>Baz</Name>
<Private>False</Private> <!-- ??? -->
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
ProjectReference
中的每个节点似乎都是自解释的(引用的项目文件,GUID,要在解决方案资源管理器中显示的名称,以及当前项目是否应链接到引用的项目),除了{{ 1}},而Common MSBuild Project Items页面未记录此值。 (Private
而不是Private
记录了Reference
设置 - 但它设置了ProjectReference
,Never
和Always
,而不是和假)
此设置有何作用?
答案 0 :(得分:101)
Private
标记将用户覆盖维护到Visual Studio References文件夹中的“复制本地”复选框。它控制是否从GAC使用引用,或者是否将引用的程序集复制到构建目录。
虽然我找不到任何这种效果的MSDN文档(quelle surprise),但从行为和from the comment in Microsoft.Common.CurrentVersion.targets:1742
应用的地方可以看出这一点:
这在MSDN > Common MSBuild project items中有记录,从行为和from the comment in 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.
============================================================
-->
答案 1 :(得分:0)
我只想声明,<Private>false</Private>
(您可以将其应用于ProjectReference
)在使用<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Publish" Properties="$(_MSBuildProperties)" />
且项目$(MSBuildProjectFullPath)
具有{{1}时可能不起作用}个拥有ProjectReference
的
。我已经阅读了https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets周围的源代码,并找到了解决方案。您需要定义<None><CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory></None>
,因此示例如下:_GetChildProjectCopyToPublishDirectoryItems=false