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 + +