Skip to content

Commit 2a58247

Browse files
committed
Warn when Properties metadata overrides ProjectReference expansions metadata
Resolves 8967
1 parent aad18fb commit 2a58247

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

src/wix/WixToolset.BuildTasks/UpdateProjectReferenceMetadata.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,26 @@ public static ProjectReferenceFacade CreateFacade(ITaskItem projectReference, Ta
364364
}
365365
}
366366

367-
return new ProjectReferenceFacade(projectReference, configurations, null, platforms, null, targetFrameworks, null, runtimeIdentifiersValue.Values, null, publishBaseDir);
367+
// If the Properties metadata is specified MSBuild will not use TargetFramework inference and require explicit declaration of
368+
// our expansions (Configurations, Platforms, TargetFrameworks, RuntimeIdentifiers). Rather that try to interoperate, we'll
369+
// warn the user that we're disabling our expansion behavior.
370+
var propertiesValue = projectReference.GetMetadata("Properties");
371+
372+
if (!String.IsNullOrWhiteSpace(propertiesValue) && (configurationsValue.HadValue || platformsValue.HadValue || targetFrameworksValue.HadValue || runtimeIdentifiersValue.HadValue))
373+
{
374+
logger.LogWarning(
375+
"ProjectReference '{0}' specifies 'Properties' metadata. " +
376+
"That overrides ProjectReference expansion so the 'Configurations', 'Platforms', 'TargetFrameworks', and 'RuntimeIdentifiers' metadata was ignored. " +
377+
"Instead, use the 'AdditionalProperties' metadata to pass properties to the referenced project without disabling ProjectReference expansion.",
378+
projectReference.ItemSpec);
379+
380+
// Return a facade that does not participate in expansion.
381+
return new ProjectReferenceFacade(projectReference, Array.Empty<string>(), null, Array.Empty<string>(), null, Array.Empty<string>(), null, Array.Empty<string>(), null, publishBaseDir);
382+
}
383+
else
384+
{
385+
return new ProjectReferenceFacade(projectReference, configurations, null, platforms, null, targetFrameworks, null, runtimeIdentifiersValue.Values, null, publishBaseDir);
386+
}
368387
}
369388

370389
public string CalculatePublishDir()

src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace WixToolsetTest.Sdk
1414
using WixInternal.MSTestSupport;
1515
using WixToolset.Data;
1616
using WixToolset.Data.Symbols;
17-
using WixToolset.Data.WindowsInstaller.Rows;
1817

1918
[TestClass]
2019
public class MsbuildFixture
@@ -814,6 +813,36 @@ public void CanBuildMultiTargetingWixlibUsingRids(BuildSystem buildSystem)
814813
}
815814
}
816815

816+
[TestMethod]
817+
[DataRow(BuildSystem.DotNetCoreSdk)]
818+
[DataRow(BuildSystem.MSBuild)]
819+
[DataRow(BuildSystem.MSBuild64)]
820+
public void CanBuildUsingExplicitProperties(BuildSystem buildSystem)
821+
{
822+
var sourceFolder = TestData.Get(@"TestData", "MultiTargetingWixlib");
823+
824+
using (var fs = new TestDataFolderFileSystem())
825+
{
826+
fs.Initialize(sourceFolder);
827+
var baseFolder = Path.Combine(fs.BaseFolder, "PackageUsingExplicitProperties");
828+
var binFolder = Path.Combine(baseFolder, @"bin\");
829+
var filesFolder = Path.Combine(binFolder, "Release", @"PFiles\");
830+
var projectPath = Path.Combine(baseFolder, "PackageUsingExplicitProperties.wixproj");
831+
832+
var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, [
833+
"-Restore",
834+
MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath)
835+
]);
836+
result.AssertSuccess();
837+
838+
var warnings = result.Output.Where(line => line.Contains(": warning")).Select(line => ExtractWarningFromMessage(line, baseFolder)).Distinct().ToArray();
839+
WixAssert.CompareLineByLine(
840+
[
841+
@": ProjectReference '..\TestExe\TestExe.csproj' specifies 'Properties' metadata. That overrides ProjectReference expansion so the 'Configurations', 'Platforms', 'TargetFrameworks', and 'RuntimeIdentifiers' metadata was ignored. Instead, use the 'AdditionalProperties' metadata to pass properties to the referenced project without disabling ProjectReference expansion.",
842+
], warnings);
843+
}
844+
}
845+
817846
[TestMethod]
818847
[DataRow(BuildSystem.DotNetCoreSdk)]
819848
[DataRow(BuildSystem.MSBuild)]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2+
<Package Name="Test Package" Manufacturer="~Test" Version="0" Compressed="false" UpgradeCode="11111111-1111-1111-1111-111111111111">
3+
<Feature Id="Main">
4+
<ComponentGroupRef Id="Stuff"/>
5+
</Feature>
6+
</Package>
7+
8+
<Fragment>
9+
<ComponentGroup Id="Stuff" Directory="ProgramFilesFolder">
10+
<Component Subdirectory="net8_x64">
11+
<File Id="net8_x64" Source="!(bindpath.TestExe)\e_sqlite3.dll" />
12+
</Component>
13+
</ComponentGroup>
14+
</Fragment>
15+
</Wix>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<Import Project="$(WixMSBuildProps)" />
4+
5+
<ItemGroup>
6+
<ProjectReference Include="..\TestExe\TestExe.csproj" Publish="true" TargetFrameworks="net472" RuntimeIdentifiers="win-x86">
7+
<!-- Not recommended, these disable the values on the ProjectReference -->
8+
<Properties>TargetFramework=net8.0;RuntimeIdentifier=win-x64</Properties>
9+
</ProjectReference>
10+
</ItemGroup>
11+
12+
<Import Project="$(WixTargetsPath)" />
13+
</Project>

0 commit comments

Comments
 (0)