Skip to content

Commit 7f5d417

Browse files
committed
direct p/invoke
1 parent 75fb8d3 commit 7f5d417

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</PropertyGroup>
2121

2222
<PropertyGroup>
23+
<SdkSrcRoot>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', 'src'))</SdkSrcRoot>
2324
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2425
<LangVersion>Latest</LangVersion>
2526
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>

NuGet.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
<add key="vs-impl" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json" />
2929
<!-- Used for Rich Navigation indexing task -->
3030
<add key="richnav" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-buildservices/nuget/v3/index.json" />
31-
32-
<!-- remove once https://www.nuget.org/packages/WixToolset.Dtf.WindowsInstaller is uploaded to dotnet feed -->
33-
<add key="local" value="c:\temp\packages" />
3431
</packageSources>
3532
<disabledPackageSources>
3633
<clear />

eng/dependabot/Packages.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<!-- Packages in this file have versions updated periodically by Dependabot. Versions managed by Darc/Maestro should be in ..\Packages.props. -->
44

55
<ItemGroup>
6-
<PackageVersion Include="WixToolset.Dtf.WindowsInstaller" Version="4.0.6" />
7-
86
<!--Test dependencies-->
97
<PackageVersion Include="Verify.Xunit" Version="25.0.2" />
108
<PackageVersion Include="Verify.DiffPlex" Version="3.0.0" />

src/Installer/finalizer/Program.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
5-
using System.IO;
64
using Microsoft.Win32;
7-
using WixToolset.Dtf.WindowsInstaller;
5+
using Microsoft.Win32.Msi;
86

97
if (args.Length < 3)
108
{
@@ -99,7 +97,8 @@ static bool DetectSdk(string featureBandVersion, string platform)
9997

10098
static bool RemoveDependent(string dependent)
10199
{
102-
Installer.SetInternalUI(InstallUIOptions.Silent);
100+
// Disable MSI UI
101+
_ = MsiSetInternalUI((uint)InstallUILevel.NoChange, IntPtr.Zero);
103102

104103
// Open the installer dependencies registry key
105104
// This has to be an exhaustive search as we're not looking for a specific provider key, but for a specific dependent
@@ -108,7 +107,7 @@ static bool RemoveDependent(string dependent)
108107
if (hkInstallerDependenciesKey == null)
109108
{
110109
Console.WriteLine("Installer dependencies key does not exist.");
111-
return false; // No dependencies to remove
110+
return false;
112111
}
113112

114113
// Iterate over each provider key in the dependencies
@@ -124,10 +123,8 @@ static bool RemoveDependent(string dependent)
124123
if (hkDependentsKey == null) continue;
125124

126125
// Check if the dependent exists and continue if it does not
127-
string[] dependentsKeys = hkDependentsKey.GetSubKeyNames();
128126
bool dependentExists = false;
129-
130-
foreach (string dependentsKeyName in dependentsKeys)
127+
foreach (string dependentsKeyName in hkDependentsKey.GetSubKeyNames())
131128
{
132129
if (string.Equals(dependentsKeyName, dependent, StringComparison.OrdinalIgnoreCase))
133130
{
@@ -138,7 +135,7 @@ static bool RemoveDependent(string dependent)
138135

139136
if (!dependentExists)
140137
{
141-
continue; // Skip to the next provider key if the dependent does not exist
138+
continue;
142139
}
143140

144141
Console.WriteLine($"Dependent match found: {dependent}");
@@ -163,8 +160,8 @@ static bool RemoveDependent(string dependent)
163160
{
164161
string productCode = hkProviderKey.GetValue("ProductId").ToString();
165162

166-
// Configure the product to be absent
167-
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "");
163+
// Configure the product to be absent (uninstall the product)
164+
uint error = MsiConfigureProductEx(productCode, (int)InstallUILevel.Default, InstallState.ABSENT, "");
168165
Console.WriteLine("Product configured to absent successfully.");
169166
}
170167
catch (Exception ex)
@@ -244,3 +241,11 @@ static bool IsRebootPending()
244241
Console.WriteLine("No reboot pending.");
245242
return false;
246243
}
244+
245+
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
246+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
247+
static extern uint MsiConfigureProductEx(string szProduct, int iInstallLevel, InstallState eInstallState, string szCommandLine);
248+
249+
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
250+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
251+
static extern uint MsiSetInternalUI(uint dwUILevel, IntPtr phWnd);

src/Installer/finalizer/finalizer.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(SdkTargetFramework)-windows</TargetFramework>
5-
<OutputType>Exe</OutputType>
5+
<OutputType>WinExe</OutputType>
66
<PublishAot>true</PublishAot>
77
<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier>
88
<_IsPublishing>true</_IsPublishing>
99
<PublishDir>$(ArtifactsDir)bin\finalizer\$(Configuration)\$(SdkTargetFramework)-win-$(Architecture)\publish</PublishDir>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="WixToolset.Dtf.WindowsInstaller" />
13+
<Compile Include="$(SdkSrcRoot)Microsoft.Win32.Msi\InstallUILevel.cs" />
14+
<Compile Include="$(SdkSrcRoot)Microsoft.Win32.Msi\InstallState.cs" />
1415
</ItemGroup>
1516

1617
<Target Name="PublishOnBuild" AfterTargets="Build" DependsOnTargets="Publish" />

0 commit comments

Comments
 (0)