@@ -492,12 +492,64 @@ extern "C" HRESULT DetectSdk(LPWSTR sczSdkFeatureBandVersion, LPWSTR sczArchitec
492492 return hr;
493493}
494494
495+ void RemoveInstallStateFile (LPWSTR sczSdkFeatureBandVersion, LPWSTR sczPlatform)
496+ {
497+ HRESULT hr = S_OK;
498+ LPWSTR sczProgramData = NULL ;
499+ LPWSTR sczInstallStatePath = NULL ;
500+ LPWSTR sczPath = NULL ;
501+
502+ hr = ShelGetFolder (&sczProgramData, CSIDL_COMMON_APPDATA);
503+ ExitOnFailure (hr, " Failed to get shell folder." );
504+
505+ hr = PathConcat (sczProgramData, L" dotnet" , &sczInstallStatePath);
506+ ExitOnFailure (hr, " Failed to concat dotnet to install state path." );
507+
508+ hr = PathConcat (sczInstallStatePath, L" workloads" , &sczInstallStatePath);
509+ ExitOnFailure (hr, " Failed to concat workloads to install state path." );
510+
511+ hr = PathConcat (sczInstallStatePath, sczPlatform, &sczInstallStatePath);
512+ ExitOnFailure (hr, " Failed to concat platform (%ls) to install state path." , sczPlatform);
513+
514+ hr = PathConcat (sczInstallStatePath, sczSdkFeatureBandVersion, &sczInstallStatePath);
515+ ExitOnFailure (hr, " Failed to concat feature band (%ls) to install state path." , sczSdkFeatureBandVersion);
516+
517+ hr = PathConcat (sczInstallStatePath, L" installstate" , &sczInstallStatePath);
518+ ExitOnFailure (hr, " Failed to concat installstate to install state path." );
519+
520+ hr = PathConcat (sczInstallStatePath, L" default.json" , &sczInstallStatePath);
521+ ExitOnFailure (hr, " Failed to concat default.json to install state path." );
522+
523+ if (FileExistsEx (sczInstallStatePath, NULL ))
524+ {
525+ LogStringLine (REPORT_STANDARD, " Deleting install state file: %ls" , sczInstallStatePath);
526+ hr = FileEnsureDelete (sczInstallStatePath);
527+ ExitOnFailure (hr, " Failed to delete install state file: %ls" , sczInstallStatePath);
528+
529+ hr = PathGetParentPath (sczInstallStatePath, &sczPath);
530+ ExitOnFailure (hr, " Failed to get parent path of install state file." );
531+
532+ LogStringLine (REPORT_STANDARD, " Cleaning up empty workload folders." );
533+ DirDeleteEmptyDirectoriesToRoot (sczPath, 0 );
534+ }
535+ else
536+ {
537+ LogStringLine (REPORT_STANDARD, " Install state file does not exist: %ls" , sczInstallStatePath);
538+ }
539+
540+ LExit:
541+ ReleaseStr (sczPath);
542+ ReleaseStr (sczInstallStatePath)
543+ ReleaseStr (sczProgramData);
544+ }
545+
495546int wmain (int argc, wchar_t * argv[])
496547{
497548 HRESULT hr = S_OK;
498549 DWORD dwExitCode = 0 ;
499550 LPWSTR sczDependent = NULL ;
500551 LPWSTR sczFeatureBandVersion = NULL ;
552+ LPWSTR sczPlatform = NULL ;
501553 BOOL bRestartRequired = FALSE ;
502554 BOOL bSdkFeatureBandInstalled = FALSE ;
503555 int iMajor = 0 ;
@@ -507,16 +559,19 @@ int wmain(int argc, wchar_t* argv[])
507559 hr = ::Initialize (argc, argv);
508560 ExitOnFailure (hr, " Failed to initialize." );
509561
562+ hr = StrAllocString (&sczPlatform, argv[3 ], 0 );
563+ ExitOnFailure (hr, " Failed to copy platform argument." );
564+
510565 // Convert the full SDK version to a feature band version
511566 hr = ParseSdkVersion (argv[2 ], &sczFeatureBandVersion);
512567 ExitOnFailure (hr, " Failed to parse version, %ls." , argv[2 ]);
513568
514569 // Create the dependent value, e.g., Microsoft.NET.Sdk,6.0.300,arm64
515- hr = StrAllocFormatted (&sczDependent, L" Microsoft.NET.Sdk,%ls,%ls" , sczFeatureBandVersion, argv[ 3 ] );
570+ hr = StrAllocFormatted (&sczDependent, L" Microsoft.NET.Sdk,%ls,%ls" , sczFeatureBandVersion, sczPlatform );
516571 ExitOnFailure (hr, " Failed to create dependent." );
517572 LogStringLine (REPORT_STANDARD, " Setting target dependent to %ls." , sczDependent);
518573
519- hr = ::DetectSdk (sczFeatureBandVersion, argv[ 3 ] , &bSdkFeatureBandInstalled);
574+ hr = ::DetectSdk (sczFeatureBandVersion, sczPlatform , &bSdkFeatureBandInstalled);
520575 ExitOnFailure (hr, " Failed to detect installed SDKs." );
521576
522577 // If the feature band is still present, do not remove workloads.
@@ -529,17 +584,20 @@ int wmain(int argc, wchar_t* argv[])
529584 hr = ::RemoveDependent (sczDependent, &bRestartRequired);
530585 ExitOnFailure (hr, " Failed to remove dependent \" %ls\" ." , sczDependent);
531586
532- hr = ::DeleteWorkloadRecords (sczFeatureBandVersion, argv[ 3 ] );
587+ hr = ::DeleteWorkloadRecords (sczFeatureBandVersion, sczPlatform );
533588 ExitOnFailure (hr, " Failed to remove workload records." );
534589
535590 if (bRestartRequired)
536591 {
537592 dwExitCode = ERROR_SUCCESS_REBOOT_REQUIRED;
538593 }
539594
595+ RemoveInstallStateFile (sczFeatureBandVersion, sczPlatform);
596+
540597LExit:
541598 ReleaseStr (sczDependent);
542599 ReleaseStr (sczFeatureBandVersion);
600+ ReleaseStr (sczPlatform);
543601 LogUninitialize (TRUE );
544602 RegUninitialize ();
545603 WiuUninitialize ();
0 commit comments