除了解压缩appx文件并检查给定方案的文件以获取appx文件的完整程序包名称之外,还有没有更简单的方法?
我在具有以下功能的计算机上安装特定的appx文件
Add-AppxPackage c:\my_data\Microsoft.NET.CoreRuntime.2.2.appx -ForceUpdateFromAnyVersion
在第二次运行时,我得到了预期的错误(由于我的本地化,因此从MSDN复制)
ERROR_PACKAGE_ALREADY_EXISTS
0x80073CFB The provided package is already installed, and reinstallation of the package is blocked.
You may get this error if installing a package that is not bitwise identical to the package that is already installed. Note that the digital signature is also part of the package. Hence if a package is rebuilt or resigned, it is no longer bitwise identical to the previously installed package. Two possible options to fix this error are: (1) Increment the version number of the app, then rebuild and resign the package (2) Remove the old package for every user on the system before installing the new package.
美好的。那我该如何卸载该应用程序呢?通常我们执行以下代码:
$coreFileName = "Microsoft.NET.CoreRuntime.2.2"
Get-AppxPackage | Where { $_.PackageFullName.Contains($coreFileName) } | Remove-AppxPackage
但是我将删除比安装的软件包更多的软件包,因为有两个相同的软件包,它们的区别仅在于它们的平台:
Name : Microsoft.NET.CoreRuntime.2.2
Publisher : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Architecture : X86
ResourceId :
Version : 2.2.27902.3
PackageFullName : Microsoft.NET.CoreRuntime.2.2_2.2.27902.3_x86__8wekyb3d8bbwe
InstallLocation : C:\Program Files\WindowsApps\Microsoft.NET.CoreRuntime.2.2_2.2.27902.3_x86__8wekyb3d8bbwe
IsFramework : True
PackageFamilyName : Microsoft.NET.CoreRuntime.2.2_8wekyb3d8bbwe
PublisherId : 8wekyb3d8bbwe
PackageUserInformation : {S-1-5-21-73586283-1958367476-839522115-408575 [DELEC01\schulz_j]: Installed}
...
Name : Microsoft.NET.CoreRuntime.2.2
Publisher : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Architecture : X64
ResourceId :
Version : 2.2.27902.3
PackageFullName : Microsoft.NET.CoreRuntime.2.2_2.2.27902.3_x64__8wekyb3d8bbwe
InstallLocation : C:\Program Files\WindowsApps\Microsoft.NET.CoreRuntime.2.2_2.2.27902.3_x64__8wekyb3d8bbwe
IsFramework : True
PackageFamilyName : Microsoft.NET.CoreRuntime.2.2_8wekyb3d8bbwe
PublisherId : 8wekyb3d8bbwe
PackageUserInformation : {S-1-5-21-73586283-1958367476-839522115-408575 [DELEC01\schulz_j]: Installed}
...
我应该如何获得真实的包裹全名,而该包裹的全名仅与包裹直接匹配,而无需事先知道包裹的名称是什么?
我希望Get-AppxPackageManifest
但它让我失望
Get-AppxPackageManifest c:\my_data\Microsoft.NET.CoreRuntime.2.2.appx
因为它是空的。
编辑:由于我草率行事,所以我没有很好地解释这个意图。让我更精确地
我要安装的潜在appx文件称为Microsoft.NET.CoreRuntime.2.2.appx
。从名字上我无法推断出它是x86还是x64。当我安装此appx文件的较新版本时,我需要删除此包,而仅删除此包。
因此,我正在寻找一种将Get-AppXPackage结果与appx文件相关的方法。
编码
$coreFileName = "Microsoft.NET.CoreRuntime.2.2"
Get-AppxPackage | Where { $_.PackageFullName.Contains($coreFileName) }
返回两个软件包x64和x86,但是由于我只安装一个appx文件,所以我不想卸载两个软件包。
这就是我被困住的地方。给定上面的文件(不是程序包名称)c:\my_data\Microsoft.NET.CoreRuntime.2.2.appx
:,我如何获取此文件的appx详细信息?
一种方法是提取appx文件,因为它只是一个zip文件,然后检查AppManifest.xml文件,并查找名称+平台并将其关联。
但是由于解压缩,阅读xml,删除zip等非常复杂,所以我一直在寻找一种更简便的方法来实现这一目标。
以下是一些灵感来自IDERA从ZIP存档中提取特定文件的PowerShell和逻辑。您只需要设置appx捆绑文件的完整路径位置。
本质上是...
AppxManifest.xml
从指定appx
文件中搜索并提取所有文件- 搜索提取的
AppxManifest.xml
文件的XML内容
- 从XML 1
Identity
元素获取“ CPU体系结构”的2ProcessArchitecture
属性值,并将该值保存到变量(即$bitness
)- 最后一步将删除xml-extraction创建的temp文件夹中的所有文件,然后删除该文件夹
$Path = "C:\Test\UWPTest\AppPackages\UWPTest_1.0.0.0_Debug_Test\Dependencies\x64\Microsoft.NET.CoreRuntime.2.2.appx";
$Filter = "AppxManifest.xml";
$OutPath = "$((Get-Childitem -Path $Path -Directory).Directory.FullName)\ztmp";
Add-Type -AssemblyName System.IO.Compression.FileSystem;
If(!(Test-Path -Path $OutPath)){New-Item -Path $OutPath -ItemType Directory -Force};
([System.IO.Compression.ZipFile]::OpenRead($Path)).Entries | % { Process {
If($_.FullName -like $Filter){$_ | % {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$OutPath\$($_.Name)", $true)}
}
}};
[System.IO.Compression.ZipFile]::OpenRead($Path).Dispose;
[xml]$xml = Get-Content "$OutPath\AppxManifest.xml";
$bitness = ((Select-Xml -Xml $Xml -XPath "*/*").Node).ProcessorArchitecture;
$bitness;
Remove-Item -Path "$OutPath" -Force -Recurse;
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
IgnorableNamespaces="uap">
<Identity Name="Microsoft.NET.CoreRuntime.2.2"
ProcessorArchitecture="x64"
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
Version="2.2.27902.3" />
<mp:PhoneIdentity PhoneProductId="7D3B4B8B-CA47-4518-823A-A7793F27DA93"
PhonePublisherId="6B151E87-785E-4C4A-AA41-823B05AA9A66" />
<Properties>
<Framework>true</Framework>
<DisplayName>Microsoft.NET.CoreRuntime.2.2</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Description>Microsoft .Net Core Runtime Package for Universal Windows Applications</Description>
<Logo>logo.png</Logo>
</Properties>
<Resources>
<Resource Language="en-US" />
</Resources>
<Dependencies>
<TargetDeviceFamily
Name="Windows.Universal"
MinVersion="10.0.10049.0"
MaxVersionTested="10.0.10049.0" />
</Dependencies>
</Package>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句