Skip to content

Commit

Permalink
Respond to ProduceReferenceAssembly default changing to true
Browse files Browse the repository at this point in the history
.NET projects now produce a reference assembly by default, per a change in MSBuild's common targets. This commit updates a test on the SDK side in response to that change.
  • Loading branch information
drewnoakes committed Apr 13, 2023
1 parent 458cd31 commit 9ded50a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<AppendTargetFrameworkToOutputPath Condition="'$(AppendTargetFrameworkToOutputPath)' == ''">true</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<PropertyGroup>
<ProduceReferenceAssembly Condition="'$(ProduceReferenceAssembly)' == '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0)) and ('$(ProduceOnlyReferenceAssembly)' != 'true') and '$(MSBuildProjectExtension)' != '.fsproj'" >true</ProduceReferenceAssembly>
<ProduceReferenceAssembly Condition="'$(ProduceReferenceAssembly)' == '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 7.0)) and ('$(ProduceOnlyReferenceAssembly)' != 'true') and '$(MSBuildProjectExtension)' == '.fsproj'" >true</ProduceReferenceAssembly>
</PropertyGroup>

<!--
Append $(TargetFramework) directory to output and intermediate paths to prevent bin clashes between
targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Xunit.Abstractions;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.ProjectConstruction;
using System.Collections.Generic;

namespace Microsoft.NET.Build.Tests
{
Expand All @@ -18,26 +17,35 @@ public class GivenThatWeWantToProduceReferenceAssembly : SdkTest
public GivenThatWeWantToProduceReferenceAssembly(ITestOutputHelper log) : base(log)
{}

[RequiresMSBuildVersionTheory("16.8.0")]
[InlineData("netcoreapp3.1", false)]
[InlineData(ToolsetInfo.CurrentTargetFramework, true)]
public void It_produces_ref_assembly_for_appropriate_frameworks(string targetFramework, bool expectedExists)
[RequiresMSBuildVersionTheory("17.7.0")]
[InlineData("netcoreapp3.1", ".csproj")]
[InlineData("net5.0", ".csproj")]
[InlineData("net5.0", ".fsproj")]
[InlineData("net6.0", ".csproj")]
[InlineData("net6.0", ".fsproj")]
[InlineData("net7.0", ".csproj")]
[InlineData("net7.0", ".fsproj")]
#pragma warning disable xUnit1025 // InlineData duplicates
[InlineData(ToolsetInfo.CurrentTargetFramework, ".csproj")]
[InlineData(ToolsetInfo.CurrentTargetFramework, ".fsproj")]
#pragma warning restore xUnit1025 // InlineData duplicates
public void It_produces_ref_assembly_for_appropriate_frameworks(string targetFramework, string extension)
{
TestProject testProject = new TestProject()
TestProject testProject = new()
{
Name = "ProduceRefAssembly",
IsExe = true,
TargetFrameworks = targetFramework
};

var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework);
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework, targetExtension: extension);

var buildCommand = new BuildCommand(testAsset);
buildCommand.Execute()
.Should()
.Pass();
var filePath = Path.Combine(testAsset.Path, testProject.Name, "obj", "Debug", targetFramework, "ref", $"{testProject.Name}.dll");
File.Exists(filePath).Should().Be(expectedExists);
File.Exists(filePath).Should().Be(true);
}
}
}

0 comments on commit 9ded50a

Please sign in to comment.