diff options
author | StefanStojanovic <StefanStojanovic@users.noreply.github.com> | 2022-10-25 22:40:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-25 20:40:36 +0000 |
commit | 321c30138c82390ea5ad6b0a612dff294203a877 (patch) | |
tree | 2f27ca578d9b162eac11f0c8bee460b17138b531 /src/ext/NetFx/wixext/NetFxCompiler.cs | |
parent | 98080672cdbbde00ea40a96c1ce38e8a52f24fee (diff) | |
download | wix-321c30138c82390ea5ad6b0a612dff294203a877.tar.gz wix-321c30138c82390ea5ad6b0a612dff294203a877.tar.bz2 wix-321c30138c82390ea5ad6b0a612dff294203a877.zip |
Add NetFx .NET compatibility check for MSI (#262)
Adds new custom element in NetFx extension for running NetCoreCheck.exe
tool from within the MSI installer - `<netfx:DotNetCompatibilityCheck
/>`. The checks are run before evaluating launch conditions, so their
results can be used in those conditions. There is no limitation on the
number of checks that can be run, so installer may query various
runtimes on different platforms and versions and with different roll
forward policies.
Fixes https://github.com/wixtoolset/issues/issues/6264
Diffstat (limited to 'src/ext/NetFx/wixext/NetFxCompiler.cs')
-rw-r--r-- | src/ext/NetFx/wixext/NetFxCompiler.cs | 213 |
1 files changed, 211 insertions, 2 deletions
diff --git a/src/ext/NetFx/wixext/NetFxCompiler.cs b/src/ext/NetFx/wixext/NetFxCompiler.cs index 739618e9..f3c91918 100644 --- a/src/ext/NetFx/wixext/NetFxCompiler.cs +++ b/src/ext/NetFx/wixext/NetFxCompiler.cs | |||
@@ -40,7 +40,6 @@ namespace WixToolset.Netfx | |||
40 | break; | 40 | break; |
41 | } | 41 | } |
42 | break; | 42 | break; |
43 | case "Bundle": | ||
44 | case "Fragment": | 43 | case "Fragment": |
45 | switch (element.Name.LocalName) | 44 | switch (element.Name.LocalName) |
46 | { | 45 | { |
@@ -50,8 +49,45 @@ namespace WixToolset.Netfx | |||
50 | case "DotNetCoreSearchRef": | 49 | case "DotNetCoreSearchRef": |
51 | this.ParseDotNetCoreSearchRefElement(intermediate, section, element); | 50 | this.ParseDotNetCoreSearchRefElement(intermediate, section, element); |
52 | break; | 51 | break; |
52 | case "DotNetCompatibilityCheck": | ||
53 | this.ParseDotNetCompatibilityCheckElement(intermediate, section, element); | ||
54 | break; | ||
55 | case "DotNetCompatibilityCheckRef": | ||
56 | this.ParseDotNetCompatibilityCheckRefElement(intermediate, section, element); | ||
57 | break; | ||
58 | default: | ||
59 | this.ParseHelper.UnexpectedElement(parentElement, element); | ||
60 | break; | ||
61 | } | ||
62 | break; | ||
63 | case "Bundle": | ||
64 | switch (element.Name.LocalName) | ||
65 | { | ||
66 | case "DotNetCoreSearch": | ||
67 | this.ParseDotNetCoreSearchElement(intermediate, section, element); | ||
68 | break; | ||
69 | case "DotNetCoreSearchRef": | ||
70 | this.ParseDotNetCoreSearchRefElement(intermediate, section, element); | ||
71 | break; | ||
72 | default: | ||
73 | this.ParseHelper.UnexpectedElement(parentElement, element); | ||
74 | break; | ||
75 | } | ||
76 | break; | ||
77 | case "Package": | ||
78 | case "Module": | ||
79 | switch (element.Name.LocalName) | ||
80 | { | ||
81 | case "DotNetCompatibilityCheck": | ||
82 | this.ParseDotNetCompatibilityCheckElement(intermediate, section, element); | ||
83 | break; | ||
84 | case "DotNetCompatibilityCheckRef": | ||
85 | this.ParseDotNetCompatibilityCheckRefElement(intermediate, section, element); | ||
86 | break; | ||
87 | default: | ||
88 | this.ParseHelper.UnexpectedElement(parentElement, element); | ||
89 | break; | ||
53 | } | 90 | } |
54 | |||
55 | break; | 91 | break; |
56 | default: | 92 | default: |
57 | this.ParseHelper.UnexpectedElement(parentElement, element); | 93 | this.ParseHelper.UnexpectedElement(parentElement, element); |
@@ -325,5 +361,178 @@ namespace WixToolset.Netfx | |||
325 | }); | 361 | }); |
326 | } | 362 | } |
327 | } | 363 | } |
364 | |||
365 | /// <summary> | ||
366 | /// Parses a DotNetCompatibilityCheck element. | ||
367 | /// </summary> | ||
368 | /// <param name="element">The element to parse.</param> | ||
369 | private void ParseDotNetCompatibilityCheckElement(Intermediate intermediate, IntermediateSection section, XElement element) | ||
370 | { | ||
371 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
372 | Identifier id = null; | ||
373 | string property = null; | ||
374 | string runtimeType = null; | ||
375 | string platform = null; | ||
376 | string version = null; | ||
377 | string rollForward = "Minor"; | ||
378 | |||
379 | foreach (var attrib in element.Attributes()) | ||
380 | { | ||
381 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
382 | { | ||
383 | switch (attrib.Name.LocalName) | ||
384 | { | ||
385 | case "Id": | ||
386 | id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
387 | break; | ||
388 | case "Property": | ||
389 | property = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | ||
390 | break; | ||
391 | case "RuntimeType": | ||
392 | runtimeType = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
393 | switch (runtimeType.ToLower()) | ||
394 | { | ||
395 | case "aspnet": | ||
396 | runtimeType = "Microsoft.AspNetCore.App"; | ||
397 | break; | ||
398 | case "desktop": | ||
399 | runtimeType = "Microsoft.WindowsDesktop.App"; | ||
400 | break; | ||
401 | case "core": | ||
402 | runtimeType = "Microsoft.NETCore.App"; | ||
403 | break; | ||
404 | default: | ||
405 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, element.Name.LocalName, attrib.Name.LocalName, runtimeType, "aspnet", "desktop", "core")); | ||
406 | break; | ||
407 | } | ||
408 | break; | ||
409 | case "Platform": | ||
410 | platform = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
411 | switch (platform.ToLower()) | ||
412 | { | ||
413 | case "x86": | ||
414 | case "x64": | ||
415 | case "arm64": | ||
416 | platform = platform.ToLower(); | ||
417 | break; | ||
418 | default: | ||
419 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, element.Name.LocalName, attrib.Name.LocalName, platform, "x86", "x64", "arm64")); | ||
420 | break; | ||
421 | } | ||
422 | break; | ||
423 | case "Version": | ||
424 | version = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib); | ||
425 | break; | ||
426 | case "RollForward": | ||
427 | rollForward = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
428 | switch (rollForward.ToLower()) | ||
429 | { | ||
430 | case "latestmajor": | ||
431 | rollForward = "LatestMajor"; | ||
432 | break; | ||
433 | case "major": | ||
434 | rollForward = "Major"; | ||
435 | break; | ||
436 | case "latestminor": | ||
437 | rollForward = "LatestMinor"; | ||
438 | break; | ||
439 | case "minor": | ||
440 | rollForward = "Minor"; | ||
441 | break; | ||
442 | case "latestpatch": | ||
443 | rollForward = "LatestPatch"; | ||
444 | break; | ||
445 | case "disable": | ||
446 | rollForward = "Disable"; | ||
447 | break; | ||
448 | default: | ||
449 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, element.Name.LocalName, attrib.Name.LocalName, rollForward, "latestmajor", "major", "latestminor", "minor", "latestpatch", "disable")); | ||
450 | break; | ||
451 | } | ||
452 | break; | ||
453 | default: | ||
454 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
455 | break; | ||
456 | } | ||
457 | } | ||
458 | else | ||
459 | { | ||
460 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); | ||
461 | } | ||
462 | } | ||
463 | |||
464 | if (null == id) | ||
465 | { | ||
466 | id = this.ParseHelper.CreateIdentifier("ndncc", property, runtimeType, platform, version); | ||
467 | } | ||
468 | |||
469 | if (String.IsNullOrEmpty(property)) | ||
470 | { | ||
471 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Property")); | ||
472 | } | ||
473 | |||
474 | if (String.IsNullOrEmpty(runtimeType)) | ||
475 | { | ||
476 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "RuntimeType")); | ||
477 | } | ||
478 | |||
479 | if (String.IsNullOrEmpty(platform)) | ||
480 | { | ||
481 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Platform")); | ||
482 | } | ||
483 | |||
484 | if (String.IsNullOrEmpty(version)) | ||
485 | { | ||
486 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Version")); | ||
487 | } | ||
488 | |||
489 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); | ||
490 | |||
491 | this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4NetFxDotNetCompatibilityCheck", this.Context.Platform, CustomActionPlatforms.ARM64 | CustomActionPlatforms.X64 | CustomActionPlatforms.X86); | ||
492 | |||
493 | if (!this.Messaging.EncounteredError) | ||
494 | { | ||
495 | section.AddSymbol(new NetFxDotNetCompatibilityCheckSymbol(sourceLineNumbers, id) | ||
496 | { | ||
497 | RuntimeType = runtimeType, | ||
498 | Platform = platform, | ||
499 | Version = version, | ||
500 | RollForward = rollForward, | ||
501 | Property = property, | ||
502 | }); | ||
503 | } | ||
504 | } | ||
505 | |||
506 | /// <summary> | ||
507 | /// Parses a DotNetCompatibilityCheckRef element. | ||
508 | /// </summary> | ||
509 | /// <param name="element">The element to parse.</param> | ||
510 | private void ParseDotNetCompatibilityCheckRefElement(Intermediate intermediate, IntermediateSection section, XElement element) | ||
511 | { | ||
512 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
513 | |||
514 | foreach (var attrib in element.Attributes()) | ||
515 | { | ||
516 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
517 | { | ||
518 | switch (attrib.Name.LocalName) | ||
519 | { | ||
520 | case "Id": | ||
521 | var refId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | ||
522 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, NetfxSymbolDefinitions.NetFxDotNetCompatibilityCheck, refId); | ||
523 | break; | ||
524 | default: | ||
525 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
526 | break; | ||
527 | } | ||
528 | } | ||
529 | else | ||
530 | { | ||
531 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); | ||
532 | } | ||
533 | } | ||
534 | |||
535 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); | ||
536 | } | ||
328 | } | 537 | } |
329 | } | 538 | } |