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

Commit 82a301d

Browse files
author
N. Taylor Mullen
committed
Add support for pre-compiling desktop applications.
#128
1 parent baddfe5 commit 82a301d

File tree

46 files changed

+754
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+754
-91
lines changed

NuGetPackageVerifier.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
{
2+
"adx": {
3+
"rules": [
4+
"DefaultCompositeRule"
5+
],
6+
"packages": {
7+
"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation": {
8+
"exclusions": {
9+
"DOC_MISSING": {
10+
"lib/netcoreapp2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll": "Not a class library. Docs not required for CLI tools"
11+
},
12+
"BUILD_ITEMS_FRAMEWORK": {
13+
"*": "Doesn't matter"
14+
}
15+
}
16+
}
17+
}
18+
},
219
"Default": {
320
"rules": [
421
"DefaultCompositeRule"

RazorViewCompilation.sln

Lines changed: 166 additions & 3 deletions
Large diffs are not rendered by default.

build/common-testapps.props

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@
55
</PropertyGroup>
66

77
<Import Project="..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\build\netcoreapp2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets"
8-
Condition="'$(TestIncludeViewCompilationTargets)'=='true'"/>
8+
Condition="'$(TestIncludeViewCompilationTargets)'=='true' AND '$(TargetFramework)'=='netcoreapp2.0'"/>
9+
10+
<Import Project="..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\build\net461\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets"
11+
Condition="'$(TestIncludeViewCompilationTargets)'=='true' AND '$(TargetFramework)'=='net461'"/>
912

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

17+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
18+
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
19+
</ItemGroup>
20+
1421
<Target
1522
Name="SetMvcRazorViewCompilationBinaryPath"
1623
BeforeTargets="MvcRazorPrecompile"
1724
Condition="'$(TestIncludeViewCompilationTargets)'=='true'">
1825
<PropertyGroup>
19-
<_MvcViewCompilationBinaryPath>$(MSBuildProjectDirectory)\$(OutputPath)Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll</_MvcViewCompilationBinaryPath>
26+
<_MvcViewCompilationBinaryPath Condition="'$(TargetFramework)'=='netcoreapp2.0'">$(MSBuildProjectDirectory)\$(OutputPath)Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll</_MvcViewCompilationBinaryPath>
27+
<_MvcViewCompilationBinaryPath Condition="'$(TargetFramework)'=='net461'">$(MSBuildProjectDirectory)\$(OutputPath)Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.exe</_MvcViewCompilationBinaryPath>
2028
</PropertyGroup>
2129
</Target>
2230
</Project>

build/common.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
1717
</ItemGroup>
1818

19+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
20+
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" PrivateAssets="All" />
21+
</ItemGroup>
22+
1923
</Project>

build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
44
<AspNetCoreIntegrationTestingVersion>0.4.0-*</AspNetCoreIntegrationTestingVersion>
55
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
6-
<NETStandardImplicitPackageVersion>$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
6+
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
77
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
88
<TestSdkVersion>15.3.0-*</TestSdkVersion>
99
<XunitVersion>2.3.0-beta2-*</XunitVersion>

src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44

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

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

1921
<ItemGroup>
2022
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(AspNetCoreVersion)" />
2123
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="$(AspNetCoreVersion)" />
2224
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
25+
<ProjectReference Include="$(X86ProjectDirectory)$(MSBuildThisFileName)-x86.csproj" PrivateAssets="true" ReferenceOutputAssembly="false" Condition="'$(TargetFramework)'=='net461'" />
2326
</ItemGroup>
2427

2528
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="$(MSBuildThisFileDirectory)..\common.targets" />
3+
<PropertyGroup>
4+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
</PropertyGroup>
6+
<Target
7+
Name="MvcRazorPrecompile"
8+
DependsOnTargets="_ResolveInputArguments"
9+
Inputs="@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects);"
10+
Outputs="$(_MvcRazorOutputFullPath)">
11+
12+
<PropertyGroup Condition="'$(MvcRazorRunCommand)'==''">
13+
<MvcRazorRunCommand>$(OutputPath)$(MSBuildThisFileName).exe</MvcRazorRunCommand>
14+
<MvcRazorRunCommand Condition="'$(PlatformTarget)'=='x86'">$(OutputPath)$(MSBuildThisFileName)-x86.exe</MvcRazorRunCommand>
15+
</PropertyGroup>
16+
17+
<CallTarget Targets="_CreateResponseFileForMvcRazorPrecompile" />
18+
19+
<ItemGroup Condition="'$(PlatformTarget)'=='x86'">
20+
<_PreCompilationFilesToCopy Include="$(OutputPath)$(AssemblyName).exe.config">
21+
<Destination>$(OutputPath)$(MSBuildThisFileName)-x86.exe.config</Destination>
22+
</_PreCompilationFilesToCopy>
23+
</ItemGroup>
24+
25+
<ItemGroup Condition="'$(PlatformTarget)'!='x86'">
26+
<_PreCompilationFilesToCopy Include="$(OutputPath)$(AssemblyName).exe.config" Condition="">
27+
<Destination>$(OutputPath)$(MSBuildThisFileName).exe.config</Destination>
28+
</_PreCompilationFilesToCopy>
29+
</ItemGroup>
30+
31+
<Copy
32+
SourceFiles="@(_PreCompilationFilesToCopy)"
33+
DestinationFiles="%(Destination)" />
34+
35+
<Message
36+
Text="Executing Razor view precompilation."
37+
Importance="Low" />
38+
39+
<Exec
40+
Command="$(MvcRazorRunCommand) @&quot;$(_MvcRazorResponseFilePath)&quot;"
41+
WorkingDirectory="$(MSBuildProjectDirectory)"/>
42+
43+
<Message
44+
Text="Razor view compilation for $(MSBuildProjectName) -> $(_MvcRazorOutputFullPath)"
45+
Importance="High" />
46+
47+
<Delete Files="%(_PreCompilationFilesToCopy.Destination)" />
48+
49+
</Target>
50+
</Project>

src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netcoreapp2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
<Import Project="$(MSBuildThisFileDirectory)..\common.targets" />
33
<PropertyGroup>
44
<MvcRazorRunCommand>dotnet</MvcRazorRunCommand>
5-
<_MvcViewCompilationBinaryPath Condition="'$(_MvcViewCompilationBinaryPath)'==''">$(MSBuildThisFileDirectory)$(MSBuildThisFileName).dll</_MvcViewCompilationBinaryPath>
5+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
6+
<_MvcViewCompilationBinaryPath Condition="'$(_MvcViewCompilationBinaryPath)'==''">$(MSBuildThisFileDirectory)../../lib/netcoreapp2.0/$(MSBuildThisFileName).dll</_MvcViewCompilationBinaryPath>
67
</PropertyGroup>
78
<Target
89
Name="MvcRazorPrecompile"
910
DependsOnTargets="_ResolveInputArguments"
10-
Inputs="$(MSBuildThisFileFullPath);@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects)"
11+
Inputs="@(MvcRazorFilesToCompile);@(IntermediateAssembly);@(DocFileItem);@(_DebugSymbolsIntermediatePath);@(ReferencePath);$(MSBuildAllProjects)"
1112
Outputs="$(_MvcRazorOutputFullPath)">
1213

1314
<CallTarget Targets="_CreateResponseFileForMvcRazorPrecompile" />

test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationConsumingPrecompiledViews.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Server.IntegrationTesting;
6+
using Microsoft.AspNetCore.Testing.xunit;
57
using Xunit;
68

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

1719
public ApplicationTestFixture Fixture { get; }
1820

19-
[Fact]
20-
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork()
21+
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
22+
23+
[ConditionalTheory]
24+
[MemberData(nameof(SupportedFlavorsTheoryData))]
25+
public async Task ConsumingClassLibrariesWithPrecompiledViewsWork(RuntimeFlavor flavor)
2126
{
27+
// Arrange
28+
Fixture.CreateDeployment(flavor);
29+
2230
// Act
2331
var response = await Fixture.HttpClient.GetStringWithRetryAsync("Manage/Home", Fixture.Logger);
2432

@@ -34,4 +42,4 @@ public ApplicationConsumingPrecompiledViewsFixture()
3442
}
3543
}
3644
}
37-
}
45+
}

