Skip to content

Commit 56f6516

Browse files
srsaggamDmitry-A
authored andcommitted
added nuget sources in generated csproj (dotnet#262)
* added nuget sources in csproj * changed the structure in generated code * space
1 parent fcdb09a commit 56f6516

6 files changed

+75
-18
lines changed

src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.GeneratedProjectCodeTest.approved.txt

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<TargetFramework>netcoreapp2.1</TargetFramework>
66
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
77
</PropertyGroup>
8+
<PropertyGroup>
9+
<RestoreSources>
10+
https://api.nuget.org/v3/index.json;
11+
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
12+
</RestoreSources>
13+
</PropertyGroup>
814
<ItemGroup>
915
<Compile Include="Program.cs" />
1016
<Compile Include="ConsoleHelper.cs" />

src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.GeneratedTrainCodeTest.approved.txt

+19-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,28 @@ namespace MyNamespace
2626
// Create MLContext to be shared across the model creation workflow objects
2727
var mlContext = new MLContext();
2828

29-
// (Optional step) Create, Train, Evaluate and Save the model.zip file
30-
TrainEvaluateAndSaveModel(mlContext);
29+
var command = Command.Predict; // Your desired action here
3130

32-
// Make a single test prediction loading the model from model.zip file
33-
Predict(mlContext);
31+
if (command == Command.Predict)
32+
{
33+
Predict(mlContext);
34+
ConsoleHelper.ConsoleWriteHeader("=============== If you also want to train a model use Command.TrainAndPredict ===============");
35+
}
3436

35-
ConsoleHelper.ConsoleWriteHeader("=============== End of process, hit any key to finish ===============");
37+
if (command == Command.TrainAndPredict)
38+
{
39+
TrainEvaluateAndSaveModel(mlContext);
40+
Predict(mlContext);
41+
}
42+
43+
Console.WriteLine("=============== End of process, hit any key to finish ===============");
3644
Console.ReadKey();
45+
}
3746

47+
private enum Command
48+
{
49+
Predict,
50+
TrainAndPredict
3851
}
3952

4053
private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
@@ -77,7 +90,7 @@ namespace MyNamespace
7790
mlContext.Model.Save(trainedModel, fs);
7891

7992
Console.WriteLine("The model is saved to {0}", ModelPath);
80-
ConsoleHelper.ConsoleWriteHeader("=============== End of training process ===============");
93+
Console.WriteLine("=============== End of training process ===============");
8194

8295
return trainedModel;
8396
}

src/mlnet/Templates/Console/MLCodeGen.cs

+19-6
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,28 @@ static void Main(string[] args)
6060
// Create MLContext to be shared across the model creation workflow objects
6161
var mlContext = new MLContext();
6262
63-
// (Optional step) Create, Train, Evaluate and Save the model.zip file
64-
TrainEvaluateAndSaveModel(mlContext);
63+
var command = Command.Predict; // Your desired action here
6564
66-
// Make a single test prediction loading the model from model.zip file
67-
Predict(mlContext);
65+
if (command == Command.Predict)
66+
{
67+
Predict(mlContext);
68+
ConsoleHelper.ConsoleWriteHeader(""=============== If you also want to train a model use Command.TrainAndPredict ==============="");
69+
}
6870
69-
ConsoleHelper.ConsoleWriteHeader(""=============== End of process, hit any key to finish ==============="");
71+
if (command == Command.TrainAndPredict)
72+
{
73+
TrainEvaluateAndSaveModel(mlContext);
74+
Predict(mlContext);
75+
}
76+
77+
Console.WriteLine(""=============== End of process, hit any key to finish ==============="");
7078
Console.ReadKey();
79+
}
7180
81+
private enum Command
82+
{
83+
Predict,
84+
TrainAndPredict
7285
}
7386
7487
private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
@@ -184,7 +197,7 @@ private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
184197
mlContext.Model.Save(trainedModel, fs);
185198
186199
Console.WriteLine(""The model is saved to {0}"", ModelPath);
187-
ConsoleHelper.ConsoleWriteHeader(""=============== End of training process ==============="");
200+
Console.WriteLine(""=============== End of training process ==============="");
188201
189202
return trainedModel;
190203
}

src/mlnet/Templates/Console/MLCodeGen.tt

+19-6
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,28 @@ namespace <#= Namespace #>
3434
// Create MLContext to be shared across the model creation workflow objects
3535
var mlContext = new MLContext();
3636

37-
// (Optional step) Create, Train, Evaluate and Save the model.zip file
38-
TrainEvaluateAndSaveModel(mlContext);
37+
var command = Command.Predict; // Your desired action here
3938

40-
// Make a single test prediction loading the model from model.zip file
41-
Predict(mlContext);
39+
if (command == Command.Predict)
40+
{
41+
Predict(mlContext);
42+
ConsoleHelper.ConsoleWriteHeader("=============== If you also want to train a model use Command.TrainAndPredict ===============");
43+
}
4244

43-
ConsoleHelper.ConsoleWriteHeader("=============== End of process, hit any key to finish ===============");
45+
if (command == Command.TrainAndPredict)
46+
{
47+
TrainEvaluateAndSaveModel(mlContext);
48+
Predict(mlContext);
49+
}
50+
51+
Console.WriteLine("=============== End of process, hit any key to finish ===============");
4452
Console.ReadKey();
53+
}
4554

55+
private enum Command
56+
{
57+
Predict,
58+
TrainAndPredict
4659
}
4760

4861
private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
@@ -123,7 +136,7 @@ if(string.IsNullOrEmpty(TestPath)){ #>
123136
mlContext.Model.Save(trainedModel, fs);
124137

125138
Console.WriteLine("The model is saved to {0}", ModelPath);
126-
ConsoleHelper.ConsoleWriteHeader("=============== End of training process ===============");
139+
Console.WriteLine("=============== End of training process ===============");
127140

128141
return trainedModel;
129142
}

src/mlnet/Templates/Console/MLProjectGen.cs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public virtual string TransformText()
3232
<TargetFramework>netcoreapp2.1</TargetFramework>
3333
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
3434
</PropertyGroup>
35+
<PropertyGroup>
36+
<RestoreSources>
37+
https://api.nuget.org/v3/index.json;
38+
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
39+
</RestoreSources>
40+
</PropertyGroup>
3541
<ItemGroup>
3642
<Compile Include=""Program.cs"" />
3743
<Compile Include=""ConsoleHelper.cs"" />

src/mlnet/Templates/Console/MLProjectGen.tt

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
<TargetFramework>netcoreapp2.1</TargetFramework>
1111
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
1212
</PropertyGroup>
13+
<PropertyGroup>
14+
<RestoreSources>
15+
https://api.nuget.org/v3/index.json;
16+
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
17+
</RestoreSources>
18+
</PropertyGroup>
1319
<ItemGroup>
1420
<Compile Include="Program.cs" />
1521
<Compile Include="ConsoleHelper.cs" />

0 commit comments

Comments
 (0)