Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/internal/WixInternal.MSTestSupport/MsbuildUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static MsbuildRunnerResult BuildProject(BuildSystem buildSystem, string p

if (binlog)
{
MsbuildUtilities.GetQuotedSwitch(buildSystem, "bl", Path.ChangeExtension(projectPath, ".binlog"));
var binlogSwitch = MsbuildUtilities.GetQuotedSwitch(buildSystem, "bl", Path.ChangeExtension(projectPath, ".binlog"));
allArgs.Add(binlogSwitch);
}

if (arguments != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows7.0</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</StandardDirectory>

<Feature Id='Main' Title='WpfApp'>
<Component Directory='ApplicationFolder'>
<File Source='CsprojWpfNetCore.exe' />
</Component>
<Files Directory='ApplicationFolder' Include='!(bindpath.CsprojWpfNetCore)\**'>
<Exclude Files="**\*.pdb" />
</Files>
</Feature>
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
<Project Sdk='WixToolset.Sdk'>
<!-- <Project> -->
<!-- <Import Sdk="WixToolset.Sdk" Project='D:\src\wix4\build\wix\Debug\net8.0\Sdk\Sdk.props' /> -->

<PropertyGroup>
<!-- <WixBinDir>D:\src\wix4\build\wix\Debug\net472\</WixBinDir> -->
<!-- <WixBinDir64>D:\src\wix4\build\wix\Debug\publish\WixToolset.Sdk\tools\net472\x64\</WixBinDir64> -->
</PropertyGroup>
<ItemGroup>
<Compile Remove="abc\Bad.wxs" />
</ItemGroup>

<ItemGroup>
<!-- SkipPublish="true" BindPath="$(MSBuildProjectDirectory)\does\not\exist" BindName="Xxx" Publish="true" -->
<ProjectReference Include="..\CsprojWpfNetCore\CsprojWpfNetCore.csproj" Publish="true" />
</ItemGroup>

<!-- <Import Sdk="WixToolset.Sdk" Project='D:\src\wix4\build\wix\Debug\net8.0\Sdk\Sdk.targets' /> -->
</Project>
13 changes: 13 additions & 0 deletions src/wix/WixToolset.BuildTasks/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.BuildTasks
{
public interface ILogger
{
bool HasLoggedErrors { get; }

void LogError(string message);

void LogWarning(string message);
}
}
28 changes: 28 additions & 0 deletions src/wix/WixToolset.BuildTasks/MSBuildLoggerAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.BuildTasks
{
using Microsoft.Build.Utilities;

internal class MSBuildLoggerAdapter : ILogger
{
private readonly TaskLoggingHelper log;

public MSBuildLoggerAdapter(TaskLoggingHelper log)
{
this.log = log;
}

public bool HasLoggedErrors => this.log.HasLoggedErrors;

public void LogError(string message)
{
this.log.LogError(message);
}

public void LogWarning(string message)
{
this.log.LogWarning(message);
}
}
}
174 changes: 174 additions & 0 deletions src/wix/WixToolset.BuildTasks/ResolveInstallerPlatform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.BuildTasks
{
using System;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

/// <summary>
/// This task calculates the InstallerPlatform from the RuntimeIdentifier,
/// InitialInstallerPlatform and Platform properties.
/// </summary>
public class ResolveInstallerPlatform : Task
{
private readonly ILogger logger;

/// <summary>
/// Default constructor.
/// </summary>
public ResolveInstallerPlatform()
{
this.logger = new MSBuildLoggerAdapter(this.Log);
}

/// <summary>
/// Constructor for dependency injection of logger used by unit tests.
/// </summary>
public ResolveInstallerPlatform(ILogger logger)
{
this.logger = logger;
}

/// <summary>
/// The optional RuntimeIdentifier property.
/// </summary>
public string RuntimeIdentifier { private get; set; }

/// <summary>
/// The optional InitialInstallerPlatform property.
/// </summary>
public string InitialInstallerPlatform { private get; set; }

/// <summary>
/// The InstallerPlatform property.
/// </summary>
public string InstallerPlatform { private get; set; }

/// <summary>
/// The optional Platform property.
/// </summary>
public string Platform { private get; set; }

/// <summary>
/// The resolved InstallerPlatform.
/// </summary>
[Output]
public string ResolvedInstallerPlatform { get; private set; }

/// <summary>
/// The optionally resolved Platform.
/// </summary>
[Output]
public string ResolvedPlatform { get; private set; }

/// <summary>
/// Convert the input properties into output items.
/// </summary>
/// <returns>True upon completion of the task execution.</returns>
public override bool Execute()
{
if (String.IsNullOrEmpty(this.RuntimeIdentifier))
{
this.ResolvedInstallerPlatform = this.InstallerPlatform;
}
else if (this.ValidateWindowsRuntimeIdentifier(this.RuntimeIdentifier, out var platform))
{
if (!String.IsNullOrEmpty(this.InitialInstallerPlatform) && !String.Equals(this.InitialInstallerPlatform, platform, StringComparison.OrdinalIgnoreCase))
{
this.logger.LogError($"The RuntimeIdentifier '{this.RuntimeIdentifier}' resolves to platform '{platform}', which conflicts with the provided InstallerPlatform '{this.InitialInstallerPlatform}'.");
}
else
{
this.ResolvedInstallerPlatform = platform;
}
}

// If Platform was a generic value, resolve it to the resolved installer platform.
if (String.IsNullOrEmpty(this.Platform)
|| this.Platform.Equals("AnyCPU", StringComparison.OrdinalIgnoreCase)
|| this.Platform.Equals("Any CPU", StringComparison.OrdinalIgnoreCase)
|| this.Platform.Equals("Win32", StringComparison.OrdinalIgnoreCase))
{
this.ResolvedPlatform = this.ResolvedInstallerPlatform;
}
else if (!this.Platform.Equals(this.ResolvedInstallerPlatform, StringComparison.OrdinalIgnoreCase))
{
this.logger.LogWarning($"The provided Platform '{this.Platform}' does not match the resolved InstallerPlatform '{this.ResolvedInstallerPlatform}'. The output will be built using '{this.ResolvedInstallerPlatform}'.");
}

return !this.logger.HasLoggedErrors;
}

private bool ValidateWindowsRuntimeIdentifier(string runtimeIdentifier, out string platform)
{
platform = null;

var ridParts = runtimeIdentifier.Split('-');
if (ridParts.Length < 2)
{
this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' is not valid.");

return false;
}

var os = ridParts[0];

if (!os.StartsWith("win", StringComparison.OrdinalIgnoreCase) || (os.Length > 3 && !Int32.TryParse(os.Substring(3), out var _)))
{
this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' is not a valid Windows RuntimeIdentifier.");

return false;
}

// Ensure there is only one platform specified in the RID.
foreach (var part in ridParts.Skip(1))
{
string platformPart;
switch (part.ToLowerInvariant())
{
case "x86":
case "win32":
platformPart = "x86";
break;

case "x64":
case "amd64":
platformPart = "x64";
break;

case "arm":
case "arm32":
platformPart = "arm";
break;

case "arm64":
platformPart = "arm64";
break;

default:
continue;
}

if (String.IsNullOrEmpty(platform))
{
platform = platformPart;
}
else // there can be only one platform in the RID.
{
this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' specifies multiple platforms which is not supported.");
}
}

if (String.IsNullOrEmpty(platform))
{
this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' does not specify a valid platform.");

return false;
}

return true;
}
}
}
21 changes: 20 additions & 1 deletion src/wix/WixToolset.BuildTasks/UpdateProjectReferenceMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,26 @@ public static ProjectReferenceFacade CreateFacade(ITaskItem projectReference, Ta
}
}

return new ProjectReferenceFacade(projectReference, configurations, null, platforms, null, targetFrameworks, null, runtimeIdentifiersValue.Values, null, publishBaseDir);
// If the Properties metadata is specified MSBuild will not use TargetFramework inference and require explicit declaration of
// our expansions (Configurations, Platforms, TargetFrameworks, RuntimeIdentifiers). Rather that try to interoperate, we'll
// warn the user that we're disabling our expansion behavior.
var propertiesValue = projectReference.GetMetadata("Properties");

if (!String.IsNullOrWhiteSpace(propertiesValue) && (configurationsValue.HadValue || platformsValue.HadValue || targetFrameworksValue.HadValue || runtimeIdentifiersValue.HadValue))
{
logger.LogWarning(
"ProjectReference '{0}' 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.",
projectReference.ItemSpec);

// Return a facade that does not participate in expansion.
return new ProjectReferenceFacade(projectReference, Array.Empty<string>(), null, Array.Empty<string>(), null, Array.Empty<string>(), null, Array.Empty<string>(), null, publishBaseDir);
}
else
{
return new ProjectReferenceFacade(projectReference, configurations, null, platforms, null, targetFrameworks, null, runtimeIdentifiersValue.Values, null, publishBaseDir);
}
}

