Skip to content

Commit 8cd699f

Browse files
committed
Don't assume missing workload packs can always be satisfied
When getting a suggestion for workloads to satisfy missing packs, first determine which cannot be installed on the current machine, and report them with a specific error code NETSDK1177.
1 parent 9d2b9a3 commit 8cd699f

File tree

20 files changed

+178
-31
lines changed

20 files changed

+178
-31
lines changed

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/IWorkloadResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IWorkloadResolver
99
{
1010
IEnumerable<WorkloadResolver.PackInfo> GetInstalledWorkloadPacksOfKind(WorkloadPackKind kind);
1111
IEnumerable<WorkloadPackId> GetPacksInWorkload(WorkloadId workloadId);
12-
ISet<WorkloadResolver.WorkloadInfo> GetWorkloadSuggestionForMissingPacks(IList<WorkloadPackId> packId);
12+
ISet<WorkloadResolver.WorkloadInfo>? GetWorkloadSuggestionForMissingPacks(IList<WorkloadPackId> packId, out ISet<WorkloadPackId> unsatisfiablePacks);
1313
IEnumerable<WorkloadResolver.WorkloadInfo> GetAvailableWorkloads();
1414
bool IsWorkloadPlatformCompatible(WorkloadId workloadId);
1515
string GetManifestVersion(string manifestId);

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadResolver.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,17 +451,37 @@ public IEnumerable<WorkloadPackId> GetPacksInWorkload(WorkloadId workloadId)
451451
/// <remarks>
452452
/// Used by the MSBuild workload resolver to emit actionable errors
453453
/// </remarks>
454-
public ISet<WorkloadInfo> GetWorkloadSuggestionForMissingPacks(IList<WorkloadPackId> packIds)
454+
public ISet<WorkloadInfo>? GetWorkloadSuggestionForMissingPacks(IList<WorkloadPackId> packIds, out ISet<WorkloadPackId> unsatisfiablePacks)
455455
{
456456
var requestedPacks = new HashSet<WorkloadPackId>(packIds);
457457
var availableWorkloads = GetAvailableWorkloadDefinitions();
458-
var expandedWorkloads = availableWorkloads.Select(w => (w.workload.Id, new HashSet<WorkloadPackId>(GetPacksInWorkload(w.workload, w.manifest).Select(p => p.packId))));
458+
459+
List<(WorkloadId Id, HashSet<WorkloadPackId> Packs)>? expandedWorkloads = availableWorkloads
460+
.Select(w => (w.workload.Id, new HashSet<WorkloadPackId>(GetPacksInWorkload(w.workload, w.manifest).Select(p => p.packId))))
461+
.ToList();
462+
463+
var unsatisfiable = requestedPacks
464+
.Where(p => !expandedWorkloads.Any(w => w.Packs.Contains(p)))
465+
.ToHashSet();
466+
467+
unsatisfiablePacks = unsatisfiable;
468+
469+
requestedPacks.ExceptWith(unsatisfiable);
470+
if (requestedPacks.Count == 0)
471+
{
472+
return null;
473+
}
474+
475+
expandedWorkloads = expandedWorkloads
476+
.Where(w => w.Packs.Any(p => requestedPacks.Contains(p)))
477+
.ToList();
478+
459479
var finder = new WorkloadSuggestionFinder(GetInstalledPacks(), requestedPacks, expandedWorkloads);
460480

461-
return new HashSet<WorkloadInfo>
462-
(
463-
finder.GetBestSuggestion().Workloads.Select(s => new WorkloadInfo(s, _workloads[s].workload.Description))
464-
);
481+
return finder.GetBestSuggestion()
482+
.Workloads
483+
.Select(s => new WorkloadInfo(s, _workloads[s].workload.Description))
484+
.ToHashSet();
465485
}
466486

467487
/// <summary>

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadSuggestionFinder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public WorkloadSuggestionFinder(HashSet<WorkloadPackId> installedPacks, HashSet<
3030
return new WorkloadSuggestion(c.Workloads, extraPacks);
3131
})
3232
.ToList();
33+
34+
if (UnsortedSuggestions.Count == 0)
35+
{
36+
throw new ArgumentException("requestedPacks may only contain packs that exist in expandedWorkloads", "requestedPacks");
37+
}
3338
}
3439

3540
/// <summary>

src/Tasks/Common/Resources/Strings.resx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,9 @@ To install these workloads, run the following command: {1}</value>
811811
<value>NETSDK1176: Placeholder</value>
812812
<comment>{StrBegin="NETSDK1176: "} - This string is not used here, but is a placeholder for the error code, which is used by the "dotnet run" command.</comment>
813813
</data>
814-
</root>
814+
<data name="WorkloadNotAvailable" xml:space="preserve">
815+
<value>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
816+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</value>
817+
<comment>{StrBegin="NETSDK1177: "}</comment>
818+
</data>
819+
</root>

src/Tasks/Common/Resources/xlf/Strings.cs.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="needs-review-translation">NETSDK1149: Závislý modul byl zkompilován novější verzí Microsoft.Windows.SDK.NET.dll. Pro odkazování na tento modul prosím přejděte na novější verzi .NET SDK.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.de.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.es.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.fr.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.it.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.ja.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.ko.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.pl.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.ru.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.tr.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,13 @@ The following are names of parameters or literal values and should not be transl
880880
<target state="new">NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly.</target>
881881
<note>{StrBegin="NETSDK1148: "}</note>
882882
</trans-unit>
883+
<trans-unit id="WorkloadNotAvailable">
884+
<source>NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
885+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</source>
886+
<target state="new">NETSDK1177: The project depends on the following workload packs that do not exist in any of the workloads available in this installation: {0}
887+
You may need to build the project on another operating system or architecture, or update the .NET SDK.</target>
888+
<note>{StrBegin="NETSDK1177: "}</note>
889+
</trans-unit>
883890
<trans-unit id="WorkloadNotInstalled">
884891
<source>NETSDK1147: To build this project, the following workloads must be installed: {0}
885892
To install these workloads, run the following command: {1}</source>

0 commit comments

Comments
 (0)