@@ -100,22 +100,25 @@ private static void RunCodeGen(Options options, (TextLoader.Arguments, IEnumerab
100100 var trainerAndUsings = codeGenerator . GenerateTrainerAndUsings ( ) ;
101101 var transformsAndUsings = codeGenerator . GenerateTransformsAndUsings ( ) ;
102102
103+ //Capture all the usings
104+ var usings = new List < string > ( ) ;
105+
103106 //Get trainer code and its associated usings.
104107 var trainer = trainerAndUsings . Item1 ;
105- var trainerUsings = trainerAndUsings . Item2 ;
108+ usings . Add ( trainerAndUsings . Item2 ) ;
106109
107- //Get transforms code and its associated usings.
110+ //Get transforms code and its associated (unique) usings.
108111 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 ( ) ;
110114
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 =>
114118 {
115119 if ( t != null )
116- usings . Append ( t ) ;
120+ usingsBuilder . Append ( t ) ;
117121 } ) ;
118- usings . Append ( trainerUsings ) ;
119122
120123 //Generate code for columns
121124 var columns = codeGenerator . GenerateColumns ( ) ;
@@ -137,7 +140,7 @@ private static void RunCodeGen(Options options, (TextLoader.Arguments, IEnumerab
137140 Trainer = trainer ,
138141 TaskType = options . MlTask . ToString ( ) ,
139142 ClassLabels = classLabels ,
140- GeneratedUsings = usings . ToString ( )
143+ GeneratedUsings = usingsBuilder . ToString ( )
141144 } ;
142145
143146 MLProjectGen csProjGenerator = new MLProjectGen ( ) ;
0 commit comments