Skip to content

Commit b25c785

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

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
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: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
using System;
55
using System.IO;
6+
using System.Runtime.InteropServices;
67
using Microsoft.Win32;
7-
using WixToolset.Dtf.WindowsInstaller;
8+
using Microsoft.Win32.Msi;
89

910
if (args.Length < 3)
1011
{
@@ -99,7 +100,8 @@ static bool DetectSdk(string featureBandVersion, string platform)
99100

100101
static bool RemoveDependent(string dependent)
101102
{
102-
Installer.SetInternalUI(InstallUIOptions.Silent);
103+
// Disable MSI UI
104+
_ = MsiSetInternalUI((uint)InstallUILevel.NoChange, IntPtr.Zero);
103105

104106
// Open the installer dependencies registry key
105107
// This has to be an exhaustive search as we're not looking for a specific provider key, but for a specific dependent
@@ -108,7 +110,7 @@ static bool RemoveDependent(string dependent)
108110
if (hkInstallerDependenciesKey == null)
109111
{
110112
Console.WriteLine("Installer dependencies key does not exist.");
111-
return false; // No dependencies to remove
113+
return false;
112114
}
113115

114116
// Iterate over each provider key in the dependencies
@@ -124,10 +126,8 @@ static bool RemoveDependent(string dependent)
124126
if (hkDependentsKey == null) continue;
125127

126128
// Check if the dependent exists and continue if it does not
127-
string[] dependentsKeys = hkDependentsKey.GetSubKeyNames();
128129
bool dependentExists = false;
129-
130-
foreach (string dependentsKeyName in dependentsKeys)
130+
foreach (string dependentsKeyName in hkDependentsKey.GetSubKeyNames())
131131
{
132132
if (string.Equals(dependentsKeyName, dependent, StringComparison.OrdinalIgnoreCase))
133133
{
@@ -138,7 +138,7 @@ static bool RemoveDependent(string dependent)
138138

139139
if (!dependentExists)
140140
{
141-
continue; // Skip to the next provider key if the dependent does not exist
141+
continue;
142142
}
143143

144144
Console.WriteLine($"Dependent match found: {dependent}");
@@ -163,8 +163,8 @@ static bool RemoveDependent(string dependent)
163163
{
164164
string productCode = hkProviderKey.GetValue("ProductId").ToString();
165165

166-
// Configure the product to be absent
167-
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "");
166+
// Configure the product to be absent (uninstall the product)
167+
uint error = MsiConfigureProductEx(productCode, (int)InstallUILevel.Default, InstallState.ABSENT, "");
168168
Console.WriteLine("Product configured to absent successfully.");
169169
}
170170
catch (Exception ex)
@@ -244,3 +244,11 @@ static bool IsRebootPending()
244244
Console.WriteLine("No reboot pending.");
245245
return false;
246246
}
247+
248+
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
249+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
250+
static extern uint MsiConfigureProductEx(string szProduct, int iInstallLevel, InstallState eInstallState, string szCommandLine);
251+
252+
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
253+
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
254+
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)