Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround O# path bug #16434

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public async ValueTask<bool> 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);
Expand Down
15 changes: 15 additions & 0 deletions src/RazorSdk/Razor.slnf
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ Copyright (c) .NET Foundation. All rights reserved.
<_RazorAdditionalFile Include="@(RazorComponentWithTargetPath)" />
<!-- Ignore .cshtml files if RazorCompileOnBuild=false -->
<_RazorAdditionalFile Include="@(RazorGenerateWithTargetPath)" Condition="'$(RazorCompileOnBuild)' != 'false'" />

<!-- Workaround for O# bug where it modifies the root path on Windows-->
<_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`))" />

<AdditionalFiles Include="@(_RazorAdditionalFile)" />

<!-- pre-emptively include the files generated by source-generators -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ public void Build_ErrorInGeneratedCode_ReportsMSBuildError()
var projectDirectory = CreateAspNetSdkTestAsset(testAsset);

var filePath = Path.Combine(projectDirectory.Path, "Views", "Home", "Index.cshtml");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just make this a relative path and check for the existence of that instead of having the conditional check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping we would undo this PR after we get o# to fix their bug. But using a relative path seems like a good long term fix


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);
}

Expand Down Expand Up @@ -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();

Expand Down