@@ -100,22 +100,25 @@ private static void RunCodeGen(Options options, (TextLoader.Arguments, IEnumerab
100
100
var trainerAndUsings = codeGenerator . GenerateTrainerAndUsings ( ) ;
101
101
var transformsAndUsings = codeGenerator . GenerateTransformsAndUsings ( ) ;
102
102
103
+ //Capture all the usings
104
+ var usings = new List < string > ( ) ;
105
+
103
106
//Get trainer code and its associated usings.
104
107
var trainer = trainerAndUsings . Item1 ;
105
- var trainerUsings = trainerAndUsings . Item2 ;
108
+ usings . Add ( trainerAndUsings . Item2 ) ;
106
109
107
- //Get transforms code and its associated usings.
110
+ //Get transforms code and its associated (unique) usings.
108
111
var transforms = transformsAndUsings . Select ( t => t . Item1 ) . ToList ( ) ;
109
- var transformUsings = transformsAndUsings . Select ( t => t . Item2 ) . ToList ( ) ;
112
+ usings . AddRange ( transformsAndUsings . Select ( t => t . Item2 ) ) ;
113
+ usings = usings . Distinct ( ) . ToList ( ) ;
110
114
111
- //Combine all using statements.
112
- StringBuilder usings = new StringBuilder ( ) ;
113
- transformUsings . ForEach ( t =>
115
+ //Combine all using statements to actual text .
116
+ StringBuilder usingsBuilder = new StringBuilder ( ) ;
117
+ usings . ForEach ( t =>
114
118
{
115
119
if ( t != null )
116
- usings . Append ( t ) ;
120
+ usingsBuilder . Append ( t ) ;
117
121
} ) ;
118
- usings . Append ( trainerUsings ) ;
119
122
120
123
//Generate code for columns
121
124
var columns = codeGenerator . GenerateColumns ( ) ;
@@ -137,7 +140,7 @@ private static void RunCodeGen(Options options, (TextLoader.Arguments, IEnumerab
137
140
Trainer = trainer ,
138
141
TaskType = options . MlTask . ToString ( ) ,
139
142
ClassLabels = classLabels ,
140
- GeneratedUsings = usings . ToString ( )
143
+ GeneratedUsings = usingsBuilder . ToString ( )
141
144
} ;
142
145
143
146
MLProjectGen csProjGenerator = new MLProjectGen ( ) ;
0 commit comments