Skip to content

Commit

Permalink
Fix ResolveProjectReferences MSBuild target
Browse files Browse the repository at this point in the history
  • Loading branch information
drolevar committed Mar 10, 2021
1 parent 59fea83 commit c70e122
Showing 1 changed file with 81 additions and 104 deletions.
185 changes: 81 additions & 104 deletions src/WixToolset.Sdk/tools/wix.targets
Original file line number Diff line number Diff line change
Expand Up @@ -314,145 +314,122 @@
</PropertyGroup>

<!--
================================================================================================
ResolveProjectReferences
============================================================
PrepareProjectReferences
Builds all of the referenced projects to get their outputs.
Prepares project references for consumption by other targets.
[IN]
@(NonVCProjectReference) - The list of non-VC project references.
[IN]
@(ProjectReference) - The list of project references.
[OUT]
@(ProjectReferenceWithConfiguration) - The list of non-VC project references.
@(WixLibProjects) - Paths to any .wixlibs that were built by referenced projects.
================================================================================================
[OUT]
@(ProjectReferenceWithConfiguration) - Project references with apporpriate metadata
@(_MSBuildProjectReferenceExistent) - Subset of @(ProjectReferenceWithConfiguration) that exist
with added SetTargetFramework metadata for cross-targeting
@(_MSBuildProjectReferenceNonExistent) - Subset of @(ProjectReferenceWithConfiguration) that do not exist
============================================================
-->
<Target
Name="ResolveProjectReferences"
DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence"
Condition=" '@(ProjectReferenceWithConfiguration)' != '' ">

<!-- Issue a warning for each non-existent project. -->
<Warning
Text="The referenced project '%(_MSBuildProjectReferenceNonexistent.Identity)' does not exist."
Condition=" '@(_MSBuildProjectReferenceNonexistent)' != '' " />
<PropertyGroup>
<PrepareProjectReferencesDependsOn>
AssignProjectConfiguration;
_SplitProjectReferencesByFileExistence;
_GetProjectReferenceTargetFrameworkProperties
</PrepareProjectReferencesDependsOn>
</PropertyGroup>
<Target Name="PrepareProjectReferences" DependsOnTargets="$(PrepareProjectReferencesDependsOn)" />

<!--
When building this project from the IDE or when building a .sln from the command line or
when only building .wixlib project references, gather the referenced build outputs. The
code that builds the .sln will already have built the project, so there's no need to do
it again here and when building only .wixlib project references we'll use the results to
determine which projects to build.
The ContinueOnError setting is here so that, during project load, as much information as
possible will be passed to the compilers.
-->
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="%(_MSBuildProjectReferenceExistent.Targets);GetTargetPath"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);%(_MSBuildProjectReferenceExistent.SetPlatform)"
Condition="('$(BuildingSolutionFile)' == 'true' or '$(BuildingInsideVisualStudio)' == 'true' or '$(BuildProjectReferences)' != 'true') and '@(_MSBuildProjectReferenceExistent)' != '' "
ContinueOnError="!$(BuildingProject)">
<!--
============================================================
ResolveProjectReferences
<Output TaskParameter="TargetOutputs" ItemName="_GatheredProjectReferencePaths" />
</MSBuild>
Build referenced projects:
<!--
Determine which project references should be built. Note: we will not build any project references
if building in the IDE because it builds project references directly.
[IN]
@(ProjectReferenceWithConfiguration) - The list of project references.
If BuildProjectReferences is 'true' (the default) then take all MSBuild project references that exist
on disk and add them to the list of things to build. This is the easy case.
[OUT]
@(_ResolvedNativeProjectReferencePaths) - Paths to referenced native projects.
@(_ResolvedProjectReferencePaths) - Paths to referenced managed projects.
============================================================
-->
<CreateItem
Include="@(_MSBuildProjectReferenceExistent)"
Condition=" '$(BuildProjectReferences)' == 'true' and '$(BuildingInsideVisualStudio)' != 'true' ">

<Output TaskParameter="Include" ItemName="_ProjectReferencesToBuild" />
</CreateItem>
<!-- By default, the outputs of project references are passed to the compiler -->
<ItemDefinitionGroup>
<ProjectReference>
<!-- Target to build in the project reference; by default, this property is blank, indicating the default targets-->
<Targets>$(ProjectReferenceBuildTargets)</Targets>
<!-- Extra item type to emit outputs of the destination into. Defaults to blank. To emit only into this list, set the ReferenceOutputAssembly metadata to false as well. -->
<OutputItemType/>
<ReferenceSourceTarget>ProjectReference</ReferenceSourceTarget>
</ProjectReference>
</ItemDefinitionGroup>

<!--
If BuildProjectReferences is 'wixlib' then build only the MSBuild project references that exist and
create a .wixlib file. That requires us to first filter the gathered project references down to only
those that build .wixlibs.
-->
<CreateItem
Include="@(_GatheredProjectReferencePaths)"
Condition=" '$(BuildProjectReferences)' == 'wixlib' and '%(Extension)' == '.wixlib' and '$(BuildingInsideVisualStudio)' != 'true' ">

<Output TaskParameter="Include" ItemName="_ReferencedWixLibPaths" />
</CreateItem>
<Target
Name="ResolveProjectReferences"
DependsOnTargets="PrepareProjectReferences"
Returns="@(_ResolvedNativeProjectReferencePaths);@(_ResolvedProjectReferencePaths)">

