@joebigelow / wix / commits / db17200a

Remove MsuPackage/@KB and Permanent attributes

Windows no longer allows for the silent removal of MSUs which renders the KB and Permanent attributes irrelevant. This removes both. Fixes 6749 Fixes 6801

Rob Mensching committed Jun 15, 2022 at 13:44 UTC db17200a99cfcc2ec5af4a5893be44f11087dc7a
14 files changed +130 -39
src/api/wix/WixToolset.Data/Symbols/WixBundleMsuPackageSymbol.cs
+1 -9
@@ -10,8 +10,7 @@ namespace WixToolset.Data
10 SymbolDefinitionType.WixBundleMsuPackage,
11 new[]
12 {
13 - new IntermediateFieldDefinition(nameof(WixBundleMsuPackageSymbolFields.DetectCondition), IntermediateFieldType.String),
14 - new IntermediateFieldDefinition(nameof(WixBundleMsuPackageSymbolFields.MsuKB), IntermediateFieldType.String),
13 + new IntermediateFieldDefinition(nameof(WixBundleMsuPackageSymbolFields.DetectCondition), IntermediateFieldType.String)
14 },
15 typeof(WixBundleMsuPackageSymbol));
16 }
@@ -22,7 +21,6 @@ namespace WixToolset.Data.Symbols
21 public enum WixBundleMsuPackageSymbolFields
22 {
23 DetectCondition,
25 - MsuKB,
24 }
25
26 public class WixBundleMsuPackageSymbol : IntermediateSymbol
@@ -42,11 +40,5 @@ namespace WixToolset.Data.Symbols
40 get => (string)this.Fields[(int)WixBundleMsuPackageSymbolFields.DetectCondition];
41 set => this.Set((int)WixBundleMsuPackageSymbolFields.DetectCondition, value);
42 }
45 -
46 - public string MsuKB
47 - {
48 - get => (string)this.Fields[(int)WixBundleMsuPackageSymbolFields.MsuKB];
49 - set => this.Set((int)WixBundleMsuPackageSymbolFields.MsuKB, value);
50 - }
43 }
44 }
\ No newline at end of file
src/wix/WixToolset.Converters/WixConverter.cs
+26
@@ -1216,6 +1216,22 @@ namespace WixToolset.Converters
1216 this.ConvertSuppressSignatureValidation(element);
1217
1218 this.UpdatePackageCacheAttribute(element);
1219 +
1220 + var kbAttribute = element.Attribute("KB");
1221 +
1222 + if (null != kbAttribute
1223 + && this.OnInformation(ConverterTestType.MsuPackageKBObsolete, element, "The MsuPackage element contains obsolete '{0}' attribute. Windows no longer supports silently removing MSUs so the attribute is unnecessary. The attribute will be removed.", kbAttribute.Name))
1224 + {
1225 + kbAttribute.Remove();
1226 + }
1227 +
1228 + var permanentAttribute = element.Attribute("Permanent");
1229 +
1230 + if (null != permanentAttribute
1231 + && this.OnInformation(ConverterTestType.MsuPackagePermanentObsolete, element, "The MsuPackage element contains obsolete '{0}' attribute. MSU packages are now always permanent because Windows no longer supports silently removing MSUs. The attribute will be removed.", permanentAttribute.Name))
1232 + {
1233 + permanentAttribute.Remove();
1234 + }
1235 }
1236
1237 private void ConvertProductElement(XElement element)
@@ -2664,6 +2680,16 @@ namespace WixToolset.Converters
2680 /// Cache attribute value updated.
2681 /// </summary>
2682 BundlePackageCacheAttributeValueObsolete,
2683 +
2684 + /// <summary>
2685 + /// The MsuPackage element contains obsolete '{0}' attribute. Windows no longer supports silently removing MSUs so the attribute is unnecessary. The attribute will be removed.
2686 + /// </summary>
2687 + MsuPackageKBObsolete,
2688 +
2689 + /// <summary>
2690 + /// The MsuPackage element contains obsolete '{0}' attribute. MSU packages are now always permanent because Windows no longer supports silently removing MSUs. The attribute will be removed.
2691 + /// </summary>
2692 + MsuPackagePermanentObsolete,
2693 }
2694 }
2695 }
src/wix/WixToolset.Core.Burn/Bundles/CreateBurnManifestCommand.cs
-1
@@ -499,7 +499,6 @@ namespace WixToolset.Core.Burn.Bundles
499 else if (package.SpecificPackageSymbol is WixBundleMsuPackageSymbol msuPackage) // MSU
500 {
501 writer.WriteAttributeString("DetectCondition", msuPackage.DetectCondition);
502 - writer.WriteAttributeString("KB", msuPackage.MsuKB);
502 }
503
504 var packageMsiProperties = msiPropertiesByPackage[package.PackageId];
src/wix/WixToolset.Core/Compiler_Bundle.cs
+2 -22
@@ -2019,7 +2019,6 @@ namespace WixToolset.Core
2019 string detectCondition = null;
2020 string protocol = null;
2021 long? installSize = null;
2022 - string msuKB = null;
2022 var enableFeatureSelection = YesNoType.NotSet;
2023 var forcePerMachine = YesNoType.NotSet;
2024 CompilerPackagePayload childCompilerPackagePayload = null;
@@ -2114,6 +2113,7 @@ namespace WixToolset.Core
2113 break;
2114 case "Permanent":
2115 permanent = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
2116 + allowed = (packageType != WixBundlePackageType.Msu);
2117 break;
2118 case "Visible":
2119 visible = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
@@ -2153,10 +2153,6 @@ namespace WixToolset.Core
2153 case "InstallSize":
2154 installSize = this.Core.GetAttributeLongValue(sourceLineNumbers, attrib, 0, Int64.MaxValue);
2155 break;
2156 - case "KB":
2157 - msuKB = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
2158 - allowed = (packageType == WixBundlePackageType.Msu);
2159 - break;
2156 case "Compressed":
2157 compilerPayload.ParseCompressed(attrib);
2158 hasPayloadInfo = true;
@@ -2464,21 +2460,6 @@ namespace WixToolset.Core
2460 }
2461 else if (packageType == WixBundlePackageType.Msu)
2462 {
2467 - if (permanent == YesNoType.No)
2468 - {
2469 - if (String.IsNullOrEmpty(msuKB))
2470 - {
2471 - this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "KB", "Permanent", "no"));
2472 - }
2473 - }
2474 - else if (permanent == YesNoType.NotSet)
2475 - {
2476 - if (String.IsNullOrEmpty(msuKB))
2477 - {
2478 - this.Core.Write(ErrorMessages.ExpectedAttributeWithoutOtherAttribute(sourceLineNumbers, node.Name.LocalName, "KB", "Permanent"));
2479 - }
2480 - }
2481 -
2463 // Detect condition is recommended for Msu packages.
2464 if (String.IsNullOrEmpty(detectCondition))
2465 {
@@ -2583,8 +2564,7 @@ namespace WixToolset.Core
2564 case WixBundlePackageType.Msu:
2565 this.Core.AddSymbol(new WixBundleMsuPackageSymbol(sourceLineNumbers, id)
2566 {
2586 - DetectCondition = detectCondition,
2587 - MsuKB = msuKB
2567 + DetectCondition = detectCondition
2568 });
2569 break;
2570 }
src/wix/test/WixToolsetTest.Converters/MsuPackageFixture.cs new
+60
@@ -0,0 +1,60 @@
1 +// 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.
2 +
3 +namespace WixToolsetTest.Converters
4 +{
5 + using System;
6 + using System.Linq;
7 + using System.Xml.Linq;
8 + using WixBuildTools.TestSupport;
9 + using WixToolset.Converters;
10 + using WixToolsetTest.Converters.Mocks;
11 + using Xunit;
12 +
13 + public class MsuPackageFixture : BaseConverterFixture
14 + {
15 + [Fact]
16 + public void CanRemoveMsuPackageDeprecatedAttributes()
17 + {
18 + var parse = String.Join(Environment.NewLine,
19 + "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
20 + " <Fragment>",
21 + " <PackageGroup Id='msu'>",
22 + " <MsuPackage Id='PermanentMsuPackage' KB='1234' Permanent='yes' DetectCondition='none'>",
23 + " <MsuPackagePayload DownloadUrl='example.com' SourceFile='ignored.msu' />",
24 + " </MsuPackage>",
25 + " </PackageGroup>",
26 + " </Fragment>",
27 + "</Wix>");
28 +
29 + var expected = new[]
30 + {
31 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
32 + " <Fragment>",
33 + " <PackageGroup Id=\"msu\">",
34 + " <MsuPackage Id=\"PermanentMsuPackage\" DetectCondition=\"none\">",
35 + " <MsuPackagePayload DownloadUrl=\"example.com\" SourceFile=\"ignored.msu\" />",
36 + " </MsuPackage>",
37 + " </PackageGroup>",
38 + " </Fragment>",
39 + "</Wix>"
40 + };
41 +
42 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
43 +
44 + var messaging = new MockMessaging();
45 + var converter = new WixConverter(messaging, 2, null, null);
46 +
47 + var errors = converter.ConvertDocument(document);
48 +
49 + var actualLines = UnformattedDocumentLines(document);
50 + WixAssert.CompareLineByLine(new[]
51 + {
52 + "[Converted] The MsuPackage element contains obsolete 'KB' attribute. Windows no longer supports silently removing MSUs so the attribute is unnecessary. The attribute will be removed. (MsuPackageKBObsolete)",
53 + "[Converted] The MsuPackage element contains obsolete 'Permanent' attribute. MSU packages are now always permanent because Windows no longer supports silently removing MSUs. The attribute will be removed. (MsuPackagePermanentObsolete)",
54 + }, messaging.Messages.Select(m => m.ToString()).ToArray());
55 + WixAssert.CompareLineByLine(expected, actualLines);
56 +
57 + Assert.Equal(2, errors);
58 + }
59 + }
60 +}
src/wix/test/WixToolsetTest.CoreIntegration/MsuPackageFixture.cs
+24
@@ -88,5 +88,29 @@ namespace WixToolsetTest.CoreIntegration
88 Assert.Equal("The MsuPackage/@CacheId attribute was not found; it is required when attribute CertificatePublicKey is specified.", message.ToString());
89 }
90 }
91 +
92 + [Fact]
93 + public void ErrorWhenSpecifyingPermanent()
94 + {
95 + var folder = TestData.Get(@"TestData", "MsuPackage");
96 +
97 + using (var fs = new DisposableFileSystem())
98 + {
99 + var baseFolder = fs.GetFolder();
100 +
101 + var result = WixRunner.Execute(false, new[]
102 + {
103 + "build",
104 + Path.Combine(folder, "PermanentMsuPackage.wxs"),
105 + "-o", Path.Combine(baseFolder, "test.wixlib")
106 + });
107 +
108 + WixAssert.CompareLineByLine(new[]
109 + {
110 + "The MsuPackage element contains an unexpected attribute 'Permanent'.",
111 + }, result.Messages.Select(m => m.ToString()).ToArray());
112 + Assert.Equal(4, result.ExitCode);
113 + }
114 + }
115 }
116 }
src/wix/test/WixToolsetTest.CoreIntegration/RemotePayloadFixture.cs
+1 -1
@@ -289,7 +289,7 @@ namespace WixToolsetTest.CoreIntegration
289 }, elements);
290
291 // Append required attributes to build.
292 - elements[0] = elements[0].Replace(">", " KB='KB2937592' DetectCondition='test'>");
292 + elements[0] = elements[0].Replace(">", " DetectCondition='test'>");
293
294 var remotePayloadSourceText = "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>" +
295 " <Fragment>" +
src/wix/test/WixToolsetTest.CoreIntegration/TestData/MsuPackage/Bundle.wxs
+1 -1
@@ -5,7 +5,7 @@
5 </BootstrapperApplication>
6
7 <Chain>
8 - <MsuPackage DetectCondition="DetectedTheMsu" KB="xyz" SourceFile="test.msu" />
8 + <MsuPackage DetectCondition="DetectedTheMsu" SourceFile="test.msu" />
9 </Chain>
10 </Bundle>
11 </Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/MsuPackage/BundleUsingCertificateVerification.wxs
+1 -1
@@ -5,7 +5,7 @@
5 </BootstrapperApplication>
6
7 <Chain>
8 - <MsuPackage DetectCondition="DetectedTheMsu" KB="xyz" CacheId="8cf75b99-13c0-4184-82ce-dbde45dcd55a">
8 + <MsuPackage DetectCondition="DetectedTheMsu" CacheId="8cf75b99-13c0-4184-82ce-dbde45dcd55a">
9 <MsuPackagePayload Name='Windows8.1-KB2937592-x86.msu' DownloadUrl='http://wixtoolset.org' CertificatePublicKey="abc" CertificateThumbprint="123" Size='309544' />
10 </MsuPackage>
11 </Chain>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/MsuPackage/BundleUsingCertificateVerificationWithoutCacheId.wxs
+1 -1
@@ -5,7 +5,7 @@
5 </BootstrapperApplication>
6
7 <Chain>
8 - <MsuPackage DetectCondition="DetectedTheMsu" KB="xyz" >
8 + <MsuPackage DetectCondition="DetectedTheMsu">
9 <MsuPackagePayload Name='Windows8.1-KB2937592-x86.msu' DownloadUrl='http://wixtoolset.org' CertificatePublicKey="abc" CertificateThumbprint="123" Size='309544' />
10 </MsuPackage>
11 </Chain>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/MsuPackage/PermanentMsuPackage.wxs new
+10
@@ -0,0 +1,10 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Fragment>
4 + <PackageGroup Id="BundlePackages">
5 + <MsuPackage Id="PermanentMsuPackage" Permanent="yes" DetectCondition="none">
6 + <MsuPackagePayload DownloadUrl="example.com" SourceFile="ignored.msu" />
7 + </MsuPackage>
8 + </PackageGroup>
9 + </Fragment>
10 +</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndHash.wxs
+1 -1
@@ -2,7 +2,7 @@
2 <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <PackageGroup Id="BundlePackages">
5 - <MsuPackage Id="MissingSourceFileAndHash" Permanent="yes" DetectCondition="none">
5 + <MsuPackage Id="MissingSourceFileAndHash" DetectCondition="none">
6 <MsuPackagePayload DownloadUrl="example.com" />
7 </MsuPackage>
8 </PackageGroup>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHashAndMissingDownloadUrl.wxs
+1 -1
@@ -2,7 +2,7 @@
2 <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <PackageGroup Id="BundlePackages">
5 - <MsuPackage Id="SpecifiedHashAndMissingDownloadUrl" Permanent="yes" DetectCondition="none">
5 + <MsuPackage Id="SpecifiedHashAndMissingDownloadUrl" DetectCondition="none">
6 <MsuPackagePayload Name="example.msu" Hash="abcd" Size="1" Version="1.0.0.0" ProductName="KB1234567" Description="fake msu" />
7 </MsuPackage>
8 </PackageGroup>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/RemotePayload/DiversePayloadsBundle.wxs
+1 -1
@@ -6,7 +6,7 @@
6 <Chain>
7 <PackageGroupRef Id="ExternalContainerPackages" />
8 <ExePackage SourceFile="signed_bundle_engine.exe" DetectCondition="none" Permanent="yes" />
9 - <MsuPackage SourceFile="Windows8.1-KB2937592-x86.msu" DetectCondition="none" Permanent="yes" Compressed="no" DownloadUrl="http://example.com/test.msu" />
9 + <MsuPackage SourceFile="Windows8.1-KB2937592-x86.msu" DetectCondition="none" Compressed="no" DownloadUrl="http://example.com/test.msu" />
10 <MsiPackage SourceFile="test.msi" Compressed="no" />
11 </Chain>
12 <Container Name="External.cab">