Saved searches

Use saved searches to filter your results more quickly

Cancel Create saved search Sign up Reseting focus

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

dotnet / msbuild Public

ProjectReference-Protocol.md

Latest commit

History

189 lines (138 loc) · 16.3 KB

ProjectReference-Protocol.md

File metadata and controls

189 lines (138 loc) · 16.3 KB

The ProjectReference Protocol

The MSBuild engine doesn't have a notion of a “project reference”—it only provides the MSBuild task to allow cross-project communication.

That's a powerful tool, but no one would want to have to specify how to build every single reference in every single project. The common targets introduce an item, ProjectReference , and a default process for building references declared via that item.

Default protocol implementation:

Projects that have references

In its simplest form, a project need only specify the path to another project in a ProjectReference item. For example,

ItemGroup> ProjectReference Include="..\..\some\other\project.csproj" /> ItemGroup>

Importing Microsoft.Common.targets includes logic that consumes these items and transforms them into compile-time references before the compiler runs.

Who this document is for

This document describes that process, including what is required of a project to be referenceable through a ProjectReference . It is intended for MSBuild SDK maintainers, and those who have created a completely custom project type that needs to interoperate with other projects. It may also be of interest if you'd like to see the implementation details of references. Understanding the details should not be necessary to use ProjectReferences in your project.

Targets related to consuming a reference

The bulk of the work of transforming ProjectReference items into something suitable to feed the compiler is done by tasks listed in the ResolveReferencesDependsOn property defined in Microsoft.Common.CurrentVersion.targets .

There are empty hooks in the default targets for

AssignProjectConfiguration runs when building in a solution context, and ensures that the right Configuration and Platform are assigned to each reference. For example, if a solution specifies (using the Solution Build Manager) that for a given solution configuration, a project should always be built Release , that is applied inside MSBuild in this target.

PrepareProjectReferences then runs, ensuring that each referenced project exists (creating the item @(_MSBuildProjectReferenceExistent) ).

_ComputeProjectReferenceTargetFrameworkMatches calls GetTargetFrameworks in existent ProjectReferences and determines the parameters needed to produce a compatible build by calling the AssignReferenceProperties task for each reference that multitargets.

ResolveProjectReferences does the bulk of the work, building the referenced projects and collecting their outputs.

After the compiler is invoked, GetCopyToOutputDirectoryItems pulls child-project outputs into the current project to be copied to its output directory.

When Clean ing the output of a project, CleanReferencedProjects ensures that referenced projects also clean.

Targets required to be referenceable

These targets should exist in a project to be compatible with the common targets' ProjectReference (unless marked with the SkipNonexistentTargets='true' metadatum). Some are called only conditionally.

These targets are all defined in Microsoft.Common.targets and are defined in Microsoft SDKs. You should only have to implement them yourself if you require custom behavior or are authoring a project that doesn't import the common targets.

If implementing a project with an “outer” (determine what properties to pass to the real build) and “inner” (fully specified) build, only GetTargetFrameworks is required in the “outer” build. The other targets listed can be “inner” build only.