Make sure RazorSdk works when BuildingInVisualStudio \ BuildProjectReferences is disabled
Fixes #2247
This commit is contained in:
parent
f8dc5c4702
commit
8d1de6ec80
|
|
@ -69,6 +69,11 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
_RazorAddDebugSymbolsProjectOutputGroupOutput
|
_RazorAddDebugSymbolsProjectOutputGroupOutput
|
||||||
</DebugSymbolsProjectOutputGroupDependsOn>
|
</DebugSymbolsProjectOutputGroupDependsOn>
|
||||||
|
|
||||||
|
<PrepareForRunDependsOn>
|
||||||
|
_RazorPrepareForRun;
|
||||||
|
$(PrepareForRunDependsOn)
|
||||||
|
</PrepareForRunDependsOn>
|
||||||
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
@ -361,6 +366,15 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Set up RazorCompile to run before PrepareForRun. This should ensure that the Razor dll and pdbs are available to be copied
|
||||||
|
as part of GetCopyToOutputDirectoryItems which is invoked during PrepareForRun.
|
||||||
|
-->
|
||||||
|
<Target
|
||||||
|
Name="_RazorPrepareForRun"
|
||||||
|
DependsOnTargets="RazorCompile"
|
||||||
|
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnBuild)'=='true'" />
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Called as part of GetCopyToOutputDirectoryItems - this target populates the list of items that get
|
Called as part of GetCopyToOutputDirectoryItems - this target populates the list of items that get
|
||||||
copied to the output directory when building as a project reference.
|
copied to the output directory when building as a project reference.
|
||||||
|
|
@ -368,7 +382,6 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
<Target
|
<Target
|
||||||
Name="_RazorGetCopyToOutputDirectoryItems"
|
Name="_RazorGetCopyToOutputDirectoryItems"
|
||||||
BeforeTargets="GetCopyToOutputDirectoryItems"
|
BeforeTargets="GetCopyToOutputDirectoryItems"
|
||||||
DependsOnTargets="RazorCompile"
|
|
||||||
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnBuild)'=='true'">
|
Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(RazorCompileOnBuild)'=='true'">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
@ -472,6 +473,41 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
|
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[InitializeTestProject("AppWithP2PReference", additionalProjects: new[] { "ClassLibrary", "ClassLibrary2" })]
|
||||||
|
public async Task Build_WithP2P_WorksWhenBuildProjectReferencesIsDisabled()
|
||||||
|
{
|
||||||
|
// Simulates building the same way VS does by setting BuildProjectReferences=false.
|
||||||
|
// With this flag, P2P references aren't resolved during GetCopyToOutputDirectoryItems. This test ensures that
|
||||||
|
// no Razor work is done in such a scenario and the build succeeds.
|
||||||
|
var additionalProjectContent = @"
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include=""..\ClassLibrary2\ClassLibrary2.csproj"" />
|
||||||
|
</ItemGroup>
|
||||||
|
";
|
||||||
|
AddProjectFileContent(additionalProjectContent);
|
||||||
|
|
||||||
|
var result = await DotnetMSBuild(target: default);
|
||||||
|
|
||||||
|
Assert.BuildPassed(result);
|
||||||
|
|
||||||
|
Assert.FileExists(result, OutputPath, "AppWithP2PReference.dll");
|
||||||
|
Assert.FileExists(result, OutputPath, "AppWithP2PReference.Views.dll");
|
||||||
|
Assert.FileExists(result, OutputPath, "ClassLibrary.dll");
|
||||||
|
Assert.FileExists(result, OutputPath, "ClassLibrary.Views.dll");
|
||||||
|
Assert.FileExists(result, OutputPath, "ClassLibrary2.dll");
|
||||||
|
Assert.FileExists(result, OutputPath, "ClassLibrary2.Views.dll");
|
||||||
|
|
||||||
|
// Force a rebuild of ClassLibrary2 by changing a file
|
||||||
|
var class2Path = Path.Combine(Project.SolutionPath, "ClassLibrary2", "Class2.cs");
|
||||||
|
File.AppendAllText(class2Path, Environment.NewLine + "// Some changes");
|
||||||
|
|
||||||
|
// dotnet msbuild /p:BuildProjectReferences=false
|
||||||
|
result = await DotnetMSBuild(target: default, "/p:BuildProjectReferences=false", suppressRestore: true);
|
||||||
|
|
||||||
|
Assert.BuildPassed(result);
|
||||||
|
}
|
||||||
|
|
||||||
private static DependencyContext ReadDependencyContext(string depsFilePath)
|
private static DependencyContext ReadDependencyContext(string depsFilePath)
|
||||||
{
|
{
|
||||||
var reader = new DependencyContextJsonReader();
|
var reader = new DependencyContextJsonReader();
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
}
|
}
|
||||||
|
|
||||||
MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_originalProjectName, _testProjectName, _baseDirectory, _additionalProjects, _language);
|
MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_originalProjectName, _testProjectName, _baseDirectory, _additionalProjects, _language);
|
||||||
MSBuildIntegrationTestBase.TargetFramework = _originalProjectName == "ClassLibrary" ? "netstandard2.0" : "netcoreapp2.0";
|
MSBuildIntegrationTestBase.TargetFramework = _originalProjectName.StartsWith("ClassLibrary") ? "netstandard2.0" : "netcoreapp2.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void After(MethodInfo methodUnderTest)
|
public override void After(MethodInfo methodUnderTest)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,12 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
buildArgumentList.Add($"/p:_RazorSuppressCurrentUserOnlyPipeOptions=true");
|
buildArgumentList.Add($"/p:_RazorSuppressCurrentUserOnlyPipeOptions=true");
|
||||||
}
|
}
|
||||||
|
|
||||||
buildArgumentList.Add($"/t:{target} /p:Configuration={Configuration} {args}");
|
if (!string.IsNullOrEmpty(target))
|
||||||
|
{
|
||||||
|
buildArgumentList.Add($"/t:{target}");
|
||||||
|
}
|
||||||
|
|
||||||
|
buildArgumentList.Add($"/p:Configuration={Configuration} {args}");
|
||||||
var buildArguments = string.Join(" ", buildArgumentList);
|
var buildArguments = string.Join(" ", buildArgumentList);
|
||||||
|
|
||||||
return MSBuildProcessManager.RunProcessAsync(
|
return MSBuildProcessManager.RunProcessAsync(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using ClassLibrary;
|
||||||
|
|
||||||
|
namespace ClassLibrary2
|
||||||
|
{
|
||||||
|
public class Class2
|
||||||
|
{
|
||||||
|
public void Method()
|
||||||
|
{
|
||||||
|
Console.WriteLine(typeof(Class1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
|
<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>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ClassLibrary\ClassLibrary.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Test Placeholder -->
|
||||||
|
|
||||||
|
<Import Project="$(SolutionRoot)src\Microsoft.AspNetCore.Mvc.Razor.Extensions\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.Extensions.targets" />
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
@{ var message = "Hello world";}
|
||||||
|
@message
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
@using ClassLibrary
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
Loading…
Reference in New Issue