Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Private setting do on a ProjectReference in a MSBuild project file?

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?

like image 662
Billy ONeal Avatar asked Oct 07 '14 18:10

Billy ONeal


People also ask

What does Csproj file contains?

A CSPROJ file is a C# (C Sharp) programming project file created by Microsoft Visual Studio. It contains XML-formatted text that lists a project's included files and compilation options.

What is none include?

None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file. Compile - The file is compiled into the build output. This setting is used for code files.

Which is the initial step needed when using the MSBuild at the command prompt?

Build the targettargets file. Run MSBuild from the Developer Command Prompt for Visual Studio to build the HelloWorld target defined above. Use the -target or -t command-line switch to select the target.

What is MSBuild target?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.


1 Answers

The Private tag maintains the user-override to the "Copy Local" checkbox in the Visual Studio References folder. This controls whether the reference is used from the GAC or whether it will copy the referenced assembly to the build directory.

While I cannot find any MSDN documentation to this effect (quelle surprise), it is evident from behavior and from the comment in Microsoft.Common.CurrentVersion.targets:1742 where it is applied:

This is documented in MSDN > Common MSBuild project items, and is evident from behavior and from the comment in Microsoft.Common.CurrentVersion.targets:1742 where it is applied:

  <!--     ============================================================                                          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.     ============================================================     --> 
like image 166
Mitch Avatar answered Nov 24 '22 15:11

Mitch