Noop Razor Sdk for F# projects

This commit is contained in:
Ajay Bhargav Baaskaran 2018-04-11 12:05:13 -07:00
parent 5504374125
commit 6d9df1ef33
11 changed files with 119 additions and 16 deletions

View File

@ -74,11 +74,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<!--
Default values for properties that affect Razor targets to the standard build lifecycle.
-->
<PropertyGroup Condition="'$(RazorCompileOnBuild)'==''">
<PropertyGroup Condition="'$(RazorCompileOnBuild)'=='' AND '$(Language)'=='C#'">
<RazorCompileOnBuild>true</RazorCompileOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(RazorCompileOnPublish)'==''">
<PropertyGroup Condition="'$(RazorCompileOnPublish)'=='' AND '$(Language)'=='C#'">
<!-- Always compile on publish by default if we're compiling on build -->
<RazorCompileOnPublish Condition="'$(RazorCompileOnBuild)'=='true'">true</RazorCompileOnPublish>

View File

@ -194,7 +194,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
}
[Fact]
[InitializeTestProject("AppWithP2PReference", "ClassLibrary")]
[InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")]
public async Task Build_WithP2P_CopiesRazorAssembly()
{
var result = await DotnetMSBuild("Build");
@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
}
[Fact]
[InitializeTestProject("SimplePages", "LinkedDir")]
[InitializeTestProject("SimplePages", additionalProjects: "LinkedDir")]
public async Task Build_SetsUpEmbeddedResourcesWithLogicalName()
{
// Arrange
@ -455,6 +455,23 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2-1\")");
}
[Fact]
[InitializeTestProject("SimpleMvcFSharp", language: "F#")]
public async Task Build_SimpleMvcFSharp_NoopsWithoutFailing()
{
var result = await DotnetMSBuild("Build");
Assert.BuildPassed(result);
Assert.FileExists(result, OutputPath, "SimpleMvcFSharp.dll");
Assert.FileExists(result, OutputPath, "SimpleMvcFSharp.pdb");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvcFSharp.dll");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvcFSharp.pdb");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
}
private static DependencyContext ReadDependencyContext(string depsFilePath)
{
var reader = new DependencyContextJsonReader();

View File

@ -13,18 +13,20 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
private readonly string _testProjectName;
private readonly string _baseDirectory;
private readonly string[] _additionalProjects;
private readonly string _language;
public InitializeTestProjectAttribute(string projectName, params string[] additionalProjects)
: this (projectName, projectName, string.Empty, additionalProjects)
public InitializeTestProjectAttribute(string projectName, string language = "C#", params string[] additionalProjects)
: this (projectName, projectName, string.Empty, language, additionalProjects)
{
}
public InitializeTestProjectAttribute(string originalProjectName, string targetProjectName, string baseDirectory, string[] additionalProjects = null)
public InitializeTestProjectAttribute(string originalProjectName, string targetProjectName, string baseDirectory, string language = "C#", string[] additionalProjects = null)
{
_originalProjectName = originalProjectName;
_testProjectName = targetProjectName;
_baseDirectory = baseDirectory;
_additionalProjects = additionalProjects ?? Array.Empty<string>();
_language = language;
}
public override void Before(MethodInfo methodUnderTest)
@ -34,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
throw new InvalidOperationException($"This should be used on a class derived from {typeof(MSBuildIntegrationTestBase)}");
}
MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_originalProjectName, _testProjectName, _baseDirectory, _additionalProjects);
MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_originalProjectName, _testProjectName, _baseDirectory, _additionalProjects, _language);
MSBuildIntegrationTestBase.TargetFramework = _originalProjectName == "ClassLibrary" ? "netstandard2.0" : "netcoreapp2.0";
}

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
public bool PreserveWorkingDirectory { get; set; }
#endif
public static ProjectDirectory Create(string originalProjectName, string targetProjectName, string baseDirectory, string[] additionalProjects)
public static ProjectDirectory Create(string originalProjectName, string targetProjectName, string baseDirectory, string[] additionalProjects, string language)
{
var destinationPath = Path.Combine(Path.GetTempPath(), "Razor", baseDirectory, Path.GetRandomFileName());
Directory.CreateDirectory(destinationPath);
@ -53,10 +53,23 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
SetupDirectoryBuildFiles(solutionRoot, binariesRoot, testAppsRoot, projectDestination);
}
// Rename the csproj
// Rename the csproj/fsproj
string extension;
if (language.Equals("C#", StringComparison.OrdinalIgnoreCase))
{
extension = ".csproj";
}
else if (language.Equals("F#", StringComparison.OrdinalIgnoreCase))
{
extension = ".fsproj";
}
else
{
throw new InvalidOperationException($"Language {language} is not supported.");
}
var directoryPath = Path.Combine(destinationPath, originalProjectName);
var oldProjectFilePath = Path.Combine(directoryPath, originalProjectName + ".csproj");
var newProjectFilePath = Path.Combine(directoryPath, targetProjectName + ".csproj");
var oldProjectFilePath = Path.Combine(directoryPath, originalProjectName + extension);
var newProjectFilePath = Path.Combine(directoryPath, targetProjectName + extension);
File.Move(oldProjectFilePath, newProjectFilePath);
CopyGlobalJson(solutionRoot, destinationPath);

