Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respond to ProduceReferenceAssembly default changing to true #31598

Merged

Conversation

drewnoakes
Copy link
Member

@drewnoakes drewnoakes commented Apr 4, 2023

Fixes dotnet/msbuild#8133
Relates to dotnet/msbuild#8571

We have changed the default for all .NET projects such that ProduceReferenceAssembly is true by default. This change requires updates to the SDK, which are included in this PR.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Apr 4, 2023
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

[InlineData("net7.0", ".fsproj")]
[InlineData(ToolsetInfo.CurrentTargetFramework, ".csproj")]
[InlineData(ToolsetInfo.CurrentTargetFramework, ".fsproj")]
public void It_produces_ref_assembly_for_all_frameworks(string targetFramework, string extension)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixes here address the failures that led to dotnet/msbuild#8131

dotnet-maestro bot and others added 2 commits April 12, 2023 23:22
…0412.2

Microsoft.SourceBuild.Intermediate.msbuild , Microsoft.Build , Microsoft.Build.Localization
 From Version 17.7.0-preview-23212-01 -> To Version 17.7.0-preview-23212-02
.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.
@drewnoakes drewnoakes force-pushed the ref-assemblies-by-default branch from 4549367 to 9ded50a Compare April 13, 2023 00:16
@drewnoakes drewnoakes changed the base branch from main to release/7.0.4xx April 13, 2023 00:17
@drewnoakes
Copy link
Member Author

This is failing due to test GivenThatWeWantToBuildANetCoreApp.It_builds_the_project_successfully_with_only_reference_assembly_set on line 909:

[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_builds_the_project_successfully_with_only_reference_assembly_set(bool produceOnlyReferenceAssembly)
{
var testProject = new TestProject()
{
Name = "MainProject",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
IsSdkProject = true,
IsExe = true
};
testProject.AdditionalProperties["ProduceOnlyReferenceAssembly"] = produceOnlyReferenceAssembly.ToString();
var testProjectInstance = _testAssetsManager.CreateTestProject(testProject, identifier: produceOnlyReferenceAssembly.ToString());
var buildCommand = new BuildCommand(testProjectInstance);
buildCommand
.Execute()
.Should()
.Pass();
var outputPath = buildCommand.GetOutputDirectory(targetFramework: ToolsetInfo.CurrentTargetFramework).FullName;
if (produceOnlyReferenceAssembly == true)
{
var refPath = Path.Combine(outputPath, "ref");
Directory.Exists(refPath)
.Should()
.BeFalse();
}
else
{
// Reference assembly should be produced in obj
var refPath = Path.Combine(
buildCommand.GetIntermediateDirectory(targetFramework: ToolsetInfo.CurrentTargetFramework).FullName,
"ref",
"MainProject.dll");
File.Exists(refPath)
.Should()
.BeTrue();
}
}

The test fails when produceOnlyReferenceAssembly is false because the path obj\Debug\net7.0\ref\MainProject.dll does not exist. When I run this test locally it is created.

I'm going to need some help understanding the test failure here as it passes on my machine. I'm pretty sure my environment is set up correctly as the test I did change in this PR also passes on my machine (GivenThatWeWantToProduceReferenceAssembly.It_produces_ref_assembly_for_appropriate_frameworks) and it would fail if the corresponding MSBuild change wasn't being picked up.

Is there some way to get a .binlog from the CI machine for a specific unit test?

@drewnoakes drewnoakes force-pushed the ref-assemblies-by-default branch from 876e5e9 to c234603 Compare April 13, 2023 05:06
@drewnoakes
Copy link
Member Author

drewnoakes commented Apr 13, 2023

Latest build is failing with:

Process ID: 4796
    Microsoft.NET.Build.Tests.GivenThatWeWantToProduceReferenceAssembly.It_produces_ref_assembly_for_appropriate_frameworks(targetFramework: "net7.0", extension: ".fsproj") [FAIL]
      System.Exception : Test dir C:\h\w\B2730982\t\dotnetSdkTests\42553ekg.5uy\It_produces_r---08D0FE86_2 already exists
      Stack Trace:
        /_/src/Tests/Microsoft.NET.TestFramework/TestAssetsManager.cs(223,0): at Microsoft.NET.TestFramework.TestAssetsManager.GetTestDestinationDirectoryPath(String testProjectName, String callingMethodAndFileName, String identifier, Boolean allowCopyIfPresent)
        /_/src/Tests/Microsoft.NET.TestFramework/TestAssetsManager.cs(83,0): at Microsoft.NET.TestFramework.TestAssetsManager.CreateTestProject(TestProject testProject, String callingMethod, String identifier, String targetExtension)
        /_/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToProduceReferenceAssembly.cs(41,0): at Microsoft.NET.Build.Tests.GivenThatWeWantToProduceReferenceAssembly.It_produces_ref_assembly_for_appropriate_frameworks(String targetFramework, String extension)
           at InvokeStub_GivenThatWeWantToProduceReferenceAssembly.It_produces_ref_assembly_for_appropriate_frameworks(Object, Object, IntPtr*)
           at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

This failure seems intermittent. Could xUnit be running these in parallel? I can't see why this wouldn't have failed before my changes though.

@drewnoakes
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@drewnoakes
Copy link
Member Author

Ah, I see, the truncated-with-hash file name needs to include an identifier for the leg of a multi-leg theory that is unique. Fixed in 039025f.

@@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who from F# do we need to vet this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzarytovskii is the go-to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think any action is needed from us? Now it will set it to true for all projects when using .net8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that, combined with the MS Build change, ref assemblies will be produced for all F# projects when using VS 17.7, irrespective of the target framework.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it should be fine, and leaves us window to make changes, if needed, before net8 release.

@drewnoakes drewnoakes marked this pull request as ready for review April 13, 2023 22:46
@lewing
Copy link
Member

lewing commented Apr 14, 2023

@dotnet/domestic-cat can we land this?

@marcpopMSFT marcpopMSFT merged commit d2e470b into dotnet:release/7.0.4xx Apr 14, 2023
@drewnoakes drewnoakes deleted the ref-assemblies-by-default branch April 14, 2023 22:05
rainersigwald added a commit that referenced this pull request Apr 21, 2023
…31598)"

This reverts commit d2e470b, reversing
changes made to 377caa7.

Follows the MSBuild revert in dotnet/msbuild#8571.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants