From 4f862db3e3454b22df3376fcb8e595dab7e0334a Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 19 Mar 2021 09:01:04 -0700 Subject: [PATCH] Workaround O# path bug Workaround for https://github.com/dotnet/aspnetcore/issues/30750 --- .../dotnet-watch/HotReload/CompilationHandler.cs | 4 ++-- src/RazorSdk/Razor.slnf | 15 +++++++++++++++ ...crosoft.NET.Sdk.Razor.SourceGenerators.targets | 11 +++++++++++ .../BuildIntegrationTest.cs | 9 ++++++--- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/RazorSdk/Razor.slnf diff --git a/src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs b/src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs index 0416098c8054..31c75e358342 100644 --- a/src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs +++ b/src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs @@ -84,13 +84,13 @@ public async ValueTask TryHandleFileChange(DotNetWatchContext context, Fil Solution? updatedSolution = null; ProjectId updatedProjectId; - if (_currentSolution.Projects.SelectMany(p => p.Documents).FirstOrDefault(d => d.FilePath == file.FilePath) is Document documentToUpdate) + if (_currentSolution.Projects.SelectMany(p => p.Documents).FirstOrDefault(d => string.Equals(d.FilePath, file.FilePath, StringComparison.OrdinalIgnoreCase)) is Document documentToUpdate) { var sourceText = await GetSourceTextAsync(file.FilePath); updatedSolution = documentToUpdate.WithText(sourceText).Project.Solution; updatedProjectId = documentToUpdate.Project.Id; } - else if (_currentSolution.Projects.SelectMany(p => p.AdditionalDocuments).FirstOrDefault(d => d.FilePath == file.FilePath) is AdditionalDocument additionalDocument) + else if (_currentSolution.Projects.SelectMany(p => p.AdditionalDocuments).FirstOrDefault(d => string.Equals(d.FilePath, file.FilePath, StringComparison.OrdinalIgnoreCase)) is AdditionalDocument additionalDocument) { var sourceText = await GetSourceTextAsync(file.FilePath); updatedSolution = _currentSolution.WithAdditionalDocumentText(additionalDocument.Id, sourceText, PreservationMode.PreserveValue); diff --git a/src/RazorSdk/Razor.slnf b/src/RazorSdk/Razor.slnf new file mode 100644 index 000000000000..0cfea7b0c655 --- /dev/null +++ b/src/RazorSdk/Razor.slnf @@ -0,0 +1,15 @@ +{ + "solution": { + "path": "..\\..\\sdk.sln", + "projects": [ + "src\\BuiltInTools\\AspNetCoreDeltaApplier\\Microsoft.Extensions.AspNetCoreDeltaApplier.csproj", + "src\\RazorSdk\\SourceGenerators\\Microsoft.NET.Sdk.Razor.SourceGenerators.csproj", + "src\\RazorSdk\\Tasks\\Microsoft.NET.Sdk.Razor.Tasks.csproj", + "src\\RazorSdk\\Tool\\Microsoft.NET.Sdk.Razor.Tool.csproj", + "src\\Resolvers\\Microsoft.DotNet.NativeWrapper\\Microsoft.DotNet.NativeWrapper.csproj", + "src\\Tests\\Microsoft.NET.Sdk.Razor.Tests\\Microsoft.NET.Sdk.Razor.Tests.csproj", + "src\\Tests\\Microsoft.NET.Sdk.Razor.Tool.Tests\\Microsoft.NET.Sdk.Razor.Tool.Tests.csproj", + "src\\Tests\\Microsoft.NET.TestFramework\\Microsoft.NET.TestFramework.csproj" + ] + } +} \ No newline at end of file diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets index 12443751c06c..eb335583037a 100644 --- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets @@ -51,6 +51,17 @@ Copyright (c) .NET Foundation. All rights reserved. <_RazorAdditionalFile Include="@(RazorComponentWithTargetPath)" /> <_RazorAdditionalFile Include="@(RazorGenerateWithTargetPath)" Condition="'$(RazorCompileOnBuild)' != 'false'" /> + + + <_RazorOmnisharpWorkAround Include="$([System.String]::Copy('%(_RazorAdditionalFile.RootDir)').ToLower())%(Directory)%(FileName)%(Extension)" + TargetPath="%(_RazorAdditionalFile.TargetPath)" + GeneratedOutputFullPath="%(_RazorAdditionalFile.GeneratedOutputFullPath)" + CssScope="%(_RazorAdditionalFile.CssScope)" + Condition="$([MSBuild]::IsOSPlatform(`Windows`))" /> + + <_RazorAdditionalFile Remove="@(_RazorAdditionalFile)" Condition="$([MSBuild]::IsOSPlatform(`Windows`))" /> + <_RazorAdditionalFile Include="@(_RazorOmnisharpWorkAround)" Condition="$([MSBuild]::IsOSPlatform(`Windows`))" /> + diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs index 317868980000..b31eed5532f9 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs @@ -74,15 +74,18 @@ public void Build_ErrorInGeneratedCode_ReportsMSBuildError() var projectDirectory = CreateAspNetSdkTestAsset(testAsset); var filePath = Path.Combine(projectDirectory.Path, "Views", "Home", "Index.cshtml"); + File.WriteAllText(filePath, "@{ var foo = \"\".Substring(\"bleh\"); }"); var location = filePath + "(1,27)"; var build = new BuildCommand(projectDirectory); - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Absolute paths on OSX don't work well. build.Execute().Should().Fail().And.HaveStdOutContaining("CS1503"); - } else { + } + else + { build.Execute().Should().Fail().And.HaveStdOutContaining("CS1503").And.HaveStdOutContaining(location); } @@ -185,7 +188,7 @@ public void Build_DoesNotAddRelatedAssemblyPart_IfViewCompilationIsDisabled() { var testAsset = "RazorSimpleMvc"; var projectDirectory = CreateAspNetSdkTestAsset(testAsset); - + var build = new BuildCommand(projectDirectory); build.Execute("/p:RazorCompileOnBuild=false", "/p:RazorCompileOnPublish=false").Should().Pass();