From 818d4256aaa8d5de8673e82ced5e06f9f9a3c490 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 1 Feb 2018 11:16:57 -0800 Subject: [PATCH] Fix #1999 The fix for this for preview1 is to ignore any files with an absolute path. MvcPrecompilation ignores files outside the project root, and we're aiming for parity. This will have a proper fix in preview2 --- .../Microsoft.AspNetCore.Razor.Design.targets | 12 +++++-- .../MSBuildIntegrationTestBase.cs | 12 +++++++ .../IntegrationTests/ProjectDirectory.cs | 10 ++++-- .../RazorGenerateIntegrationTest.cs | 32 +++++++++++++++++++ .../AppWithP2PReference.csproj | 2 ++ .../testapps/ClassLibrary/ClassLibrary.csproj | 2 ++ test/testapps/SimpleMvc/SimpleMvc.csproj | 2 ++ test/testapps/SimplePages/SimplePages.csproj | 2 ++ 8 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets index 5fcb47a7ce..27a54e7a17 100644 --- a/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets +++ b/src/Microsoft.AspNetCore.Razor.Design/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.targets @@ -167,8 +167,16 @@ - - + + + $(RazorGenerateIntermediateOutputPath)%(RelativeDir)%(Filename).cs diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs index 1bc76c5745..b69109869b 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs @@ -61,6 +61,18 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests msBuildProcessKind); } + internal void AddProjectFileContent(string content) + { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + + var existing = File.ReadAllText(Project.ProjectFilePath); + var updated = existing.Replace("", content); + File.WriteAllText(Project.ProjectFilePath, updated); + } + internal void ReplaceContent(string content, params string[] paths) { if (content == null) diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs index 8b117f9dff..c21f2faa2b 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs @@ -57,7 +57,10 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests CopyGlobalJson(solutionRoot, destinationPath); - return new ProjectDirectory(destinationPath, Path.Combine(destinationPath, projectName)); + return new ProjectDirectory( + destinationPath, + Path.Combine(destinationPath, projectName), + Path.Combine(destinationPath, projectName, projectName + ".csproj")); } catch { @@ -132,14 +135,17 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests } } - private ProjectDirectory(string solutionPath, string directoryPath) + private ProjectDirectory(string solutionPath, string directoryPath, string projectFilePath) { SolutionPath = solutionPath; DirectoryPath = directoryPath; + ProjectFilePath = projectFilePath; } public string DirectoryPath { get; } + public string ProjectFilePath { get;} + public string SolutionPath { get; } public void Dispose() diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/RazorGenerateIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/RazorGenerateIntegrationTest.cs index af4dd592d1..80193b0069 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/RazorGenerateIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/RazorGenerateIntegrationTest.cs @@ -247,5 +247,37 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Home", "About.cs"); Assert.FileCountEquals(result, 1, RazorIntermediateOutputPath, "*.cs"); } + + [Fact] + [InitializeTestProject("SimpleMvc")] + public async Task RazorGenerate_FileWithAbsolutePath_IgnoresFile() + { + // In preview1 we totally ignore files that are specified with an absolute path + var filePath = Path.Combine(Project.SolutionPath, "temp.cshtml"); + File.WriteAllText(filePath, string.Empty); + + AddProjectFileContent($@" + + +"); + + var result = await DotnetMSBuild(RazorGenerateTarget); + + Assert.BuildPassed(result); + + // RazorGenerate should compile the assembly, but not the views. + Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.dll"); + Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.PrecompiledViews.dll"); + + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "_ViewImports.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "_ViewStart.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Home", "About.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Home", "Contact.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Home", "Index.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Shared", "_Layout.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Shared", "_ValidationScriptsPartial.cs"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Shared", "Error.cs"); + Assert.FileCountEquals(result, 8, RazorIntermediateOutputPath, "*.cs"); + } } } diff --git a/test/testapps/AppWithP2PReference/AppWithP2PReference.csproj b/test/testapps/AppWithP2PReference/AppWithP2PReference.csproj index 2ef0434947..82ba010fe7 100644 --- a/test/testapps/AppWithP2PReference/AppWithP2PReference.csproj +++ b/test/testapps/AppWithP2PReference/AppWithP2PReference.csproj @@ -6,6 +6,8 @@ RazorSDK + + diff --git a/test/testapps/ClassLibrary/ClassLibrary.csproj b/test/testapps/ClassLibrary/ClassLibrary.csproj index 7e9ea198c6..18338f29d2 100644 --- a/test/testapps/ClassLibrary/ClassLibrary.csproj +++ b/test/testapps/ClassLibrary/ClassLibrary.csproj @@ -6,6 +6,8 @@ RazorSDK + + diff --git a/test/testapps/SimpleMvc/SimpleMvc.csproj b/test/testapps/SimpleMvc/SimpleMvc.csproj index e553d82b2a..11dac1b1da 100644 --- a/test/testapps/SimpleMvc/SimpleMvc.csproj +++ b/test/testapps/SimpleMvc/SimpleMvc.csproj @@ -6,6 +6,8 @@ RazorSDK + + diff --git a/test/testapps/SimplePages/SimplePages.csproj b/test/testapps/SimplePages/SimplePages.csproj index e553d82b2a..11dac1b1da 100644 --- a/test/testapps/SimplePages/SimplePages.csproj +++ b/test/testapps/SimplePages/SimplePages.csproj @@ -6,6 +6,8 @@ RazorSDK + +