diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.BeforeCommon.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.BeforeCommon.targets new file mode 100644 index 000000000000..97a992ab31f0 --- /dev/null +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.BeforeCommon.targets @@ -0,0 +1,21 @@ + + + + + + true + + + false + + diff --git a/src/RazorSdk/Targets/Sdk.Razor.CurrentVersion.props b/src/RazorSdk/Targets/Sdk.Razor.CurrentVersion.props index 795c769a0681..a28e616ff935 100644 --- a/src/RazorSdk/Targets/Sdk.Razor.CurrentVersion.props +++ b/src/RazorSdk/Targets/Sdk.Razor.CurrentVersion.props @@ -67,12 +67,6 @@ Copyright (c) .NET Foundation. All rights reserved. --> .g.cs - - true - - - false - - - + + + + @@ -181,7 +187,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_FrameworkIdentifierForImplicitDefine Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework'">NET <_FrameworkVersionForImplicitDefine>$(TargetFrameworkVersion.TrimStart('vV')) - + <_FrameworkVersionForImplicitDefine>$(_FrameworkVersionForImplicitDefine.Replace('.', '_')) <_FrameworkVersionForImplicitDefine Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework'">$(_FrameworkVersionForImplicitDefine.Replace('_', '')) @@ -214,9 +220,9 @@ Copyright (c) .NET Foundation. All rights reserved. <_CompatibleFrameworkVersions Include="@(_SupportedFrameworkVersions)" Condition=" $([MSBuild]::VersionLessThanOrEquals(%(Identity), $(TargetFrameworkVersion))) " /> <_FormattedCompatibleFrameworkVersions Include="@(_CompatibleFrameworkVersions)" Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' or '$(TargetFrameworkIdentifier)' == '.NETStandard' " /> <_FormattedCompatibleFrameworkVersions Include="@(_CompatibleFrameworkVersions->'%(Identity)'->Replace('.', ''))" Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' " /> - <_ImplicitDefineConstant Include="@(_FormattedCompatibleFrameworkVersions->'$(_FrameworkIdentifierForImplicitDefine)%(Identity)_OR_GREATER'->Replace('.', '_'))" + <_ImplicitDefineConstant Include="@(_FormattedCompatibleFrameworkVersions->'$(_FrameworkIdentifierForImplicitDefine)%(Identity)_OR_GREATER'->Replace('.', '_'))" Condition=" '$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionGreaterThanOrEquals(%(_FormattedCompatibleFrameworkVersions.Identity), 5.0)) " /> - <_ImplicitDefineConstant Include="@(_FormattedCompatibleFrameworkVersions->'NETCOREAPP%(Identity)_OR_GREATER'->Replace('.', '_'))" + <_ImplicitDefineConstant Include="@(_FormattedCompatibleFrameworkVersions->'NETCOREAPP%(Identity)_OR_GREATER'->Replace('.', '_'))" Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionLessThan(%(_FormattedCompatibleFrameworkVersions.Identity), 5.0)) " /> diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs index b31eed5532f9..b72c12888998 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs @@ -117,7 +117,7 @@ public void Build_WithP2P_CopiesRazorAssembly() } [Fact] - public void Build_WithViews_ProducesDepsFileWithCompilationContext_ButNoReferences() + public void Build_CompilationContextAndRefsDirectoryAreNotPreserved() { var testAsset = "RazorSimpleMvc"; var projectDirectory = CreateAspNetSdkTestAsset(testAsset); @@ -132,14 +132,9 @@ public void Build_WithViews_ProducesDepsFileWithCompilationContext_ButNoReferenc var depsFilePath = Path.Combine(outputPath, "SimpleMvc.deps.json"); var dependencyContext = ReadDependencyContext(depsFilePath); - // Pick a couple of libraries and ensure they have some compile references - var packageReference = dependencyContext.CompileLibraries.First(l => l.Name == "System.Diagnostics.DiagnosticSource"); - packageReference.Assemblies.Should().NotBeEmpty(); - - var projectReference = dependencyContext.CompileLibraries.First(l => l.Name == "SimpleMvc"); - projectReference.Assemblies.Should().NotBeEmpty(); - - dependencyContext.CompilationOptions.Defines.Should().Contain(customDefine); + var library = Assert.Single(dependencyContext.CompileLibraries); + Assert.Empty(library.Assemblies); + Assert.Empty(dependencyContext.CompilationOptions.Defines); // Verify no refs folder is produced new DirectoryInfo(Path.Combine(outputPath, "publish", "refs")).Should().NotExist(); diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs index a1f535f09a5f..9905b016dadd 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs @@ -3,9 +3,11 @@ using System; using System.IO; +using System.Linq; using System.Threading.Tasks; using System.Xml.Linq; using FluentAssertions; +using Microsoft.Extensions.DependencyModel; using Microsoft.NET.TestFramework; using Microsoft.NET.TestFramework.Assertions; using Microsoft.NET.TestFramework.Commands; @@ -106,5 +108,43 @@ public virtual void Publish_IncludesRefAssemblies_WhenCopyRefAssembliesToPublish new FileInfo(Path.Combine(outputPath, "refs", "System.Threading.Tasks.Extensions.dll")).Should().Exist(); } + + [CoreMSBuildOnlyFact] + public void Build_ProducesDepsFileWithCompilationContext_ButNoReferences() + { + var testAsset = $"Razor{TestProjectName}"; + var projectDirectory = CreateAspNetSdkTestAsset(testAsset); + + var customDefine = "AspNetSdkTest"; + var build = new BuildCommand(projectDirectory); + build.Execute($"/p:DefineConstants={customDefine}").Should().Pass(); + + var outputPath = build.GetOutputDirectory(TargetFramework, "Debug").ToString(); + + var depsFile = new FileInfo(Path.Combine(outputPath, $"{TestProjectName}.deps.json")); + depsFile.Should().Exist(); + var dependencyContext = ReadDependencyContext(depsFile.FullName); + + // Ensure some compile references exist + var packageReference = dependencyContext.CompileLibraries.First(l => l.Name == "System.Runtime.CompilerServices.Unsafe"); + packageReference.Assemblies.Should().NotBeEmpty(); + + var projectReference = dependencyContext.CompileLibraries.First(l => l.Name == TestProjectName); + projectReference.Assemblies.Should().NotBeEmpty(); + + dependencyContext.CompilationOptions.Defines.Should().Contain(customDefine); + + // Verify no refs folder is produced + new DirectoryInfo(Path.Combine(outputPath, "publish", "refs")).Should().NotExist(); + } + + private static DependencyContext ReadDependencyContext(string depsFilePath) + { + var reader = new DependencyContextJsonReader(); + using (var stream = File.OpenRead(depsFilePath)) + { + return reader.Read(stream); + } + } } }