Skip to content

Commit 26066f7

Browse files
[CodeGenerator] Fix MLNet.CLI build error. (#5546)
* upgrade to 3.1 * write inline data using invariantCulture * fix mlnet build error
1 parent 02b1fa6 commit 26066f7

10 files changed

+17
-16
lines changed

src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public class ConsumeModel
4141
{
4242
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
4343
44-
public static string MLNetModelPath = Path.GetFullPath(""");
44+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, """);
4545
this.Write(this.ToStringHelper.ToStringWithCulture(MLNetModelName));
4646
this.Write("\");\r\n");
4747
if(IsAzureImage || IsAzureObjectDetection){
48-
this.Write(" \r\n public static string OnnxModelPath = Path.GetFullPath(\"");
48+
this.Write(" \r\n public static string OnnxModelPath = Path.Combine(System.AppContext.Ba" +
49+
"seDirectory, \"");
4950
this.Write(this.ToStringHelper.ToStringWithCulture(OnnxModelName));
5051
this.Write("\");\r\n");
5152
}

src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace <#= Namespace #>.Model
2323
{
2424
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
2525

26-
public static string MLNetModelPath = Path.GetFullPath("<#= MLNetModelName #>");
26+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "<#= MLNetModelName #>");
2727
<#if(IsAzureImage || IsAzureObjectDetection){ #>
28-
public static string OnnxModelPath = Path.GetFullPath("<#= OnnxModelName #>");
28+
public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "<#= OnnxModelName #>");
2929
<#} #>
3030

3131
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Test.Model
1414
{
1515
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
1616

17-
public static string MLNetModelPath = Path.GetFullPath("\path\to\model");
17+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "\path\to\model");
1818

1919
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2020
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace CodeGenTest.Model
1414
{
1515
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
1616

17-
public static string MLNetModelPath = Path.GetFullPath("/path/to/model");
17+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/model");
1818

19-
public static string OnnxModelPath = Path.GetFullPath("/path/to/onnxModel");
19+
public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/onnxModel");
2020

2121
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2222
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace CodeGenTest.Model
1414
{
1515
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
1616

17-
public static string MLNetModelPath = Path.GetFullPath("/path/to/model");
17+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/model");
1818

19-
public static string OnnxModelPath = Path.GetFullPath("/path/to/onnxModel");
19+
public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/onnxModel");
2020

2121
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2222
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace TestNamespace.Model
1818
{
1919
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
2020

21-
public static string MLNetModelPath = Path.GetFullPath("x:\models\model.zip");
21+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "x:\models\model.zip");
2222

2323
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2424
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace TestNamespace.Model
1818
{
1919
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
2020

21-
public static string MLNetModelPath = Path.GetFullPath("x:\models\model.zip");
21+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "x:\models\model.zip");
2222

2323
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2424
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace Namespace.Model
1414
{
1515
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
1616

17-
public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip");
17+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip");
1818

19-
public static string OnnxModelPath = Path.GetFullPath("onnx.onnx");
19+
public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "onnx.onnx");
2020

2121
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2222
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace Namespace.Model
1414
{
1515
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
1616

17-
public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip");
17+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip");
1818

19-
public static string OnnxModelPath = Path.GetFullPath("onnx.onnx");
19+
public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "onnx.onnx");
2020

2121
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2222
// Method for consuming model in your app

test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Namespace.Model
1414
{
1515
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
1616

17-
public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip");
17+
public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip");
1818

1919
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
2020
// Method for consuming model in your app

0 commit comments

Comments
 (0)