Skip to content

Commit

Permalink
fix: Upgrade Wix to v5 to fix an issue with non-elevated installs. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaffinito committed May 10, 2024
1 parent e66bf2c commit acd12fa
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 555 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ updates:
nuget:
patterns:
- "*"
- package-ecosystem: nuget
directory: /src/Agent/MsiInstaller
schedule:
interval: weekly
groups:
nuget:
patterns:
- "*"
18 changes: 15 additions & 3 deletions build/ArtifactBuilder/Artifacts/MsiInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void ValidateWixIisRegistryDefinitions(WixFragmentComponentGroup framewo

foreach (var value in _frameworkIISRegistryValues)
{
if (!component.RegistryValue.MultiStringValue.Contains(value))
if (!component.RegistryValue.MultiStringValue.Any(msv => msv.Value == value))
{
throw new PackagingException($@"Product.wxs Framework registryvalue {component.RegistryValue.Name}\{component.RegistryValue.Name} missing {value}");
}
Expand All @@ -251,7 +251,7 @@ private void ValidateWixIisRegistryDefinitions(WixFragmentComponentGroup framewo

foreach (var value in _coreIISRegistryValues)
{
if (!component.RegistryValue.MultiStringValue.Contains(value))
if (!component.RegistryValue.MultiStringValue.Any(msv => msv.Value == value))
{
throw new PackagingException($@"Product.wxs Core registryvalue {component.RegistryValue.Name}\{component.RegistryValue.Name} missing {value}");
}
Expand Down Expand Up @@ -313,13 +313,25 @@ private void ValidateContent()
return;
}

// Wix v4+ admin install places files into proper subdirectories instead of a single directory
// Combining the new directories results in the same structure from Wix v3 for less changes
var commAppRoot = Path.Join(unpackedLocation, "CommApp", "New Relic", ".NET Agent");
var pFilesRootx86 = Path.Join(unpackedLocation, "PFiles", "New Relic", ".NET Agent");
var pFilesRootx64 = Path.Join(unpackedLocation, "PFiles64", "New Relic", ".NET Agent");
var installedFilesRoot = Path.Join(unpackedLocation, "New Relic", ".NET Agent");

FileHelpers.CopyAll(commAppRoot, installedFilesRoot);
FileHelpers.CopyAll(pFilesRootx86, installedFilesRoot); // needed for both x86 and x64
if (Platform == "x64")
{
FileHelpers.CopyAll(pFilesRootx64, installedFilesRoot);
}

var expectedComponents = GetExpectedComponents(installedFilesRoot);

var unpackedComponents = ValidationHelpers.GetUnpackedComponents(installedFilesRoot);

ValidationHelpers.ValidateComponents(expectedComponents, unpackedComponents, "msi");
ValidationHelpers.ValidateComponents(expectedComponents, unpackedComponents, Platform + " msi");

FileHelpers.DeleteDirectories(unpackedLocation);
}
Expand Down
65 changes: 27 additions & 38 deletions build/ArtifactBuilder/ParsedProductWxsTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,108 +7,97 @@ namespace ArtifactBuilder
{
// This code was auto-generated by visual studio and then edited to remove all of the generated
// classes that were not needed for our testing purposes.

// NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
/// <remarks />

[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
[XmlRoot(Namespace = "http://schemas.microsoft.com/wix/2006/wi", IsNullable = false)]
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
[XmlRoot(Namespace = "http://wixtoolset.org/schemas/v4/wxs", IsNullable = false)]
public class Wix
{
/// <remarks />

public WixFragment Fragment { get; set; }
}

/// <remarks />
[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
public class WixFragment
{
/// <remarks />
[XmlElement("ComponentGroup", typeof(WixFragmentComponentGroup))]
public object[] Items { get; set; }
}

/// <remarks />
[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
public class WixFragmentComponentGroup
{
/// <remarks />
[XmlElement("Component")]
public WixFragmentComponentGroupComponent[] Component { get; set; }

/// <remarks />
[XmlAttribute]
public string Id { get; set; }

/// <remarks />
[XmlAttribute]
public string Directory { get; set; }
}

/// <remarks />
[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
public class WixFragmentComponentGroupComponent
{
/// <remarks />
public WixFragmentComponentGroupComponentFile File { get; set; }

/// <remarks />
public WixFragmentComponentGroupComponentRegistryValue RegistryValue { get; set; }
}

/// <remarks />
[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
public class WixFragmentComponentGroupComponentFile
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
public class WixFragmentComponentGroupComponentRegistryValue
{
/// <remarks />
[XmlAttribute]
public string Id { get; set; }
public string Root { get; set; }

/// <remarks />
[XmlAttribute]
public string Name { get; set; }

/// <remarks />
[XmlAttribute]
public string KeyPath { get; set; }

/// <remarks />
[XmlAttribute]
public string Source { get; set; }
public string Key { get; set; }

[XmlElement("MultiStringValue")]
public List<WixFragmentComponentGroupComponentRegistryValueMultiStringValue> MultiStringValue { get; set; }
}

/// <remarks />
[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
public class WixFragmentComponentGroupComponentRegistryValue
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
public class WixFragmentComponentGroupComponentRegistryValueMultiStringValue
{
[XmlAttribute()]
public string Value { get; set; }
}

[Serializable]
[DesignerCategory("code")]
[XmlType(AnonymousType = true, Namespace = "http://wixtoolset.org/schemas/v4/wxs")]
public class WixFragmentComponentGroupComponentFile
{
/// <remarks />
[XmlAttribute]
public string Root { get; set; }
public string Id { get; set; }

/// <remarks />
[XmlAttribute]
public string Name { get; set; }

/// <remarks />
[XmlAttribute]
public string KeyPath { get; set; }

/// <remarks />
[XmlAttribute]
public string Key { get; set; }

[XmlElement(ElementName = "MultiStringValue", Namespace = "http://schemas.microsoft.com/wix/2006/wi")]
public List<string> MultiStringValue { get; set; }
public string Source { get; set; }
}
}
66 changes: 14 additions & 52 deletions src/Agent/MsiInstaller/Installer/Installer.wixproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="WixToolset.Sdk/5.0.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.6</ProductVersion>
<ProjectGuid>b5c13b8f-279b-455b-ace5-864ca37ceb08</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>Installer</OutputName>
<OutputType>Package</OutputType>
<IntermediateOutputPath>$(SolutionDir)..\..\_build\$(Platform)-$(Configuration)\$(OutputName)\</IntermediateOutputPath>
<OutputPath>$(SolutionDir)..\..\_build\$(Platform)-$(Configuration)\$(OutputName)\</OutputPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
</PropertyGroup>
<ItemGroup>
<Compile Include="LicenseKeyDialog.wxs" />
<Compile Include="Product.wxs" />
<Compile Include="WizardUI.wxs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\InstallerActions\InstallerActions.csproj">
<Name>InstallerActions</Name>
Expand All @@ -38,33 +16,21 @@
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<WixExtension Include="WixNetFxExtension">
<HintPath>$(WixExtDir)\WixNetFxExtension.dll</HintPath>
<Name>WixNetFxExtension</Name>
</WixExtension>
<WixExtension Include="WixIIsExtension">
<HintPath>$(WixExtDir)\WixIIsExtension.dll</HintPath>
<Name>WixIIsExtension</Name>
</WixExtension>
<WixExtension Include="WixUIExtension">
<HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
<WixExtension Include="WixUtilExtension">
<HintPath>$(WixExtDir)\WixUtilExtension.dll</HintPath>
<Name>WixUtilExtension</Name>
</WixExtension>
<PackageReference Include="WixToolset.NetFx.wixext" Version="5.0.0" />
<PackageReference Include="WixToolset.Iis.wixext" Version="5.0.0" />
<PackageReference Include="WixToolset.UI.wixext" Version="5.0.0" />
<PackageReference Include="WixToolset.Util.wixext" Version="5.0.0" />
</ItemGroup>
<Import Project="$(WixTargetsPath)" />


<PropertyGroup>
<WindowsSdkPathBin>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('Windows', '10.0'))bin</WindowsSdkPathBin>
<WindowsSdkPath>$(WindowsSdkPathBin)\10.0.19041.0</WindowsSdkPath>
<SignToolPath>$(WindowsSdkPath)\x64\signtool.exe</SignToolPath>
</PropertyGroup>

<Target Name="SignInstaller">
<Target Name="SignInstaller" BeforeTargets="AfterBuild">
<Exec Command="&quot;$(SignToolPath)&quot; sign /d &quot;New Relic .NET Agent&quot; /a &quot;$(OutputPath)$(OutputName).msi&quot;" StandardOutputImportance="high" />
<ReadFileVersionFromDll FilePath="$(SolutionDir)..\..\_build\AnyCPU-$(Configuration)\NewRelic.Agent.Core\net462\NewRelic.Agent.Core.dll">
<Output PropertyName="FileVersionString" TaskParameter="FileVersionString" />
Expand All @@ -73,21 +39,17 @@
<Delete Files="$(OutputPath)\$(OutputName).msi" />
</Target>

<Target Name="AfterBuild" DependsOnTargets="SignInstaller" />

<UsingTask TaskName="ReadFileVersionFromDll" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<FilePath ParameterType="System.String" Required="true" />
<FileVersionString ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
<Code Type="Fragment" Language="cs"><![CDATA[
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(FilePath);
FileVersionString = myFileVersionInfo.FileVersion;
]]>
</Code>
]]></Code>
</Task>
</UsingTask>
</Project>
</Project>
23 changes: 10 additions & 13 deletions src/Agent/MsiInstaller/Installer/LicenseKeyDialog.wxs
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
<!--
Copyright 2020 New Relic Corporation. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<Property Id="PIDTemplate">
<![CDATA[&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&]]>
</Property>
<Property Id="PIDTemplate" Value="&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;" />
<UI>
<Dialog Id="LicenseKeyDialog" Width="370" Height="270" Title="[ProductName] Setup">
<Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />
<Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
<Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}License Key"/>
<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Please enter your license key"/>
<Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}License Key" />
<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Please enter your license key" />
<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />

<Control Id="LicenseLabel" Type="Text" X="45" Y="147" Width="50" Height="10" TabSkip="no" Text="License Key:"/>
<Control Id="LicenseEdit" Type="MaskedEdit" X="45" Y="159" Width="250" Height="16" Property="NR_LICENSE_KEY" Text="[PIDTemplate]"/>
<Control Id="LicenseLabel" Type="Text" X="45" Y="147" Width="50" Height="10" TabSkip="no" Text="License Key:" />
<Control Id="LicenseEdit" Type="MaskedEdit" X="45" Y="159" Width="250" Height="16" Property="NR_LICENSE_KEY" Text="[PIDTemplate]" />

<Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&amp;Back">
<Publish Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
<Publish Event="NewDialog" Value="LicenseAgreementDlg" />
</Control>
<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next">
<Publish Event="NewDialog" Value="FeaturesDlg"><![CDATA[NR_LICENSE_KEY <> " "]]></Publish>
<Publish Event="NewDialog" Value="FeaturesDlg" Condition="NR_LICENSE_KEY &lt;&gt; &quot; &quot;" />
</Control>
<Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
<Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
<Publish Event="SpawnDialog" Value="CancelDlg" />
</Control>
</Dialog>
</UI>
Expand Down

0 comments on commit acd12fa

Please sign in to comment.