@@ -27,14 +27,30 @@ public class InstallWorkloadFromArtifacts : Task
27
27
[ Required , NotNull ]
28
28
public string ? LocalNuGetsPath { get ; set ; }
29
29
30
+ [ Required , NotNull ]
31
+ public string ? TemplateNuGetConfigPath { get ; set ; }
32
+
30
33
[ Required , NotNull ]
31
34
public string ? SdkDir { get ; set ; }
32
35
33
36
public bool OnlyUpdateManifests { get ; set ; }
34
37
35
- public ITaskItem [ ] ExtraNuGetSources { get ; set ; } = Array . Empty < ITaskItem > ( ) ;
38
+ private const string s_nugetInsertionTag = "<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->" ;
36
39
37
40
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 ( )
38
54
{
39
55
if ( ! HasMetadata ( WorkloadId , nameof ( WorkloadId ) , "Version" ) ||
40
56
! HasMetadata ( WorkloadId , nameof ( WorkloadId ) , "ManifestName" ) )
@@ -48,6 +64,12 @@ public override bool Execute()
48
64
return false ;
49
65
}
50
66
67
+ if ( ! File . Exists ( TemplateNuGetConfigPath ) )
68
+ {
69
+ Log . LogError ( $ "Cannot find TemplateNuGetConfigPath={ TemplateNuGetConfigPath } ") ;
70
+ return false ;
71
+ }
72
+
51
73
Log . LogMessage ( MessageImportance . High , $ "{ Environment . NewLine } ** Installing workload manifest { WorkloadId . ItemSpec } **{ Environment . NewLine } ") ;
52
74
53
75
string nugetConfigContents = GetNuGetConfig ( ) ;
@@ -86,25 +108,11 @@ public override bool Execute()
86
108
87
109
private string GetNuGetConfig ( )
88
110
{
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 } ") ;
105
114
106
- nugetConfigBuilder . AppendLine ( $ "</packageSources>{ Environment . NewLine } </configuration>") ;
107
- return nugetConfigBuilder . ToString ( ) ;
115
+ return contents . Replace ( s_nugetInsertionTag , $@ "<add key=""nuget-local"" value=""{ LocalNuGetsPath } "" />") ;
108
116
}
109
117
110
118
private bool InstallWorkloadManifest ( string name , string version , string nugetConfigContents , bool stopOnMissing )
0 commit comments