test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationUsingRelativePathsTest.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Server.IntegrationTesting;
6+
using Microsoft.AspNetCore.Testing.xunit;
57
using Xunit;
68

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

1719
public ApplicationTestFixture Fixture { get; }
1820

19-
[Fact]
20-
public async Task Precompilation_WorksForViewsUsingRelativePath()
21+
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
22+
23+
[ConditionalTheory]
24+
[MemberData(nameof(SupportedFlavorsTheoryData))]
25+
public async Task Precompilation_WorksForViewsUsingRelativePath(RuntimeFlavor flavor)
2126
{
27+
// Arrange
28+
Fixture.CreateDeployment(flavor);
29+
2230
// Act
2331
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
2432
Fixture.DeploymentResult.ApplicationBaseUri,
@@ -28,9 +36,13 @@ public async Task Precompilation_WorksForViewsUsingRelativePath()
2836
TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.Index.txt", response);
2937
}
3038

31-
[Fact]
32-
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal()
39+
[ConditionalTheory]
40+
[MemberData(nameof(SupportedFlavorsTheoryData))]
41+
public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor)
3342
{
43+
// Arrange
44+
Fixture.CreateDeployment(flavor);
45+
3446
// Act
3547
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
3648
Fixture.DeploymentResult.ApplicationBaseUri,

test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithConfigureMvcTest.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Server.IntegrationTesting;
6+
using Microsoft.AspNetCore.Testing.xunit;
57
using Xunit;
68

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

1719
public ApplicationTestFixture Fixture { get; }
1820

19-
[Fact]
20-
public async Task Precompilation_RunsConfiguredCompilationCallbacks()
21+
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
22+
23+
[ConditionalTheory]
24+
[MemberData(nameof(SupportedFlavorsTheoryData))]
25+
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
2126
{
27+
// Arrange
28+
Fixture.CreateDeployment(flavor);
29+
2230
// Act
2331
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
2432
Fixture.DeploymentResult.ApplicationBaseUri,
@@ -28,9 +36,13 @@ public async Task Precompilation_RunsConfiguredCompilationCallbacks()
2836
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
2937
}
3038

31-
[Fact]
32-
public async Task Precompilation_UsesConfiguredParseOptions()
39+
[ConditionalTheory]
40+
[MemberData(nameof(SupportedFlavorsTheoryData))]
41+
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
3342
{
43+
// Arrange
44+
Fixture.CreateDeployment(flavor);
45+
3446
// Act
3547
var response = await Fixture.HttpClient.GetStringWithRetryAsync(
3648
"Home/ViewWithPreprocessor",

test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithCustomInputFilesTest.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.IO;
66
using System.Linq;
77
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Server.IntegrationTesting;
9+
using Microsoft.AspNetCore.Testing.xunit;
810
using Xunit;
911

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

2224
public ApplicationTestFixture Fixture { get; }
2325

24-
[Fact]
25-
public async Task ApplicationWithCustomInputFiles_Works()
26+
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
27+
28+
[ConditionalTheory]
29+
[MemberData(nameof(SupportedFlavorsTheoryData))]
30+
public async Task ApplicationWithCustomInputFiles_Works(RuntimeFlavor flavor)
2631
{
2732
// Arrange
33+
Fixture.CreateDeployment(flavor);
2834
var expectedText = "Hello Index!";
2935

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

39-
[Fact]
40-
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled()
45+
[ConditionalTheory]
46+
[MemberData(nameof(SupportedFlavorsTheoryData))]
47+
public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled(RuntimeFlavor flavor)
4148
{
4249
// Arrange
50+
Fixture.CreateDeployment(flavor);
4351
var expectedViews = new[]
4452
{
4553
"/Views/Home/About.cshtml",
@@ -57,10 +65,12 @@ public async Task MvcRazorFilesToCompile_OverridesTheFilesToBeCompiled()
5765
Assert.Equal(expectedViews, actual);
5866
}
5967

60-
[Fact]
61-
public void MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled()
68+
[ConditionalTheory]
69+
[MemberData(nameof(SupportedFlavorsTheoryData))]
70+
public void MvcRazorFilesToCompile_SpecificallyDoesNotPublishFilesToBeCompiled(RuntimeFlavor flavor)
6271
{
6372
// Arrange
73+
Fixture.CreateDeployment(flavor);
6474
var viewsNotPublished = new[]
6575
{
6676
"Index.cshtml",

test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationWithParseErrorsTest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
using System.Linq;
77
using System.Threading.Tasks;
88
using Microsoft.AspNetCore.Server.IntegrationTesting;
9+
using Microsoft.AspNetCore.Testing.xunit;
910
using Microsoft.Extensions.Logging.Testing;
1011
using Xunit;
1112

1213
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
1314
{
1415
public class ApplicationWithParseErrorsTest
1516
{
16-
[Fact]
17-
public async Task PublishingPrintsParseErrors()
17+
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
18+
19+
[ConditionalTheory]
20+
[MemberData(nameof(SupportedFlavorsTheoryData))]
21+
public async Task PublishingPrintsParseErrors(RuntimeFlavor flavor)
1822
{
1923
// Arrange
2024
var applicationPath = ApplicationPaths.GetTestAppDirectory("ApplicationWithParseErrors");
@@ -27,7 +31,7 @@ public async Task PublishingPrintsParseErrors()
2731

2832
};
2933
var testSink = new TestSink();
30-
var deploymentParameters = ApplicationTestFixture.GetDeploymentParameters(applicationPath);
34+
var deploymentParameters = ApplicationTestFixture.GetDeploymentParameters(applicationPath, flavor);
3135
var loggerFactory = new TestLoggerFactory(testSink, enabled: true);
3236
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
3337
{

0 commit comments

Comments
 (0)