<!--
The second step when building only 'wixlib' project references is to create the list of existing MSBuild
project references that do *not* build a .wixlib. These are the projects that will be skipped.
-->
<CreateItem
Include="@(_MSBuildProjectReferenceExistent->'%(FullPath)')"
Exclude="@(_ReferencedWixLibPaths->'%(MSBuildSourceProjectFile)')"
Condition=" '$(BuildProjectReferences)' == 'wixlib' and '$(BuildingInsideVisualStudio)' != 'true' ">
When building this project from the IDE, just gather the referenced build outputs.
The IDE will already have built the project, so there's no need to do it again here.
<Output TaskParameter="Include" ItemName="_ProjectReferencesToSkip" />
</CreateItem>

<!--
Finally, when building only 'wixlib' project references, the list of projects to build are naturally the
list of projects *not* being skipped.
The ContinueOnError setting is here so that, during project load, as
much information as possible will be passed to the compilers.
-->
<CreateItem
Include="@(_MSBuildProjectReferenceExistent->'%(FullPath)')"
Exclude="@(_ProjectReferencesToSkip)"
Condition=" '$(BuildProjectReferences)' == 'wixlib' and '$(BuildingInsideVisualStudio)' != 'true' ">

<Output TaskParameter="Include" ItemName="_ProjectReferencesToBuild" />
</CreateItem>
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetTargetPath"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and ('$(BuildingInsideVisualStudio)' == 'true' or '$(BuildProjectReferences)' != 'true') and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)$(_GlobalPropertiesToRemoveFromProjectReferences)">

<!-- Display a warning for all projects being skipped. -->
<Warning
Text="BuildProjectReferences set to '$(BuildProjectReferences)'. Skipping the non-Library project: %(_ProjectReferencesToSkip.Identity)"
Condition=" '@(_ProjectReferencesToSkip)' != '' " />
<Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths" Condition="'%(_MSBuildProjectReferenceExistent.ReferenceOutputAssembly)'=='true'"/>
<Output TaskParameter="TargetOutputs" ItemName="%(_MSBuildProjectReferenceExistent.OutputItemType)" Condition="'%(_MSBuildProjectReferenceExistent.OutputItemType)' != ''"/>

<Message
Importance="low"
Text="Project reference to build: %(_ProjectReferencesToBuild.Identity), properties: %(_ProjectReferencesToBuild.Properties)"
Condition=" '@(_ProjectReferencesToBuild)' != '' " />
</MSBuild>

<!--
Build referenced projects when building from the command line.
The $(ProjectReferenceBuildTargets) will normally be blank so that the project's default target
is used during a P2P reference. However if a custom build process requires that the referenced
project has a different target to build it can be specified.
-->
<MSBuild
Projects="@(_ProjectReferencesToBuild)"
Targets="$(ProjectReferenceBuildTargets)"
Properties="%(_ProjectReferencesToBuild.SetConfiguration);%(_ProjectReferencesToBuild.SetPlatform)"
Condition=" '@(_ProjectReferencesToBuild)' != '' ">
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="%(_MSBuildProjectReferenceExistent.Targets)"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and '$(BuildingInsideVisualStudio)' != 'true' and '$(BuildProjectReferences)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="$(ContinueOnError)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)$(_GlobalPropertiesToRemoveFromProjectReferences)">

<Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths" Condition="'%(_MSBuildProjectReferenceExistent.ReferenceOutputAssembly)'=='true' or '$(DesignTimeBuild)' == 'true'"/>
<Output TaskParameter="TargetOutputs" ItemName="%(_MSBuildProjectReferenceExistent.OutputItemType)" Condition="'%(_MSBuildProjectReferenceExistent.OutputItemType)' != ''"/>

<Output TaskParameter="TargetOutputs" ItemName="_BuiltProjectReferencePaths" />
</MSBuild>

<!--
VC project references must build GetNativeTargetPath because neither GetTargetPath nor the return of the default build
target return the output for a native .vcxproj.
-->
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetNativeTargetPath"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);%(_MSBuildProjectReferenceExistent.SetPlatform)"
Condition=" '@(ProjectReferenceWithConfiguration)' != '' and '%(_MSBuildProjectReferenceExistent.Extension)' == '.vcxproj' ">
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetNativeTargetPath"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '%(_MSBuildProjectReferenceExistent.Extension)' == '.vcxproj' and '@(ProjectReferenceWithConfiguration)' != '' and '$(BuildingProject)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="$(ContinueOnError)"
SkipNonexistentTargets="true"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)$(_GlobalPropertiesToRemoveFromProjectReferences)">

<Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths" />
<Output TaskParameter="TargetOutputs" ItemName="_MSBuildResolvedProjectReferencePaths" />
</MSBuild>

<!-- Assign the unique gathered and built project references to the resolved project
reference paths. -->
<RemoveDuplicates Inputs="@(_GatheredProjectReferencePaths);@(_BuiltProjectReferencePaths)">
<Output TaskParameter="Filtered" ItemName="_ResolvedProjectReferencePaths" />
<Output TaskParameter="Filtered" ItemName="_MSBuildResolvedProjectReferencePaths" />
</RemoveDuplicates>
<!-- Issue a warning for each non-existent project. -->
<Warning
Text="The referenced project '%(_MSBuildProjectReferenceNonexistent.Identity)' does not exist."
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceNonexistent)' != ''"/>


<!-- Create list of all .wixlib project references. -->
<CreateItem
Expand Down

0 comments on commit c70e122

Please sign in to comment.