diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Sdk.Razor.CurrentVersion.props b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Sdk.Razor.CurrentVersion.props index b7d17b206b..b1394c1fbe 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Sdk.Razor.CurrentVersion.props +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Sdk.Razor.CurrentVersion.props @@ -42,6 +42,14 @@ Copyright (c) .NET Foundation. All rights reserved. --> false + + false + - $(CopyRefAssembliesToPublishDirectory) - - false - true + false + true - true + true + + $(CopyRefAssembliesToPublishDirectory) + + + + public class BuildIntegrationTest11 : MSBuildIntegrationTestBase, IClassFixture { public BuildIntegrationTest11(BuildServerTestFixture buildServer) : base(buildServer) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22NetFx.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22NetFx.cs new file mode 100644 index 0000000000..b4b5e993c2 --- /dev/null +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22NetFx.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + public class BuildIntegrationTest22NetFx : BuildIntegrationTestLegacy + { + public BuildIntegrationTest22NetFx(LegacyBuildServerTestFixture buildServer) + : base(buildServer) + { + } + + public override string TestProjectName => "SimpleMvc22NetFx"; + public override string TargetFramework => "net461"; + public override string OutputFileName => $"{TestProjectName}.exe"; + + [Fact] + public override async Task BuildingProject_CopyToOutputDirectoryFiles() + { + using (CreateTestProject()) + { + // Build + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + // No cshtml files should be in the build output directory + Assert.FileCountEquals(result, 0, Path.Combine(OutputPath, "Views"), "*.cshtml"); + + // refs are required for runtime compilation in desktop targeting projects. + Assert.FileCountEquals(result, 97, Path.Combine(OutputPath, "refs"), "*.dll"); + } + } + } +} diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs index 460cd6e117..f3f7e38a6e 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs @@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { public abstract string TestProjectName { get; } public abstract new string TargetFramework { get; } + public virtual string OutputFileName => $"{TestProjectName}.dll"; public BuildIntegrationTestLegacy(LegacyBuildServerTestFixture buildServer) : base(buildServer) @@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests var result = await DotnetMSBuild("Build"); Assert.BuildPassed(result); - Assert.FileExists(result, OutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, OutputPath, OutputFileName); Assert.FileExists(result, OutputPath, $"{TestProjectName}.pdb"); Assert.FileExists(result, OutputPath, $"{TestProjectName}.Views.dll"); Assert.FileExists(result, OutputPath, $"{TestProjectName}.Views.pdb"); @@ -49,6 +50,24 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests result, Path.Combine(IntermediateOutputPath, $"{TestProjectName}.TagHelpers.output.cache"), @"""Name"":""SimpleMvc.SimpleTagHelper"""); + + } + } + + [Fact] + public virtual async Task BuildingProject_CopyToOutputDirectoryFiles() + { + using (CreateTestProject()) + { + // Build + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + // No cshtml files should be in the build output directory + Assert.FileCountEquals(result, 0, Path.Combine(OutputPath, "Views"), "*.cshtml"); + + // For .NET Core projects, no ref assemblies should be present in the output directory. + Assert.FileCountEquals(result, 0, Path.Combine(OutputPath, "refs"), "*.dll"); } } @@ -61,7 +80,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildPassed(result); - Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, PublishOutputPath, OutputFileName); Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.pdb"); Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.Views.dll"); Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.Views.pdb"); @@ -82,7 +101,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildPassed(result); // Everything we do should noop - including building the app. - Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, PublishOutputPath, OutputFileName); Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.pdb"); Assert.FileDoesNotExist(result, PublishOutputPath, $"{TestProjectName}.Views.dll"); Assert.FileDoesNotExist(result, PublishOutputPath, $"{TestProjectName}.Views.pdb"); @@ -98,8 +117,8 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildPassed(result); - Assert.FileExists(result, IntermediateOutputPath, $"{TestProjectName}.dll"); - Assert.FileExists(result, IntermediateOutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, IntermediateOutputPath, OutputFileName); + Assert.FileExists(result, IntermediateOutputPath, OutputFileName); Assert.FileDoesNotExist(result, IntermediateOutputPath, $"{TestProjectName}.Views.dll"); Assert.FileDoesNotExist(result, IntermediateOutputPath, $"{TestProjectName}.Views.pdb"); } @@ -133,6 +152,18 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests } } + [Fact] + public async Task Publish_IncludesRefAssemblies_WhenCopyRefAssembliesToPublishDirectoryIsSet() + { + using (CreateTestProject()) + { + var result = await DotnetMSBuild("Publish", "/p:CopyRefAssembliesToPublishDirectory=true"); + + Assert.BuildPassed(result); + Assert.FileExists(result, PublishOutputPath, "refs", "System.Threading.Tasks.Extensions.dll"); + } + } + private class Disposable : IDisposable { public void Dispose() diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/Models/ErrorViewModel.cs b/src/Razor/test/testassets/SimpleMvc22NetFx/Models/ErrorViewModel.cs new file mode 100644 index 0000000000..b4aa044914 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/Models/ErrorViewModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace SimpleMvc.Models +{ + public class ErrorViewModel + { + public string RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } +} \ No newline at end of file diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/Program.cs b/src/Razor/test/testassets/SimpleMvc22NetFx/Program.cs new file mode 100644 index 0000000000..25883d6b8b --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/Program.cs @@ -0,0 +1,13 @@ + +namespace SimpleMvc +{ + public class Program + { + public static void Main(string[] args) + { + // Just make sure we have a reference to the MVC 2.2 + var t = typeof(Microsoft.AspNetCore.Mvc.IActionResult); + System.Console.WriteLine(t.FullName); + } + } +} diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/SimpleMvc22NetFx.csproj b/src/Razor/test/testassets/SimpleMvc22NetFx/SimpleMvc22NetFx.csproj new file mode 100644 index 0000000000..ab338c85c3 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/SimpleMvc22NetFx.csproj @@ -0,0 +1,28 @@ + + + + + $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + + + + net461 + full + + + + + + + + + + + + + false + + + diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/SimpleTagHelper.cs b/src/Razor/test/testassets/SimpleMvc22NetFx/SimpleTagHelper.cs new file mode 100644 index 0000000000..7cc52922d9 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/SimpleTagHelper.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace SimpleMvc +{ + public class SimpleTagHelper : TagHelper + { + } +} diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/Views/Home/Index.cshtml b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/Home/Index.cshtml new file mode 100644 index 0000000000..00afab6a0c --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/Home/Index.cshtml @@ -0,0 +1,108 @@ +@{ + ViewData["Title"] = "Home Page"; +} + + + + diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/Views/Shared/_Layout.cshtml b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..1a9473e464 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/Shared/_Layout.cshtml @@ -0,0 +1,71 @@ + + + + + + @ViewData["Title"] - SimpleMvc + + + + + + + + + + + + +
+ @RenderBody() +
+
+

© 2017 - SimpleMvc

+
+
+ + + + + + + + + + + + + @RenderSection("Scripts", required: false) + + diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/Views/_ViewImports.cshtml b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/_ViewImports.cshtml new file mode 100644 index 0000000000..477d4ba603 --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using SimpleMvc +@using SimpleMvc.Models +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@namespace SimpleMvc21 diff --git a/src/Razor/test/testassets/SimpleMvc22NetFx/Views/_ViewStart.cshtml b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/_ViewStart.cshtml new file mode 100644 index 0000000000..a5f10045db --- /dev/null +++ b/src/Razor/test/testassets/SimpleMvc22NetFx/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +}