Reputation: 106539
I saw this in a project file the other day:
<ProjectReference Include="Foo\Bar\Baz.csproj">
<Project>{A GUID HERE}</Project>
<Name>Baz</Name>
<Private>False</Private> <!-- ??? -->
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
Every node in a ProjectReference
appears to be self explanatory (the referenced project file, GUID, name to show in the solution explorer, and whether or not the current project should link to the referenced project) except Private
, and the Common MSBuild Project Items page doesn't document this value. (There's a Private
setting documented for Reference
rather than ProjectReference
-- but it has Never
, Always
, and PreserveNewest
settings, not true and false)
What does this setting do?
Upvotes: 179
Views: 92231
Reputation: 22251
Private
metadata on a ProjectReference
item corresponds to the "Copy Local" property on the reference node in Visual Studio's Solution Explorer.
It controls whether the reference should be copied to the output folder or not:
true
means the reference should be copiedfalse
means the reference should NOT be copiedThis is documented in Common MSBuild project items, as well as the MSBuild source itself in Microsoft.Common.CurrentVersion.targets
:
<!--
============================================================
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.
============================================================
-->
Upvotes: 182
Reputation: 1491
I want just to state, that <Private>false</Private>
(which you can apply to ProjectReference
s) may not work when using <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Publish" Properties="$(_MSBuildProperties)" />
and project $(MSBuildProjectFullPath)
have ProjectReference
s that have <None><CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory></None>
. I've read the source code around https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets and found the solution. You need to define _GetChildProjectCopyToPublishDirectoryItems=false
so an example would be: <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Publish" Properties="TargetFramework=$(TargetFramework);_GetChildProjectCopyToPublishDirectoryItems=false" />
Upvotes: 2