Skip to content

Commit 3076586

Browse files
authored
InstallWorkload: Use the repo's nuget.config as the base for installing manifests (#60699)
1 parent 603aedf commit 3076586

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

eng/testing/workloads-testing.targets

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@
8989
WorkingDirectory="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App" />
9090

9191
<ItemGroup>
92-
<_NuGetSourceForWorkloads Include="dotnet6" Value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
93-
<_NuGetSourceForWorkloads Include="dotnet7" Value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
94-
9592
<_BuiltNuGets Include="$(LibrariesShippingPackagesDir)\*.nupkg" />
9693
</ItemGroup>
9794

@@ -111,7 +108,7 @@
111108
WorkloadId="@(WorkloadIdForTesting)"
112109
VersionBand="$(SdkBandVersion)"
113110
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
114-
ExtraNuGetSources="@(_NuGetSourceForWorkloads)"
111+
TemplateNuGetConfigPath="$(RepoRoot)NuGet.config"
115112
SdkDir="$(SdkWithWorkloadForTestingPath)" />
116113
<WriteLinesToFile File="$(SdkWithWorkload_WorkloadStampPath)" Lines="" Overwrite="true" />
117114
</Target>
@@ -124,7 +121,7 @@
124121
WorkloadId="@(WorkloadIdForTesting)"
125122
VersionBand="$(SdkBandVersion)"
126123
LocalNuGetsPath="$(LibrariesShippingPackagesDir)"
127-
ExtraNuGetSources="@(_NuGetSourceForWorkloads)"
124+
TemplateNuGetConfigPath="$(RepoRoot)NuGet.config"
128125
SdkDir="$(SdkWithNoWorkloadForTestingPath)"
129126
OnlyUpdateManifests="true"/>
130127

src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,30 @@ public class InstallWorkloadFromArtifacts : Task
2727
[Required, NotNull]
2828
public string? LocalNuGetsPath { get; set; }
2929

30+
[Required, NotNull]
31+
public string? TemplateNuGetConfigPath { get; set; }
32+
3033
[Required, NotNull]
3134
public string? SdkDir { get; set; }
3235

3336
public bool OnlyUpdateManifests{ get; set; }
3437

35-
public ITaskItem[] ExtraNuGetSources { get; set; } = Array.Empty<ITaskItem>();
38+
private const string s_nugetInsertionTag = "<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->";
3639

3740
public override bool Execute()
41+
{
42+
try
43+
{
44+
return ExecuteInternal();
45+
}
46+
catch (LogAsErrorException laee)
47+
{
48+
Log.LogError(laee.Message);
49+
return false;
50+
}
51+
}
52+
53+
private bool ExecuteInternal()
3854
{
3955
if (!HasMetadata(WorkloadId, nameof(WorkloadId), "Version") ||
4056
!HasMetadata(WorkloadId, nameof(WorkloadId), "ManifestName"))
@@ -48,6 +64,12 @@ public override bool Execute()
4864
return false;
4965
}
5066

67+
if (!File.Exists(TemplateNuGetConfigPath))
68+
{
69+
Log.LogError($"Cannot find TemplateNuGetConfigPath={TemplateNuGetConfigPath}");
70+
return false;
71+
}
72+
5173
Log.LogMessage(MessageImportance.High, $"{Environment.NewLine}** Installing workload manifest {WorkloadId.ItemSpec} **{Environment.NewLine}");
5274

5375
string nugetConfigContents = GetNuGetConfig();
@@ -86,25 +108,11 @@ public override bool Execute()
86108

87109
private string GetNuGetConfig()
88110
{
89-
StringBuilder nugetConfigBuilder = new();
90-
nugetConfigBuilder.AppendLine($"<configuration>{Environment.NewLine}<packageSources>");
91-
92-
nugetConfigBuilder.AppendLine($@"<add key=""nuget-local"" value=""{LocalNuGetsPath}"" />");
93-
foreach (ITaskItem source in ExtraNuGetSources)
94-
{
95-
string key = source.ItemSpec;
96-
string value = source.GetMetadata("Value");
97-
if (string.IsNullOrEmpty(value))
98-
{
99-
Log.LogWarning($"ExtraNuGetSource {key} is missing Value metadata");
100-
continue;
101-
}
102-
103-
nugetConfigBuilder.AppendLine($@"<add key=""{key}"" value=""{value}"" />");
104-
}
111+
string contents = File.ReadAllText(TemplateNuGetConfigPath);
112+
if (contents.IndexOf(s_nugetInsertionTag) < 0)
113+
throw new LogAsErrorException($"Could not find {s_nugetInsertionTag} in {TemplateNuGetConfigPath}");
105114

106-
nugetConfigBuilder.AppendLine($"</packageSources>{Environment.NewLine}</configuration>");
107-
return nugetConfigBuilder.ToString();
115+
return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{LocalNuGetsPath}"" />");
108116
}
109117

110118
private bool InstallWorkloadManifest(string name, string version, string nugetConfigContents, bool stopOnMissing)

src/tasks/WorkloadBuildTasks/WorkloadBuildTasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<Compile Include="..\Common\Utils.cs" />
10+
<Compile Include="..\Common\LogAsErrorException.cs" />
1011

1112
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
1213
</ItemGroup>

0 commit comments

Comments
 (0)