View File

@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
}
[Fact]
[InitializeTestProject("AppWithP2PReference", "ClassLibrary")]
[InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")]
public async Task Publish_WithP2P_AndRazorCompileOnBuild_CopiesRazorAssembly()
{
var result = await DotnetMSBuild("Publish");
@ -276,7 +276,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
}
[Fact]
[InitializeTestProject("AppWithP2PReference", "ClassLibrary")]
[InitializeTestProject("AppWithP2PReference", additionalProjects: "ClassLibrary")]
public async Task Publish_WithP2P_AndRazorCompileOnPublish_CopiesRazorAssembly()
{
var result = await DotnetMSBuild("Publish");
@ -292,5 +292,20 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.dll");
Assert.FileExists(result, PublishOutputPath, "ClassLibrary.Views.pdb");
}
[Fact]
[InitializeTestProject("SimpleMvcFSharp", language: "F#")]
public async Task Publish_SimpleMvcFSharp_NoopsWithoutFailing()
{
var result = await DotnetMSBuild("Publish");
Assert.BuildPassed(result);
Assert.FileExists(result, PublishOutputPath, "SimpleMvcFSharp.dll");
Assert.FileExists(result, PublishOutputPath, "SimpleMvcFSharp.pdb");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
}
}
}

View File

@ -273,7 +273,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
}
[Fact]
[InitializeTestProject("SimpleMvc", "LinkedDir")]
[InitializeTestProject("SimpleMvc", additionalProjects: "LinkedDir")]
public async Task RazorGenerate_WorksWithLinkedFiles()
{
// Arrange
@ -300,7 +300,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
}
[Fact]
[InitializeTestProject("SimpleMvc", "LinkedDir")]
[InitializeTestProject("SimpleMvc", additionalProjects: "LinkedDir")]
public async Task RazorGenerate_PrintsErrorsFromLinkedFiles()
{
// Arrange

View File

@ -0,0 +1,8 @@
namespace SimpleMvcFSharp
open System
type ErrorViewModel private () =
member val RequestId : string = null with get, set
member val ShowRequestId : bool = true with get, set

View File

@ -0,0 +1,11 @@
namespace SimpleMvcFSharp
module Program =
let exitCode = 0
[<EntryPoint>]
let main args =
let t = typeof<Microsoft.AspNetCore.Mvc.IActionResult>
System.Console.WriteLine(t.FullName)
exitCode

View File

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<_RazorMSBuildRoot>$(SolutionRoot)src\Microsoft.AspNetCore.Razor.Design\bin\$(Configuration)\netstandard2.0\</_RazorMSBuildRoot>
</PropertyGroup>
<Import Project="$(SolutionRoot)src\Microsoft.AspNetCore.Razor.Design\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.props" />
<PropertyGroup>
<!-- Override for the MVC extension -->
<_MvcExtensionAssemblyPath>$(SolutionRoot)src\Microsoft.AspNetCore.Mvc.Razor.Extensions\bin\$(Configuration)\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.Extensions.dll</_MvcExtensionAssemblyPath>
</PropertyGroup>
<Import Project="$(SolutionRoot)src\Microsoft.AspNetCore.Mvc.Razor.Extensions\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.Extensions.props" />
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Models/ErrorViewModel.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<!-- Test Placeholder -->
<Import Project="$(SolutionRoot)src\Microsoft.AspNetCore.Mvc.Razor.Extensions\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.Extensions.targets" />
</Project>

View File

@ -0,0 +1,7 @@
@{
ViewData["Title"] = "About";
}
<h2>@ViewData["Title"].</h2>
<h3>@ViewData["Message"]</h3>
<p>Use this area to provide additional information.</p>

View File

@ -0,0 +1,2 @@
@using SimpleMvcFSharp
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers