Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Add support for pre-compiling desktop applications. #130

Merged
merged 2 commits into from
May 31, 2017
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
17 changes: 17 additions & 0 deletions NuGetPackageVerifier.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
{
"adx": {
"rules": [
"DefaultCompositeRule"
],
"packages": {
"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation": {
"exclusions": {
"DOC_MISSING": {
"lib/netcoreapp2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll": "Not a class library. Docs not required for CLI tools"
},
"BUILD_ITEMS_FRAMEWORK": {
"*": "Doesn't matter"
Copy link
Contributor

Choose a reason for hiding this comment

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

:thuglife:

}
}
}
}
},
"Default": {
"rules": [
"DefaultCompositeRule"
Expand Down
169 changes: 166 additions & 3 deletions RazorViewCompilation.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build_script:
clone_depth: 1
test: off
deploy: off
os: Visual Studio 2017
12 changes: 10 additions & 2 deletions build/common-testapps.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@
</PropertyGroup>

<Import Project="..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\build\netcoreapp2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets"
Condition="'$(TestIncludeViewCompilationTargets)'=='true'"/>
Condition="'$(TestIncludeViewCompilationTargets)'=='true' AND '$(TargetFramework)'=='netcoreapp2.0'"/>

<Import Project="..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\build\net461\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets"
Condition="'$(TestIncludeViewCompilationTargets)'=='true' AND '$(TargetFramework)'=='net461'"/>

<ItemGroup Condition="'$(TestIncludeViewCompilationTargets)'=='true'">
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
</ItemGroup>

<Target
Name="SetMvcRazorViewCompilationBinaryPath"
BeforeTargets="MvcRazorPrecompile"
Condition="'$(TestIncludeViewCompilationTargets)'=='true'">
<PropertyGroup>
<_MvcViewCompilationBinaryPath>$(MSBuildProjectDirectory)\$(OutputPath)Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll</_MvcViewCompilationBinaryPath>
<_MvcViewCompilationBinaryPath Condition="'$(TargetFramework)'=='netcoreapp2.0'">$(MSBuildProjectDirectory)\$(OutputPath)Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll</_MvcViewCompilationBinaryPath>
<_MvcViewCompilationBinaryPath Condition="'$(TargetFramework)'=='net461'">$(MSBuildProjectDirectory)\$(OutputPath)Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.exe</_MvcViewCompilationBinaryPath>
</PropertyGroup>
</Target>
</Project>
4 changes: 4 additions & 0 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
<AspNetCoreIntegrationTestingVersion>0.4.0-*</AspNetCoreIntegrationTestingVersion>
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
<NETStandardImplicitPackageVersion>$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
<TestSdkVersion>15.3.0-*</TestSdkVersion>
<XunitVersion>2.3.0-beta2-*</XunitVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@

<PropertyGroup>
<Description>Build-time references required to enable Razor view compilation as part of building the application.</Description>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<RuntimeIdentifier Condition="!$(TargetFramework.StartsWith('netcoreapp'))">win7-x64</RuntimeIdentifier>
<PackageTags>cshtml;razor;compilation;precompilation;aspnetcore</PackageTags>
<PreserveCompilationContext>true</PreserveCompilationContext>
<OutputType>exe</OutputType>
<!-- Include the build outputs in the build directory (and not the lib directory) -->
<BuildOutputTargetFolder>build</BuildOutputTargetFolder>
<X86ProjectDirectory>..\..\tools\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation-x86\</X86ProjectDirectory>
</PropertyGroup>

<ItemGroup>
<None Include="build\**\*" Pack="true" PackagePath="%(Identity)" />
<None Include="$(X86ProjectDirectory)\bin\$(Configuration)\net461\win7-x86\$(MSBuildThisFileName)-x86.exe" Pack="true" PackagePath="lib\net461\$(MSBuildThisFileName)-x86.exe" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
<ProjectReference Include="$(X86ProjectDirectory)$(MSBuildThisFileName)-x86.csproj" PrivateAssets="true" ReferenceOutputAssembly="false" Condition="'$(TargetFramework)'=='net461'" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we should be able to condense this to one project file. MSBuild is designed to handle this need w/o creating a separate csproj.

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)..\common.targets" />
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<Target
Name="MvcRazorPrecompile"
DependsOnTargets="_ResolveInputArguments"
Inputs="@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects);"
Outputs="$(_MvcRazorOutputFullPath)">

<PropertyGroup Condition="'$(MvcRazorRunCommand)'==''">
<MvcRazorRunCommand>$(OutputPath)$(MSBuildThisFileName).exe</MvcRazorRunCommand>
<MvcRazorRunCommand Condition="'$(PlatformTarget)'=='x86'">$(OutputPath)$(MSBuildThisFileName)-x86.exe</MvcRazorRunCommand>
</PropertyGroup>

<CallTarget Targets="_CreateResponseFileForMvcRazorPrecompile" />

<ItemGroup Condition="'$(PlatformTarget)'=='x86'">
<_PreCompilationFilesToCopy Include="$(OutputPath)$(AssemblyName).exe.config">
<Destination>$(OutputPath)$(MSBuildThisFileName)-x86.exe.config</Destination>
</_PreCompilationFilesToCopy>
</ItemGroup>

<ItemGroup Condition="'$(PlatformTarget)'!='x86'">
<_PreCompilationFilesToCopy Include="$(OutputPath)$(AssemblyName).exe.config" Condition="">
<Destination>$(OutputPath)$(MSBuildThisFileName).exe.config</Destination>
</_PreCompilationFilesToCopy>
</ItemGroup>

<Copy
SourceFiles="@(_PreCompilationFilesToCopy)"
DestinationFiles="%(Destination)" />

<Message
Text="Executing Razor view precompilation."
Importance="Low" />

<Exec
Command="$(MvcRazorRunCommand) @&quot;$(_MvcRazorResponseFilePath)&quot;"
WorkingDirectory="$(MSBuildProjectDirectory)"/>

<Message
Text="Razor view compilation for $(MSBuildProjectName) -> $(_MvcRazorOutputFullPath)"
Importance="High" />

<Delete Files="%(_PreCompilationFilesToCopy.Destination)" />

</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<Import Project="$(MSBuildThisFileDirectory)..\common.targets" />
<PropertyGroup>
<MvcRazorRunCommand>dotnet</MvcRazorRunCommand>
<_MvcViewCompilationBinaryPath Condition="'$(_MvcViewCompilationBinaryPath)'==''">$(MSBuildThisFileDirectory)$(MSBuildThisFileName).dll</_MvcViewCompilationBinaryPath>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<_MvcViewCompilationBinaryPath Condition="'$(_MvcViewCompilationBinaryPath)'==''">$(MSBuildThisFileDirectory)../../lib/netcoreapp2.0/$(MSBuildThisFileName).dll</_MvcViewCompilationBinaryPath>
</PropertyGroup>
<Target
Name="MvcRazorPrecompile"
DependsOnTargets="_ResolveInputArguments"
Inputs="$(MSBuildThisFileFullPath);@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects)"
Inputs="@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects)"
Outputs="$(_MvcRazorOutputFullPath)">

<CallTarget Targets="_CreateResponseFileForMvcRazorPrecompile" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;

namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
Expand All @@ -16,9 +18,15 @@ public ApplicationConsumingPrecompiledViews(ApplicationConsumingPrecompiledViews

public ApplicationTestFixture Fixture { get; }

[Fact]
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork()
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: where possible, use TheoryData<T>

Copy link
Author

Choose a reason for hiding this comment

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

Nah, it's more maintenance if you need to change signatures in the future. Same reasoning applies to why we choose to use var xyz = 123 over being explicit in the type name.


[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);

// Act
var response = await Fixture.HttpClient.GetStringWithRetryAsync("Manage/Home", Fixture.Logger);

Expand All @@ -34,4 +42,4 @@ public ApplicationConsumingPrecompiledViewsFixture()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;

namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
Expand All @@ -16,9 +18,15 @@ public ApplicationUsingRelativePathsTest(ApplicationUsingRelativePathsTestFixtur

public ApplicationTestFixture Fixture { get; }

[Fact]
public async Task Precompilation_WorksForViewsUsingRelativePath()
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;

[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForViewsUsingRelativePath(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);

// Act
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
Fixture.DeploymentResult.ApplicationBaseUri,
Expand All @@ -28,9 +36,13 @@ public async Task Precompilation_WorksForViewsUsingRelativePath()
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.Index.txt", response);
}

[Fact]
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal()
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);

// Act
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
Fixture.DeploymentResult.ApplicationBaseUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;

namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
Expand All @@ -16,9 +18,15 @@ public ApplicationWithConfigureMvcTest(ApplicationWithConfigureMvcFixture fixtur

public ApplicationTestFixture Fixture { get; }

[Fact]
public async Task Precompilation_RunsConfiguredCompilationCallbacks()
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;

[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);

// Act
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
Fixture.DeploymentResult.ApplicationBaseUri,
Expand All @@ -28,9 +36,13 @@ public async Task Precompilation_RunsConfiguredCompilationCallbacks()
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
}

[Fact]
public async Task Precompilation_UsesConfiguredParseOptions()
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);

// Act
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
"Home/ViewWithPreprocessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;

namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests
Expand All @@ -21,10 +23,14 @@ public ApplicationWithCustomInputFilesTest(ApplicationWithCustomInputFilesTestFi

public ApplicationTestFixture Fixture { get; }

[Fact]
public async Task ApplicationWithCustomInputFiles_Works()
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;

[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task ApplicationWithCustomInputFiles_Works(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);
var expectedText = "Hello Index!";

// Act
Expand All @@ -36,10 +42,12 @@ public async Task ApplicationWithCustomInputFiles_Works()
Assert.Equal(expectedText, response.Trim());
}

[Fact]
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled()
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);
var expectedViews = new[]
{
"/Views/Home/About.cshtml",
Expand All @@ -57,10 +65,12 @@ public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled()
Assert.Equal(expectedViews, actual);
}

[Fact]
public void MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled()
[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public void MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled(RuntimeFlavor flavor)
{
// Arrange
Fixture.CreateDeployment(flavor);
var viewsNotPublished = new[]
{
"Index.cshtml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;

namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
{
public class ApplicationWithParseErrorsTest
{
[Fact]
public async Task PublishingPrintsParseErrors()
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;

[ConditionalTheory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task PublishingPrintsParseErrors(RuntimeFlavor flavor)
{
// Arrange
var applicationPath = ApplicationPaths.GetTestAppDirectory("ApplicationWithParseErrors");
Expand All @@ -27,7 +31,7 @@ public async Task PublishingPrintsParseErrors()

};
var testSink = new TestSink();
var deploymentParameters = ApplicationTestFixture.GetDeploymentParameters(applicationPath);
var deploymentParameters = ApplicationTestFixture.GetDeploymentParameters(applicationPath, flavor);
var loggerFactory = new TestLoggerFactory(testSink, enabled: true);
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
Expand Down
Loading