public string CalculatePublishDir()
Expand Down
56 changes: 56 additions & 0 deletions src/wix/WixToolset.Sdk/tools/wix.targets
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<UsingTask TaskName="CreateProjectReferenceDefineConstantsAndBindPaths" AssemblyFile="$(WixTasksPath)" />
<UsingTask TaskName="WixAssignCulture" AssemblyFile="$(WixTasksPath)" />
<UsingTask TaskName="ReadTracking" AssemblyFile="$(WixTasksPath)" />
<UsingTask TaskName="ResolveInstallerPlatform" AssemblyFile="$(WixTasksPath)" />
<UsingTask TaskName="ResolveWixReferences" AssemblyFile="$(WixTasksPath)" />
<UsingTask TaskName="WixBuild" AssemblyFile="$(WixTasksPath)" />
<UsingTask TaskName="WindowsInstallerValidation" AssemblyFile="$(WixTasksPath)" />
Expand Down Expand Up @@ -165,6 +166,7 @@

<!-- Default Compiler properties. -->
<PropertyGroup>
<_InitialInstallerPlatform>$(InstallerPlatform)</_InitialInstallerPlatform>
<InstallerPlatform Condition=" '$(InstallerPlatform)' == '' and ('$(Platform)' == '' or '$(Platform)' == 'Win32' or '$(Platform)' == 'AnyCPU' or '$(Platform)' == 'Any CPU') ">x86</InstallerPlatform>
<InstallerPlatform Condition=" '$(InstallerPlatform)' == '' ">$(Platform)</InstallerPlatform>
</PropertyGroup>
Expand All @@ -178,6 +180,60 @@
<BindVariable Include="$(WixVariables)" Condition=" '$(WixVariables)' != '' " />
</ItemGroup>

