From 1aace2b6c799108ee4b99e7a714b210e01732be5 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Wed, 28 Nov 2018 12:32:14 -0800 Subject: [PATCH] Fix DevDiv 736427 When a user builds a 2.1 or 2.2 project with a 3.0 they can get an error due to invalid command line options from rzc. What happens is that the 3.0 tasks (which are a singleton) are talking to the 2.X build tool (which is NOT a singleton). Recently some changes were make to the 3.0 tasks which caused this bug because it did not properly accomodate downlevel versions of rzc. We have an integration test for this scenario for but the regression was not detected, so obviously something is wrong with the test setup. I'll investigate that separately. --- .../Microsoft.NET.Sdk.Razor/RazorGenerate.cs | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Razor/src/Microsoft.NET.Sdk.Razor/RazorGenerate.cs b/src/Razor/src/Microsoft.NET.Sdk.Razor/RazorGenerate.cs index 61246c8484..07892cfa38 100644 --- a/src/Razor/src/Microsoft.NET.Sdk.Razor/RazorGenerate.cs +++ b/src/Razor/src/Microsoft.NET.Sdk.Razor/RazorGenerate.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Razor.Tasks public ITaskItem[] Configuration { get; set; } [Required] - public ITaskItem[] Extensions { get; set; } + public ITaskItem[] Extensions { get; set; } [Required] public ITaskItem[] Sources { get; set; } @@ -90,6 +90,14 @@ namespace Microsoft.AspNetCore.Razor.Tasks builder.AppendLine(Command); + // We might be talking to a downlevel version of the command line tool, which doesn't + // understand certain parameters. Assume 2.1 if we can't parse the version because 2.1 + // 2.2 are the releases that have command line tool delivered by a package. + if (!System.Version.TryParse(Version, out var parsedVersion)) + { + parsedVersion = new System.Version(2, 1); + } + for (var i = 0; i < Sources.Length; i++) { var input = Sources[i]; @@ -103,11 +111,15 @@ namespace Microsoft.AspNetCore.Razor.Tasks var outputPath = Path.Combine(ProjectRoot, input.GetMetadata(GeneratedOutput)); builder.AppendLine(outputPath); - var kind = input.GetMetadata(DocumentKind); - if (!string.IsNullOrEmpty(kind)) + // Added in 3.0 + if (parsedVersion.Major >= 3) { - builder.AppendLine("-k"); - builder.AppendLine(kind); + var kind = input.GetMetadata(DocumentKind); + if (!string.IsNullOrEmpty(kind)) + { + builder.AppendLine("-k"); + builder.AppendLine(kind); + } } } @@ -123,7 +135,8 @@ namespace Microsoft.AspNetCore.Razor.Tasks builder.AppendLine("-c"); builder.AppendLine(Configuration[0].GetMetadata(Identity)); - if (GenerateDeclaration) + // Added in 3.0 + if (parsedVersion.Major >= 3 && GenerateDeclaration) { builder.AppendLine("--generate-declaration"); } @@ -152,4 +165,4 @@ namespace Microsoft.AspNetCore.Razor.Tasks return true; } } -} +} \ No newline at end of file