diff --git a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs index 6ba08042c9..e71626d937 100644 --- a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs +++ b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs @@ -41,11 +41,12 @@ public class ConsumeModel { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("""); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, """); this.Write(this.ToStringHelper.ToStringWithCulture(MLNetModelName)); this.Write("\");\r\n"); if(IsAzureImage || IsAzureObjectDetection){ - this.Write(" \r\n public static string OnnxModelPath = Path.GetFullPath(\""); + this.Write(" \r\n public static string OnnxModelPath = Path.Combine(System.AppContext.Ba" + + "seDirectory, \""); this.Write(this.ToStringHelper.ToStringWithCulture(OnnxModelName)); this.Write("\");\r\n"); } diff --git a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt index 8c3d11568d..7735b15ee9 100644 --- a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt +++ b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt @@ -23,9 +23,9 @@ namespace <#= Namespace #>.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("<#= MLNetModelName #>"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "<#= MLNetModelName #>"); <#if(IsAzureImage || IsAzureObjectDetection){ #> - public static string OnnxModelPath = Path.GetFullPath("<#= OnnxModelName #>"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "<#= OnnxModelName #>"); <#} #> // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt index 0706528fe5..27940abbc5 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt @@ -14,7 +14,7 @@ namespace Test.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("\path\to\model"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "\path\to\model"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt index 102d17059d..95db062089 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt @@ -14,9 +14,9 @@ namespace CodeGenTest.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("/path/to/model"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/model"); - public static string OnnxModelPath = Path.GetFullPath("/path/to/onnxModel"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/onnxModel"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt index 102d17059d..95db062089 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt @@ -14,9 +14,9 @@ namespace CodeGenTest.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("/path/to/model"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/model"); - public static string OnnxModelPath = Path.GetFullPath("/path/to/onnxModel"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/onnxModel"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt index fb1e37cb14..4f0b83618b 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt @@ -18,7 +18,7 @@ namespace TestNamespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("x:\models\model.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "x:\models\model.zip"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt index fb1e37cb14..4f0b83618b 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt @@ -18,7 +18,7 @@ namespace TestNamespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("x:\models\model.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "x:\models\model.zip"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt index 102796208a..39829e5c2c 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt @@ -14,9 +14,9 @@ namespace Namespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip"); - public static string OnnxModelPath = Path.GetFullPath("onnx.onnx"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "onnx.onnx"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt index a4c874b77b..68be854510 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt @@ -14,9 +14,9 @@ namespace Namespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip"); - public static string OnnxModelPath = Path.GetFullPath("onnx.onnx"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "onnx.onnx"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt index b1e4146d53..30fa1b7dfb 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt @@ -14,7 +14,7 @@ namespace Namespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app