From 57e7f35fab5851b1e5470a113df83891bdfbc414 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 6 Feb 2017 13:02:27 -0800 Subject: [PATCH 1/8] ViewCompilation 1.1.0-msbuild3-final does not work with Microsoft.AspNetCore.Mvc 1.1.1 Fixes #78 --- makefile.shade | 51 +++++++++++++++++++ .../Internal/CompilationOptions.cs | 2 +- .../Internal/DebugHelper.cs | 2 +- .../Internal/MvcServiceProvider.cs | 2 +- .../Internal/PrecompilationApplication.cs | 2 +- .../Internal/PrecompileRunCommand.cs | 2 +- .../Internal/SnkUtils.cs | 2 +- .../Internal/ViewCompilationInfo.cs | 2 +- .../Internal/ViewFileInfo.cs | 2 +- .../ViewInfoContainerCodeGenerator.cs | 2 +- ...spNetCore.Mvc.Razor.ViewCompilation.csproj | 4 +- .../Program.cs | 2 +- .../Properties/AssemblyInfo.cs | 4 ++ ...pNetCore.Mvc.Razor.ViewCompilation.targets | 6 --- ...pNetCore.Mvc.Razor.ViewCompilation.targets | 2 +- .../SimpleAppMvc11Test.Home.Index.txt | 3 ++ .../SimpleAppMvc11Test.cs | 50 ++++++++++++++++++ .../Controllers/HomeController.cs | 9 ++++ testapps/SimpleAppMvc11/Program.cs | 26 ++++++++++ testapps/SimpleAppMvc11/SimpleAppMvc11.csproj | 22 ++++++++ testapps/SimpleAppMvc11/Startup.cs | 20 ++++++++ .../SimpleAppMvc11/Views/Home/Index.cshtml | 1 + .../Views/Shared/_Layout.cshtml | 2 + .../SimpleAppMvc11/Views/_ViewImports.cshtml | 1 + .../SimpleAppMvc11/Views/_ViewStart.cshtml | 3 ++ 25 files changed, 204 insertions(+), 20 deletions(-) create mode 100644 makefile.shade create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppMvc11Test.Home.Index.txt create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/SimpleAppMvc11Test.cs create mode 100644 testapps/SimpleAppMvc11/Controllers/HomeController.cs create mode 100644 testapps/SimpleAppMvc11/Program.cs create mode 100644 testapps/SimpleAppMvc11/SimpleAppMvc11.csproj create mode 100644 testapps/SimpleAppMvc11/Startup.cs create mode 100644 testapps/SimpleAppMvc11/Views/Home/Index.cshtml create mode 100644 testapps/SimpleAppMvc11/Views/Shared/_Layout.cshtml create mode 100644 testapps/SimpleAppMvc11/Views/_ViewImports.cshtml create mode 100644 testapps/SimpleAppMvc11/Views/_ViewStart.cshtml diff --git a/makefile.shade b/makefile.shade new file mode 100644 index 0000000000..f88fd7789d --- /dev/null +++ b/makefile.shade @@ -0,0 +1,51 @@ +use namespace="System.IO" +use namespace="System.IO.Compression" +use namespace="System.Linq" + +use-standard-lifecycle +k-standard-goals + +#repack-x86 target='compile' if='Directory.Exists("src")' + @{ + var buildDir= Path.Combine(Directory.GetCurrentDirectory(), "artifacts", "build"); + var projectName = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation"; + var projectNupkg = Files + .Include(Path.Combine(buildDir, projectName + "*.nupkg")) + .Where(path => !path.EndsWith(".symbols.nupkg", StringComparison.OrdinalIgnoreCase)) + .OrderByDescending(f => f) // On local builds multiple nupkgs are generated. + .First(); + + Log.Info("Repacking Nupkg: " + projectNupkg); + + var extractToDirectory = projectNupkg + "-temp"; + ZipFile.ExtractToDirectory(projectNupkg, extractToDirectory); + + var runtimesDirectory = Path.Combine(extractToDirectory, "runtimes"); + var win7x86Directory = Path.Combine(runtimesDirectory, "win7-x86", "lib", "net451"); + var win7x64Directory = Path.Combine(runtimesDirectory, "win7-x64", "lib", "net451"); + Directory.CreateDirectory(win7x86Directory); + Directory.CreateDirectory(win7x64Directory); + var net451LibDirectory = Path.Combine(extractToDirectory, "lib", "net451"); + + File.Move( + Path.Combine(net451LibDirectory, projectName + ".exe"), + Path.Combine(win7x64Directory, projectName + ".exe")); + File.Move( + Path.Combine(net451LibDirectory, projectName + "-x86.exe"), + Path.Combine(win7x86Directory, projectName + "-x86.exe")); + + File.WriteAllBytes(Path.Combine(net451LibDirectory, "_._"), new byte[0]); + + File.Delete(projectNupkg); + ZipFile.CreateFromDirectory(extractToDirectory, projectNupkg); + + try + { + // Delete temporary directory we used to repack. + Directory.Delete(extractToDirectory, true); + } + catch + { + // Don't care if we couldn't delete the temp directory. + } + } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs index 5e7fc24f43..4adc9b3db7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.CommandLineUtils; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public class CompilationOptions + internal class CompilationOptions { public static readonly string ConfigureCompilationTypeTemplate = "--configure-compilation-type"; public static readonly string ContentRootTemplate = "--content-root"; diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/DebugHelper.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/DebugHelper.cs index 1999e85041..518b4318e6 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/DebugHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/DebugHelper.cs @@ -8,7 +8,7 @@ using System.Linq; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public static class DebugHelper + internal static class DebugHelper { public static void HandleDebugSwitch(ref string[] args) { diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs index fd26c58907..b2b63f2c6a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public class MvcServiceProvider + internal class MvcServiceProvider { private readonly string _projectPath; private readonly string _contentRoot; diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompilationApplication.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompilationApplication.cs index bd1ac8a803..4ba381b7f2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompilationApplication.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompilationApplication.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.CommandLineUtils; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public class PrecompilationApplication : CommandLineApplication + internal class PrecompilationApplication : CommandLineApplication { private readonly Type _callingType; diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs index 8cda93e115..1dcb12f71f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs @@ -19,7 +19,7 @@ using Microsoft.Extensions.CommandLineUtils; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public class PrecompileRunCommand + internal class PrecompileRunCommand { private static readonly ParallelOptions ParalellOptions = new ParallelOptions { diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/SnkUtils.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/SnkUtils.cs index dfe3edb258..6e06878277 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/SnkUtils.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/SnkUtils.cs @@ -8,7 +8,7 @@ using System.IO; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { // Copied from https://github.com/dotnet/cli/blob/rel/1.0.0/src/Microsoft.DotNet.ProjectModel.Workspaces/SnkUtils.cs - public static class SnkUtils + internal static class SnkUtils { const byte PUBLICKEYBLOB = 0x06; const byte PRIVATEKEYBLOB = 0x07; diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs index 8ab014365b..88e808670c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Razor.CodeGenerators; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public class ViewCompilationInfo + internal class ViewCompilationInfo { public ViewCompilationInfo( ViewFileInfo viewFileInfo, diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs index fe8f1196fc..56e0586525 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewFileInfo.cs @@ -5,7 +5,7 @@ using System.IO; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public struct ViewFileInfo + internal struct ViewFileInfo { public ViewFileInfo(string fullPath, string viewEnginePath) { diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs index c00ded2d08..52eee2242f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs @@ -15,7 +15,7 @@ using Microsoft.CodeAnalysis.Text; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - public class ViewInfoContainerCodeGenerator + internal class ViewInfoContainerCodeGenerator { public ViewInfoContainerCodeGenerator( CSharpCompiler compiler, diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj index 3c397e3d1d..fa704733cf 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj @@ -8,13 +8,11 @@ true exe ..\..\pack\ - - build - + diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Program.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Program.cs index 623f661e3f..0b4b532c93 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Program.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Program.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation { - public class Program + internal class Program { private readonly static Type ProgramType = typeof(Program); diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Properties/AssemblyInfo.cs index 0715293428..313e1a2d31 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Properties/AssemblyInfo.cs @@ -1,4 +1,8 @@ // 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.Runtime.CompilerServices; + [assembly: System.Reflection.AssemblyMetadata("Serviceable", "True")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] + diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets index 032406f597..66a5c2b663 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/net451/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets @@ -17,18 +17,12 @@ $(OutputPath)$(MSBuildThisFileName)-x86.exe.config - - $(OutputPath)$(MSBuildThisFileName)-x86.exe - $(OutputPath)$(MSBuildThisFileName).exe.config - - $(OutputPath)$(MSBuildThisFileName).exe - --runtimeconfig "$(ProjectRuntimeConfigFilePath)" $(ExecArgs) --depsfile "$(ProjectDepsFilePath)" - $(ExecArgs) "$(MSBuildThisFileDirectory)$(MSBuildThisFileName).dll" + $(ExecArgs) "$(MSBuildThisFileDirectory)../../lib/netcoreapp1.1/$(MSBuildThisFileName).dll" $(ExecArgs) @"$(_MvcRazorResponseFilePath)" diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppMvc11Test.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppMvc11Test.Home.Index.txt new file mode 100644 index 0000000000..c963a4268b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/SimpleAppMvc11Test.Home.Index.txt @@ -0,0 +1,3 @@ +Hello from Index: AspNetCore._Views_Home_Index_cshtml, SimpleAppMvc11.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + +AspNetCore._Views_Shared__Layout_cshtml, SimpleAppMvc11.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/SimpleAppMvc11Test.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/SimpleAppMvc11Test.cs new file mode 100644 index 0000000000..0af5e7eb8d --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/SimpleAppMvc11Test.cs @@ -0,0 +1,50 @@ +// 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.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation +{ + public class SimpleAppMvc11Test : IClassFixture + { + public SimpleAppMvc11Test(TestFixture fixture) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public async Task Precompilation_WorksWithsAppsTargetingHigherVersionOfMvc(RuntimeFlavor flavor) + { + // Arrange + using (var deployer = Fixture.CreateDeployment(flavor)) + { + var deploymentResult = deployer.Deploy(); + + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + deploymentResult.ApplicationBaseUri, + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("SimpleAppMvc11Test.Home.Index.txt", response); + } + } + + public class TestFixture : ApplicationTestFixture + { + public TestFixture() + : base("SimpleAppMvc11") + { + } + } + } +} diff --git a/testapps/SimpleAppMvc11/Controllers/HomeController.cs b/testapps/SimpleAppMvc11/Controllers/HomeController.cs new file mode 100644 index 0000000000..0b44851019 --- /dev/null +++ b/testapps/SimpleAppMvc11/Controllers/HomeController.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Mvc; + +namespace SimpleApp.Controllers +{ + public class HomeController : Controller + { + public IActionResult Index() => View(); + } +} diff --git a/testapps/SimpleAppMvc11/Program.cs b/testapps/SimpleAppMvc11/Program.cs new file mode 100644 index 0000000000..6ed39c5e32 --- /dev/null +++ b/testapps/SimpleAppMvc11/Program.cs @@ -0,0 +1,26 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace SimpleApp +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/testapps/SimpleAppMvc11/SimpleAppMvc11.csproj b/testapps/SimpleAppMvc11/SimpleAppMvc11.csproj new file mode 100644 index 0000000000..ec241a12a9 --- /dev/null +++ b/testapps/SimpleAppMvc11/SimpleAppMvc11.csproj @@ -0,0 +1,22 @@ + + + netcoreapp1.1;net451 + true + Exe + win7-x64 + true + + + + 1.1.0-* + All + + + + + + + + + + diff --git a/testapps/SimpleAppMvc11/Startup.cs b/testapps/SimpleAppMvc11/Startup.cs new file mode 100644 index 0000000000..75bdc58008 --- /dev/null +++ b/testapps/SimpleAppMvc11/Startup.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace SimpleApp +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(); + app.UseMvcWithDefaultRoute(); + } + } +} diff --git a/testapps/SimpleAppMvc11/Views/Home/Index.cshtml b/testapps/SimpleAppMvc11/Views/Home/Index.cshtml new file mode 100644 index 0000000000..9807947451 --- /dev/null +++ b/testapps/SimpleAppMvc11/Views/Home/Index.cshtml @@ -0,0 +1 @@ +Hello from Index: @GetType().AssemblyQualifiedName diff --git a/testapps/SimpleAppMvc11/Views/Shared/_Layout.cshtml b/testapps/SimpleAppMvc11/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..169bf3fca0 --- /dev/null +++ b/testapps/SimpleAppMvc11/Views/Shared/_Layout.cshtml @@ -0,0 +1,2 @@ +@RenderBody() +@GetType().AssemblyQualifiedName diff --git a/testapps/SimpleAppMvc11/Views/_ViewImports.cshtml b/testapps/SimpleAppMvc11/Views/_ViewImports.cshtml new file mode 100644 index 0000000000..297d1ddb5c --- /dev/null +++ b/testapps/SimpleAppMvc11/Views/_ViewImports.cshtml @@ -0,0 +1 @@ +@using SimpleApp diff --git a/testapps/SimpleAppMvc11/Views/_ViewStart.cshtml b/testapps/SimpleAppMvc11/Views/_ViewStart.cshtml new file mode 100644 index 0000000000..a5f10045db --- /dev/null +++ b/testapps/SimpleAppMvc11/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} From 8dd1b9aa9693c87917c692347777c5af70563036 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 6 Feb 2017 15:47:28 -0800 Subject: [PATCH 2/8] Fix packaging issues --- NuGetPackageVerifier.json | 14 +++++++++++ makefile.shade | 52 +++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index b153ab1515..9835bcd0c8 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -1,4 +1,18 @@ { + "adx": { + "rules": [ + "DefaultCompositeRule" + ], + "packages": { + "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation": { + "exclusions": { + "DOC_MISSING": { + "lib/netcoreapp1.1/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll": "Not a class library. Docs not required for CLI tools" + } + } + } + } + }, "Default": { "rules": [ "DefaultCompositeRule" diff --git a/makefile.shade b/makefile.shade index f88fd7789d..41c8ccdd81 100644 --- a/makefile.shade +++ b/makefile.shade @@ -1,3 +1,6 @@ +use assembly="System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" +use assembly="System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" + use namespace="System.IO" use namespace="System.IO.Compression" use namespace="System.Linq" @@ -17,35 +20,30 @@ k-standard-goals Log.Info("Repacking Nupkg: " + projectNupkg); - var extractToDirectory = projectNupkg + "-temp"; - ZipFile.ExtractToDirectory(projectNupkg, extractToDirectory); + using (var zipArchive = ZipFile.Open(projectNupkg, ZipArchiveMode.Update)) + { + MoveEntry(zipArchive, "lib/net451/" + projectName + ".exe", "runtimes/win7-x64/lib/net451/" + projectName + ".exe"); + MoveEntry(zipArchive, "lib/net451/" + projectName + "-x86.exe", "runtimes/win7-x86/lib/net451/" + projectName + "-x86.exe"); + zipArchive.CreateEntry("lib/net451/_._"); + } + } - var runtimesDirectory = Path.Combine(extractToDirectory, "runtimes"); - var win7x86Directory = Path.Combine(runtimesDirectory, "win7-x86", "lib", "net451"); - var win7x64Directory = Path.Combine(runtimesDirectory, "win7-x64", "lib", "net451"); - Directory.CreateDirectory(win7x86Directory); - Directory.CreateDirectory(win7x64Directory); - var net451LibDirectory = Path.Combine(extractToDirectory, "lib", "net451"); - - File.Move( - Path.Combine(net451LibDirectory, projectName + ".exe"), - Path.Combine(win7x64Directory, projectName + ".exe")); - File.Move( - Path.Combine(net451LibDirectory, projectName + "-x86.exe"), - Path.Combine(win7x86Directory, projectName + "-x86.exe")); - - File.WriteAllBytes(Path.Combine(net451LibDirectory, "_._"), new byte[0]); - - File.Delete(projectNupkg); - ZipFile.CreateFromDirectory(extractToDirectory, projectNupkg); - - try +functions @{ + private static void MoveEntry(ZipArchive archive, string oldPath, string newPath) + { + var oldEntry = archive.GetEntry(oldPath); + if (oldEntry == null) { - // Delete temporary directory we used to repack. - Directory.Delete(extractToDirectory, true); + throw new Exception(oldPath + " was not found in package."); } - catch + + var newEntry = archive.CreateEntry(newPath); + using (var newStream = newEntry.Open()) + using (var oldStream = oldEntry.Open()) { - // Don't care if we couldn't delete the temp directory. + oldStream.CopyTo(newStream); } - } \ No newline at end of file + + oldEntry.Delete(); + } +} \ No newline at end of file From 01366e585520dc7e45fe55054be4422515ffca11 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 6 Feb 2017 15:47:43 -0800 Subject: [PATCH 3/8] Update to Mvc 1.1.1 --- .../Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj | 2 +- .../ApplicationUsingPrecompiledViewClassLibrary.csproj | 2 +- .../ApplicationUsingRelativePaths.csproj | 2 +- .../ApplicationWithConfigureMvc.csproj | 2 +- .../ApplicationWithCustomInputFiles.csproj | 2 +- .../ApplicationWithParseErrors.csproj | 2 +- .../ApplicationWithTagHelpers/ApplicationWithTagHelpers.csproj | 2 +- .../ClassLibraryWithPrecompiledViews.csproj | 2 +- .../PublishWithEmbedViewSources.csproj | 2 +- testapps/SimpleApp/SimpleApp.csproj | 2 +- testapps/SimpleAppDesktopOnly/SimpleAppDesktopOnly.csproj | 2 +- testapps/SimpleAppX86DesktopOnly/SimpleAppX86DesktopOnly.csproj | 2 +- testapps/StrongNamedApp/StrongNamedApp.csproj | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj index fa704733cf..8944e69d6f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj @@ -16,7 +16,7 @@ - + diff --git a/testapps/ApplicationUsingPrecompiledViewClassLibrary/ApplicationUsingPrecompiledViewClassLibrary.csproj b/testapps/ApplicationUsingPrecompiledViewClassLibrary/ApplicationUsingPrecompiledViewClassLibrary.csproj index 76b9bb0338..74b7c0f4c1 100644 --- a/testapps/ApplicationUsingPrecompiledViewClassLibrary/ApplicationUsingPrecompiledViewClassLibrary.csproj +++ b/testapps/ApplicationUsingPrecompiledViewClassLibrary/ApplicationUsingPrecompiledViewClassLibrary.csproj @@ -10,7 +10,7 @@ - + diff --git a/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj b/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj index 00372f0185..a58e936cf6 100644 --- a/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj +++ b/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj @@ -12,7 +12,7 @@ 1.1.0-* All - + diff --git a/testapps/ApplicationWithConfigureMvc/ApplicationWithConfigureMvc.csproj b/testapps/ApplicationWithConfigureMvc/ApplicationWithConfigureMvc.csproj index cf50cd50e2..a5375538d0 100644 --- a/testapps/ApplicationWithConfigureMvc/ApplicationWithConfigureMvc.csproj +++ b/testapps/ApplicationWithConfigureMvc/ApplicationWithConfigureMvc.csproj @@ -13,7 +13,7 @@ 1.1.0-* All - + diff --git a/testapps/ApplicationWithCustomInputFiles/ApplicationWithCustomInputFiles.csproj b/testapps/ApplicationWithCustomInputFiles/ApplicationWithCustomInputFiles.csproj index 5d2763adc9..d6a745da4d 100644 --- a/testapps/ApplicationWithCustomInputFiles/ApplicationWithCustomInputFiles.csproj +++ b/testapps/ApplicationWithCustomInputFiles/ApplicationWithCustomInputFiles.csproj @@ -15,7 +15,7 @@ 1.1.0-* All - + diff --git a/testapps/ApplicationWithParseErrors/ApplicationWithParseErrors.csproj b/testapps/ApplicationWithParseErrors/ApplicationWithParseErrors.csproj index 22347b4ca5..cd1bb59c48 100644 --- a/testapps/ApplicationWithParseErrors/ApplicationWithParseErrors.csproj +++ b/testapps/ApplicationWithParseErrors/ApplicationWithParseErrors.csproj @@ -11,7 +11,7 @@ 1.1.0-* All - + diff --git a/testapps/ApplicationWithTagHelpers/ApplicationWithTagHelpers.csproj b/testapps/ApplicationWithTagHelpers/ApplicationWithTagHelpers.csproj index 831009ac40..db1ffd2dbb 100644 --- a/testapps/ApplicationWithTagHelpers/ApplicationWithTagHelpers.csproj +++ b/testapps/ApplicationWithTagHelpers/ApplicationWithTagHelpers.csproj @@ -14,7 +14,7 @@ - + 1.1.0-* All diff --git a/testapps/ClassLibraryWithPrecompiledViews/ClassLibraryWithPrecompiledViews.csproj b/testapps/ClassLibraryWithPrecompiledViews/ClassLibraryWithPrecompiledViews.csproj index 4ee98030b9..d97f337c9f 100644 --- a/testapps/ClassLibraryWithPrecompiledViews/ClassLibraryWithPrecompiledViews.csproj +++ b/testapps/ClassLibraryWithPrecompiledViews/ClassLibraryWithPrecompiledViews.csproj @@ -17,7 +17,7 @@ - + 1.1.0-* All diff --git a/testapps/PublishWithEmbedViewSources/PublishWithEmbedViewSources.csproj b/testapps/PublishWithEmbedViewSources/PublishWithEmbedViewSources.csproj index d1b8e2c03a..1f53daf0c6 100644 --- a/testapps/PublishWithEmbedViewSources/PublishWithEmbedViewSources.csproj +++ b/testapps/PublishWithEmbedViewSources/PublishWithEmbedViewSources.csproj @@ -10,7 +10,7 @@ - + 1.1.0-* All diff --git a/testapps/SimpleApp/SimpleApp.csproj b/testapps/SimpleApp/SimpleApp.csproj index 365349be1a..ec241a12a9 100644 --- a/testapps/SimpleApp/SimpleApp.csproj +++ b/testapps/SimpleApp/SimpleApp.csproj @@ -11,7 +11,7 @@ 1.1.0-* All - + diff --git a/testapps/SimpleAppDesktopOnly/SimpleAppDesktopOnly.csproj b/testapps/SimpleAppDesktopOnly/SimpleAppDesktopOnly.csproj index ff561a4be7..8cd03479c0 100644 --- a/testapps/SimpleAppDesktopOnly/SimpleAppDesktopOnly.csproj +++ b/testapps/SimpleAppDesktopOnly/SimpleAppDesktopOnly.csproj @@ -9,7 +9,7 @@ - + 1.1.0-* All diff --git a/testapps/SimpleAppX86DesktopOnly/SimpleAppX86DesktopOnly.csproj b/testapps/SimpleAppX86DesktopOnly/SimpleAppX86DesktopOnly.csproj index 56dd3cab85..5e59e57728 100644 --- a/testapps/SimpleAppX86DesktopOnly/SimpleAppX86DesktopOnly.csproj +++ b/testapps/SimpleAppX86DesktopOnly/SimpleAppX86DesktopOnly.csproj @@ -9,7 +9,7 @@ - + 1.1.0-* All diff --git a/testapps/StrongNamedApp/StrongNamedApp.csproj b/testapps/StrongNamedApp/StrongNamedApp.csproj index 0f10baa02e..640fd74a76 100644 --- a/testapps/StrongNamedApp/StrongNamedApp.csproj +++ b/testapps/StrongNamedApp/StrongNamedApp.csproj @@ -12,7 +12,7 @@ - + 1.1.0-* From 64d4b1da0cc65b38791dc196414c216529774302 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 6 Feb 2017 20:38:17 -0800 Subject: [PATCH 4/8] Add an option to disable publishing "refs" assemblies if compilation of views is enabled Fixes #76 --- .../build/common.targets | 9 ++- .../Infrastructure/ApplicationTestFixture.cs | 12 +++- .../ViewCompilationOptionsTest.cs | 65 +++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets index 7df1e2a00a..55d6dbace1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets @@ -8,6 +8,7 @@ $(MSBuildProjectDirectory) true + true @@ -53,7 +54,7 @@ Condition="'$(MvcRazorCompileOnPublish)'=='true'" /> @@ -65,6 +66,12 @@ $([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)')) + + + + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs index d805ddc687..1c7c7adeac 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs @@ -38,6 +38,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation public ILogger Logger { get; private set; } public IApplicationDeployer CreateDeployment(RuntimeFlavor flavor) + { + PrepareForDeployment(flavor); + var deploymentParameters = GetDeploymentParameters(flavor); + return ApplicationDeployerFactory.Create(deploymentParameters, Logger); + } + + public virtual void PrepareForDeployment(RuntimeFlavor flavor) { Logger = CreateLogger(flavor); @@ -46,7 +53,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation Restore(); _isRestored = true; } + } + public virtual DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor) + { var tempRestoreDirectoryEnvironment = new KeyValuePair( NuGetPackagesEnvironmentKey, TempRestoreDirectory); @@ -82,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation }, }; - return ApplicationDeployerFactory.Create(deploymentParameters, Logger); + return deploymentParameters; } protected virtual ILogger CreateLogger(RuntimeFlavor flavor) diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs new file mode 100644 index 0000000000..adafc8785d --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs @@ -0,0 +1,65 @@ +// 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.Collections.Generic; +using System.IO; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation +{ + public class ViewCompilationOptionsTest : IClassFixture + { + public ViewCompilationOptionsTest(TestFixture fixture) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public void Precompilation_PreventsRefAssembliesFromBeingPublished(RuntimeFlavor flavor) + { + // Arrange + using (var deployer = Fixture.CreateDeployment(flavor)) + { + // Act + var deploymentResult = deployer.Deploy(); + + // Assert + Assert.False(Directory.Exists(Path.Combine(deploymentResult.ContentRoot, "refs"))); + } + } + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public void PublishingWithOption_AllowsPublishingRefAssemblies(RuntimeFlavor flavor) + { + // Arrange + Fixture.PrepareForDeployment(flavor); + var deploymentParameters = Fixture.GetDeploymentParameters(flavor); + deploymentParameters.PublishEnvironmentVariables.Add( + new KeyValuePair("MvcRazorExcludeRefAssembliesFromPublish", "false")); + + using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, Fixture.Logger)) + { + // Act + var deploymentResult = deployer.Deploy(); + + // Assert + Assert.True(Directory.Exists(Path.Combine(deploymentResult.ContentRoot, "refs"))); + } + } + + public class TestFixture : ApplicationTestFixture + { + public TestFixture() + : base("SimpleApp") + { + } + } + } +} From fc7d77298084e34b8c70c314541ae1e75ea0a86b Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 8 Feb 2017 14:55:37 -0800 Subject: [PATCH 5/8] Branch for 1.1.0-msbuild4-final --- build.ps1 | 2 +- build/common.props | 1 - version.props | 5 ++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/build.ps1 b/build.ps1 index 2acf6cd799..685a445230 100644 --- a/build.ps1 +++ b/build.ps1 @@ -64,5 +64,5 @@ if (!(Test-Path $buildFolder)) { } } -&".build\dotnet\dotnet-install.ps1" -Channel 'master' -SharedRuntime -Version '1.2.0-beta-001304-00' -Architecture x64 +# &".build\dotnet\dotnet-install.ps1" -Channel 'master' -SharedRuntime -Version '1.2.0-beta-001304-00' -Architecture x64 &"$buildFile" $args \ No newline at end of file diff --git a/build/common.props b/build/common.props index a56db90e38..1615bdda8d 100644 --- a/build/common.props +++ b/build/common.props @@ -1,6 +1,5 @@ - Microsoft ASP.NET Core diff --git a/version.props b/version.props index a1285c53c6..d3c390219f 100644 --- a/version.props +++ b/version.props @@ -1,8 +1,7 @@ - 1.1.0-rtm - $(Version)-$(BuildNumber) - 1.1.0 + 1.1.0-msbuild4-final + $(Version) \ No newline at end of file From ee6e7419f17448ab8d1deaa04fa062176100e715 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 8 Feb 2017 17:29:11 -0800 Subject: [PATCH 6/8] Install the shared runtime --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 685a445230..2acf6cd799 100644 --- a/build.ps1 +++ b/build.ps1 @@ -64,5 +64,5 @@ if (!(Test-Path $buildFolder)) { } } -# &".build\dotnet\dotnet-install.ps1" -Channel 'master' -SharedRuntime -Version '1.2.0-beta-001304-00' -Architecture x64 +&".build\dotnet\dotnet-install.ps1" -Channel 'master' -SharedRuntime -Version '1.2.0-beta-001304-00' -Architecture x64 &"$buildFile" $args \ No newline at end of file From ba91f403dd513b37582895ecea2715bbe2a4d176 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 8 Feb 2017 17:30:50 -0800 Subject: [PATCH 7/8] Don't attempt to repack for x86 on xplat --- makefile.shade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile.shade b/makefile.shade index 41c8ccdd81..41bc61d4f3 100644 --- a/makefile.shade +++ b/makefile.shade @@ -8,7 +8,7 @@ use namespace="System.Linq" use-standard-lifecycle k-standard-goals -#repack-x86 target='compile' if='Directory.Exists("src")' +#repack-x86 target='compile' if='Directory.Exists("src") && !IsLinux' @{ var buildDir= Path.Combine(Directory.GetCurrentDirectory(), "artifacts", "build"); var projectName = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation"; From f833b7a7c89ac0272de25ba5491f0c86ad35b1b7 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 10 Feb 2017 15:40:28 -0800 Subject: [PATCH 8/8] Bump up versions for RTM --- version.props | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/version.props b/version.props index d3c390219f..a1285c53c6 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,8 @@ - 1.1.0-msbuild4-final - $(Version) + 1.1.0-rtm + $(Version)-$(BuildNumber) + 1.1.0 \ No newline at end of file