<!--
***********************************************************************************************
***********************************************************************************************
Prepare For Build Section
***********************************************************************************************
***********************************************************************************************
-->
<PropertyGroup>
<PrepareForBuildDependsOn>
ResolveInstallerPlatform;
$(PrepareForBuildDependsOn)
</PrepareForBuildDependsOn>
</PropertyGroup>

<!--
================================================================================================
ResolveInstallerPlatform

Uses the RuntimeIdentifier to validate and update the InstallerPlatform. If the RuntimeIdentifier is
not provided, the InstallerPlatform will continue to mirror the Platform.

[IN]
$(_InitialInstallerPlatform) - Set if InstallerPlatform was explcitly defined in project.
$(InstallerPlatform) - InstallerPlatform calculated from initial value of Platform.
$(RuntimeIdentfier) - Optional runtime identifier for output.
$(Platform) - Optional platform for output.

[OUT]
$(InstallerPlatform) - InstallerPlatform resolved based on the inputs.
$(PlatformName) - Potentially updates Platform name if Platform is generic and the RuntimeIdentifier
changes the InstallerPlatform.
================================================================================================
-->
<Target
Name="ResolveInstallerPlatform"
Returns="$(InstallerPlatform)">

<ResolveInstallerPlatform
RuntimeIdentifier="$(RuntimeIdentifier)"
InitialInstallerPlatform="$(_InitialInstallerPlatform)"
InstallerPlatform="$(InstallerPlatform)"
Platform="$(Platform)">
<Output TaskParameter="ResolvedInstallerPlatform"
PropertyName="_ResolvedInstallerPlatform" />
<Output TaskParameter="ResolvedPlatform"
PropertyName="_ResolvedPlatform" />
</ResolveInstallerPlatform>

<PropertyGroup>
<InstallerPlatform>$(_ResolvedInstallerPlatform)</InstallerPlatform>
<PlatformName Condition=" '$(_ResolvedPlatform)' != '' and '$(PlatformName)' == '$(Platform)' ">$(_ResolvedPlatform)</PlatformName>
</PropertyGroup>
</Target>

<!--
***********************************************************************************************
***********************************************************************************************
Expand Down
Loading